Compare commits

..
5 changed files with 42 additions and 20 deletions
+6 -5
View File
@@ -82,9 +82,9 @@ public partial class LoginWindow : Window
const string script = @"(async()=>{try{ const string script = @"(async()=>{try{
const h={headers:{accept:'application/json'}}; const h={headers:{accept:'application/json'}};
const b=await(await fetch('/api/bootstrap',h)).json(); const b=await(await fetch('/api/bootstrap',h)).json();
const bkeys=Object.keys(b||{}).join(','); const rawB=JSON.stringify(b).slice(0,600);
const akeys=Object.keys(b?.account||{}).join(','); let id=b?.account?.memberships?.[0]?.organization?.uuid
let id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid ||b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid
||b?.default_organization?.uuid||null; ||b?.default_organization?.uuid||null;
const e=b?.account?.email_address||b?.account?.email||b?.email||null; const e=b?.account?.email_address||b?.account?.email||b?.email||null;
let orgSrc='bootstrap'; let orgSrc='bootstrap';
@@ -95,11 +95,12 @@ public partial class LoginWindow : Window
if(!id){ if(!id){
let pu=null; let pu=null;
try{pu=await(await fetch('/api/usage',h)).json();}catch(e3){} try{pu=await(await fetch('/api/usage',h)).json();}catch(e3){}
window.chrome.webview.postMessage({email:e,orgId:null,usage:(pu&&!pu.error?pu:null),debug:'no-org|bkeys:'+bkeys+'|akeys:'+akeys}); window.chrome.webview.postMessage({email:e,orgId:null,usage:(pu&&!pu.error?pu:null),debug:'no-org|raw:'+rawB});
return; return;
} }
const u=await(await fetch('/api/organizations/'+id+'/usage',h)).json(); const u=await(await fetch('/api/organizations/'+id+'/usage',h)).json();
window.chrome.webview.postMessage({email:e,orgId:id,usage:u,debug:'orgSrc:'+orgSrc+'|bkeys:'+bkeys+'|akeys:'+akeys}); const rawU=JSON.stringify(u).slice(0,300);
window.chrome.webview.postMessage({email:e,orgId:id,usage:u,debug:'src:'+orgSrc+'|ukeys:'+Object.keys(u||{}).join(',')+'|raw:'+rawB});
}catch(ex){window.chrome.webview.postMessage({error:String(ex)});}})()"; }catch(ex){window.chrome.webview.postMessage({error:String(ex)});}})()";
await Browser.CoreWebView2.ExecuteScriptAsync(script); await Browser.CoreWebView2.ExecuteScriptAsync(script);
+10 -1
View File
@@ -66,7 +66,16 @@
<!-- Cards scroll area --> <!-- Cards scroll area -->
<ScrollViewer VerticalScrollBarVisibility="Auto"> <ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="CardsPanel" Margin="0,4,0,4"/> <StackPanel Margin="0,4,0,4">
<Border x:Name="DebugBanner" Visibility="Collapsed"
Background="{DynamicResource CardBrush}"
BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1"
CornerRadius="6" Margin="12,4,12,4" Padding="12,8">
<TextBlock x:Name="DebugBannerText" FontSize="10" FontFamily="Consolas"
Foreground="{DynamicResource SecondaryBrush}" TextWrapping="Wrap"/>
</Border>
<StackPanel x:Name="CardsPanel"/>
</StackPanel>
</ScrollViewer> </ScrollViewer>
</DockPanel> </DockPanel>
+6 -3
View File
@@ -287,12 +287,15 @@ public partial class PopupWindow : Window
var dbg = AppSettings.Default.DebugInfo; var dbg = AppSettings.Default.DebugInfo;
if (!string.IsNullOrEmpty(dbg)) if (!string.IsNullOrEmpty(dbg))
{ {
DebugText.Text = dbg; DebugText.Text = dbg;
DebugText.Visibility = Visibility.Visible; DebugText.Visibility = Visibility.Visible;
DebugBannerText.Text = dbg;
DebugBanner.Visibility = Visibility.Visible;
} }
else else
{ {
DebugText.Visibility = Visibility.Collapsed; DebugText.Visibility = Visibility.Collapsed;
DebugBanner.Visibility = Visibility.Collapsed;
} }
} }
+3 -2
View File
@@ -1,3 +1,4 @@
## What's new in beta.27 ## What's new in beta.29
- Fix build error: use WebMessageAsJson (not WebMessageAsString) and post plain JS objects via postMessage - Fix: org ID is now correctly read from b.account.memberships[0].organization.uuid — bootstrap nests memberships inside account, not at the root
- This was preventing usage limits from loading for all accounts
+17 -9
View File
@@ -131,12 +131,8 @@ public class UsageViewModel : INotifyPropertyChanged
await Application.Current.Dispatcher.InvokeAsync(() => await Application.Current.Dispatcher.InvokeAsync(() =>
{ {
Limits = limits; if (limits.Count > 0) { Limits = limits; Overage = overage; Prepaid = prepaid; }
Overage = overage;
Prepaid = prepaid;
if (!string.IsNullOrEmpty(email)) UserEmail = email; if (!string.IsNullOrEmpty(email)) UserEmail = email;
// Trust that cookies / cached auth mean the user IS signed in,
// even if the live fetch failed this cycle.
IsSignedIn = true; IsSignedIn = true;
ErrorMessage = null; ErrorMessage = null;
LastUpdated = DateTime.Now; LastUpdated = DateTime.Now;
@@ -193,7 +189,8 @@ public class UsageViewModel : INotifyPropertyChanged
const string script = @"(async()=>{try{ const string script = @"(async()=>{try{
const h={headers:{accept:'application/json'}}; const h={headers:{accept:'application/json'}};
const b=await(await fetch('/api/bootstrap',h)).json(); const b=await(await fetch('/api/bootstrap',h)).json();
let id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid let id=b?.account?.memberships?.[0]?.organization?.uuid
||b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid
||b?.default_organization?.uuid||null; ||b?.default_organization?.uuid||null;
const em=b?.account?.email_address||b?.account?.email||b?.email||null; const em=b?.account?.email_address||b?.account?.email||b?.email||null;
if(!id){ if(!id){
@@ -359,8 +356,9 @@ public class UsageViewModel : INotifyPropertyChanged
acct.TryGetProperty("email_address", out var em)) acct.TryGetProperty("email_address", out var em))
email = em.GetString(); email = em.GetString();
// Path 1: memberships[0].organization.uuid // Path 1: account.memberships[0].organization.uuid (Claude.ai personal/pro accounts)
if (root.TryGetProperty("memberships", out var mems) && mems.GetArrayLength() > 0) if (root.TryGetProperty("account", out var acctNode) &&
acctNode.TryGetProperty("memberships", out var mems) && mems.GetArrayLength() > 0)
{ {
var first = mems[0]; var first = mems[0];
if (first.TryGetProperty("organization", out var org) && if (first.TryGetProperty("organization", out var org) &&
@@ -368,7 +366,17 @@ public class UsageViewModel : INotifyPropertyChanged
orgId = uuid.GetString(); orgId = uuid.GetString();
} }
// Path 2: organizations[0].uuid (flat list on root) // Path 2: memberships[0].organization.uuid (root-level, older API shape)
if (string.IsNullOrEmpty(orgId) &&
root.TryGetProperty("memberships", out var rootMems) && rootMems.GetArrayLength() > 0)
{
var first = rootMems[0];
if (first.TryGetProperty("organization", out var org) &&
org.TryGetProperty("uuid", out var uuid))
orgId = uuid.GetString();
}
// Path 3: organizations[0].uuid (flat list on root)
if (string.IsNullOrEmpty(orgId) && if (string.IsNullOrEmpty(orgId) &&
root.TryGetProperty("organizations", out var orgs) && orgs.GetArrayLength() > 0) root.TryGetProperty("organizations", out var orgs) && orgs.GetArrayLength() > 0)
{ {