Compare commits

..
6 changed files with 31 additions and 22 deletions
+7 -7
View File
@@ -75,17 +75,16 @@ public partial class LoginWindow : Window
msgHandler = (_, args) => msgHandler = (_, args) =>
{ {
Browser.CoreWebView2.WebMessageReceived -= msgHandler; Browser.CoreWebView2.WebMessageReceived -= msgHandler;
tcs.TrySetResult(args.WebMessageAsString); tcs.TrySetResult(args.WebMessageAsJson);
}; };
Browser.CoreWebView2.WebMessageReceived += msgHandler; Browser.CoreWebView2.WebMessageReceived += msgHandler;
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?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid let id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid
||b?.default_organization?.uuid||null; ||b?.default_organization?.uuid||b?.account?.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';
if(!id){ if(!id){
@@ -95,12 +94,13 @@ 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(JSON.stringify({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(JSON.stringify({email:e,orgId:id,usage:u,debug:'orgSrc:'+orgSrc+'|bkeys:'+bkeys+'|akeys:'+akeys})); const rawU=JSON.stringify(u).slice(0,300);
}catch(ex){window.chrome.webview.postMessage(JSON.stringify({error:String(ex)}));}})()"; 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)});}})()";
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;
} }
} }
+4 -3
View File
@@ -1,4 +1,5 @@
## What's new in beta.26 ## What's new in beta.28
- Fixed: script results now use window.chrome.webview.postMessage instead of async IIFE return value — older WebView2 runtimes don't await Promises from ExecuteScriptAsync, so data was never received - Debug banner now appears on the main panel after sign-in showing raw bootstrap data — paste this here so we can fix org ID parsing
- Debug text in Settings will now always show what happened during sign-in - Fix: limits no longer wiped when a refresh cycle returns no data (placeholders stay until real data arrives)
- Try account.uuid as org ID fallback when no org found in bootstrap
+3 -7
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;
@@ -203,11 +199,11 @@ public class UsageViewModel : INotifyPropertyChanged
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(JSON.stringify({email:em,orgId:null,usage:(pu&&!pu.error?pu:null)})); window.chrome.webview.postMessage({email:em,orgId:null,usage:(pu&&!pu.error?pu:null)});
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(JSON.stringify({email:em,orgId:id,usage:u})); window.chrome.webview.postMessage({email:em,orgId:id,usage:u});
}catch(ex){window.chrome.webview.postMessage(null);}})();"; }catch(ex){window.chrome.webview.postMessage(null);}})();";
var resultJson = await Application.Current.Dispatcher.InvokeAsync(async () => var resultJson = await Application.Current.Dispatcher.InvokeAsync(async () =>
+1 -1
View File
@@ -42,7 +42,7 @@ internal sealed class WebViewFetchWindow : Window
msgHandler = (_, args) => msgHandler = (_, args) =>
{ {
_wv.CoreWebView2.WebMessageReceived -= msgHandler; _wv.CoreWebView2.WebMessageReceived -= msgHandler;
tcs.TrySetResult(args.WebMessageAsString); tcs.TrySetResult(args.WebMessageAsJson);
}; };
_wv.CoreWebView2.WebMessageReceived += msgHandler; _wv.CoreWebView2.WebMessageReceived += msgHandler;