Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2dcea91a63 | ||
|
|
d240b543eb | ||
|
|
1a35ec064c | ||
|
|
204691772c | ||
|
|
15e3f1dd29 | ||
|
|
bcd208684b | ||
|
|
2bdbe4943d | ||
|
|
1c365a55a8 | ||
|
|
8b367ee539 | ||
|
|
9134b8945d | ||
|
|
19b1751e78 | ||
|
|
a20956cde2 | ||
|
|
659171bf0a | ||
|
|
f5b3accc13 | ||
|
|
22e9096f7c | ||
|
|
6aee17fad2 | ||
|
|
b594889239 | ||
|
|
0300e4a72e | ||
|
|
7febb0384f | ||
|
|
55e1f754c5 | ||
|
|
03676a980f | ||
|
|
a74d0cece5 | ||
|
|
b5cd7b1bc9 | ||
|
|
3249dbd4aa | ||
|
|
189c513677 | ||
|
|
05e66b22d1 |
@@ -14,6 +14,7 @@ public class AppSettings
|
|||||||
public int RefreshInterval { get; set; } = 120;
|
public int RefreshInterval { get; set; } = 120;
|
||||||
public bool ShowInTaskbar { get; set; } = true;
|
public bool ShowInTaskbar { get; set; } = true;
|
||||||
public bool BetaChannel { get; set; } = false;
|
public bool BetaChannel { get; set; } = false;
|
||||||
|
public string DebugInfo { get; set; } = "";
|
||||||
|
|
||||||
private static readonly string FilePath = Path.Combine(
|
private static readonly string FilePath = Path.Combine(
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||||
|
|||||||
+47
-12
@@ -47,7 +47,6 @@ public partial class LoginWindow : Window
|
|||||||
: "Complete sign-in, then click Done.";
|
: "Complete sign-in, then click Done.";
|
||||||
});
|
});
|
||||||
|
|
||||||
// Auto-close once we land on any claude.ai page that isn't the login flow
|
|
||||||
if (!uri.Contains("/login") && !uri.Contains("/signin") && signedIn)
|
if (!uri.Contains("/login") && !uri.Contains("/signin") && signedIn)
|
||||||
await SaveAndClose(cookies);
|
await SaveAndClose(cookies);
|
||||||
};
|
};
|
||||||
@@ -67,30 +66,50 @@ public partial class LoginWindow : Window
|
|||||||
|
|
||||||
UsageViewModel.SaveCookies(cookies);
|
UsageViewModel.SaveCookies(cookies);
|
||||||
|
|
||||||
// Fetch bootstrap + usage from within WebView2 (already authenticated, no header issues)
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// Use WebMessageReceived so the async script can post back without relying
|
||||||
|
// on Promise-awaiting support in the WebView2 runtime version.
|
||||||
|
var tcs = new TaskCompletionSource<string?>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
EventHandler<CoreWebView2WebMessageReceivedEventArgs>? msgHandler = null;
|
||||||
|
msgHandler = (_, args) =>
|
||||||
|
{
|
||||||
|
Browser.CoreWebView2.WebMessageReceived -= msgHandler;
|
||||||
|
tcs.TrySetResult(args.WebMessageAsJson);
|
||||||
|
};
|
||||||
|
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();
|
||||||
let id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid
|
const rawB=JSON.stringify(b).slice(0,600);
|
||||||
|
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 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';
|
||||||
if(!id){
|
if(!id){
|
||||||
try{const ol=await(await fetch('/api/organizations',h)).json();
|
try{const ol=await(await fetch('/api/organizations',h)).json();
|
||||||
if(Array.isArray(ol)&&ol.length>0)id=ol[0]?.uuid||null;}catch(e2){}
|
if(Array.isArray(ol)&&ol.length>0){id=ol[0]?.uuid||null;orgSrc='orgs-list';}}catch(e2){}
|
||||||
}
|
}
|
||||||
if(!id){
|
if(!id){
|
||||||
try{const pu=await(await fetch('/api/usage',h)).json();
|
let pu=null;
|
||||||
if(pu&&!pu.error)return{email:e,orgId:null,usage:pu};}catch(e3){}
|
try{pu=await(await fetch('/api/usage',h)).json();}catch(e3){}
|
||||||
return{email:e,orgId:null,usage:null};
|
window.chrome.webview.postMessage({email:e,orgId:null,usage:(pu&&!pu.error?pu:null),debug:'no-org|raw:'+rawB});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const u=await(await fetch('/api/organizations/'+id+'/usage',h)).json();
|
const u=await(await fetch('/api/organizations/'+id+'/usage',h)).json();
|
||||||
return{email:e,orgId:id,usage:u};
|
const rawU=JSON.stringify(u).slice(0,400);
|
||||||
}catch(ex){return{error:String(ex)};}})()";
|
window.chrome.webview.postMessage({email:e,orgId:id,usage:u,debug:'src:'+orgSrc+'|ukeys:'+Object.keys(u||{}).join(',')+'|rawU:'+rawU+'|rawB:'+rawB});
|
||||||
|
}catch(ex){window.chrome.webview.postMessage({error:String(ex)});}})()";
|
||||||
|
|
||||||
var json = await Browser.CoreWebView2.ExecuteScriptAsync(script);
|
await Browser.CoreWebView2.ExecuteScriptAsync(script);
|
||||||
if (json != "null" && !string.IsNullOrEmpty(json))
|
|
||||||
|
// Wait up to 15 s for the script to post its message
|
||||||
|
var completed = await Task.WhenAny(tcs.Task, Task.Delay(15000));
|
||||||
|
var json = completed == tcs.Task ? tcs.Task.Result : null;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(json))
|
||||||
{
|
{
|
||||||
using var doc = JsonDocument.Parse(json);
|
using var doc = JsonDocument.Parse(json);
|
||||||
var root = doc.RootElement;
|
var root = doc.RootElement;
|
||||||
@@ -104,10 +123,26 @@ public partial class LoginWindow : Window
|
|||||||
if (root.TryGetProperty("usage", out var us) && us.ValueKind == JsonValueKind.Object)
|
if (root.TryGetProperty("usage", out var us) && us.ValueKind == JsonValueKind.Object)
|
||||||
AppSettings.Default.UsageJson = us.GetRawText();
|
AppSettings.Default.UsageJson = us.GetRawText();
|
||||||
|
|
||||||
|
if (root.TryGetProperty("debug", out var dbg) && dbg.ValueKind == JsonValueKind.String)
|
||||||
|
AppSettings.Default.DebugInfo = dbg.GetString() ?? "";
|
||||||
|
else if (root.TryGetProperty("error", out var err))
|
||||||
|
AppSettings.Default.DebugInfo = "JS error: " + err.GetRawText();
|
||||||
|
else
|
||||||
|
AppSettings.Default.DebugInfo = "timeout or empty message";
|
||||||
|
|
||||||
|
AppSettings.Default.Save();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppSettings.Default.DebugInfo = json == null ? "script timeout (15s)" : "empty message";
|
||||||
AppSettings.Default.Save();
|
AppSettings.Default.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AppSettings.Default.DebugInfo = "exception: " + ex.Message;
|
||||||
|
AppSettings.Default.Save();
|
||||||
|
}
|
||||||
|
|
||||||
await Dispatcher.InvokeAsync(() => DialogResult = true);
|
await Dispatcher.InvokeAsync(() => DialogResult = true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
@@ -185,6 +194,10 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
|
<TextBlock x:Name="DebugText" FontSize="10" Foreground="{DynamicResource SecondaryBrush}"
|
||||||
|
TextWrapping="Wrap" Margin="0,12,0,0" FontFamily="Consolas"
|
||||||
|
Visibility="Collapsed"/>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|||||||
@@ -283,6 +283,20 @@ public partial class PopupWindow : Window
|
|||||||
|
|
||||||
SignOutButton.Visibility = VM.IsSignedIn ? Visibility.Visible : Visibility.Collapsed;
|
SignOutButton.Visibility = VM.IsSignedIn ? Visibility.Visible : Visibility.Collapsed;
|
||||||
SignInButton.Content = VM.IsSignedIn ? "Re-authenticate" : "Sign In";
|
SignInButton.Content = VM.IsSignedIn ? "Re-authenticate" : "Sign In";
|
||||||
|
|
||||||
|
var dbg = AppSettings.Default.DebugInfo;
|
||||||
|
if (!string.IsNullOrEmpty(dbg))
|
||||||
|
{
|
||||||
|
DebugText.Text = dbg;
|
||||||
|
DebugText.Visibility = Visibility.Visible;
|
||||||
|
DebugBannerText.Text = dbg;
|
||||||
|
DebugBanner.Visibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DebugText.Visibility = Visibility.Collapsed;
|
||||||
|
DebugBanner.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Event handlers ───────────────────────────────────────────────
|
// ── Event handlers ───────────────────────────────────────────────
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
## What's new in beta.24
|
## What's new in beta.31
|
||||||
|
|
||||||
- Sign-in now shows email and data immediately after login (loads from cache set during login flow)
|
- Fix: placeholder cards now show after sign-in when no usage data is cached yet (main panel no longer goes blank)
|
||||||
- Background refresh runs 3 seconds after login — avoids WebView2 user data folder lock race
|
- Debug: raw usage API response now included in debug banner so we can see what the endpoint returns
|
||||||
- Added /api/organizations and personal /api/usage fallbacks when bootstrap has no org ID
|
|
||||||
- Broader JS paths for email and org ID
|
|
||||||
|
|||||||
+41
-23
@@ -95,15 +95,13 @@ public class UsageViewModel : INotifyPropertyChanged
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try HttpClient first (fast path) — may be rejected by server CORS/header checks
|
// HttpClient refresh — WebView2 is NOT used here to avoid spawning a heavy
|
||||||
|
// browser process every refresh cycle (causes memory accumulation).
|
||||||
|
// SaveAndClose at login time is responsible for fetching live data via WebView2.
|
||||||
var (limits, overage, prepaid, email, orgId, ok) = hasCookies
|
var (limits, overage, prepaid, email, orgId, ok) = hasCookies
|
||||||
? await TryHttpRefreshAsync(cookies)
|
? await TryHttpRefreshAsync(cookies)
|
||||||
: ([], null, null, null, null, false);
|
: ([], null, null, null, null, false);
|
||||||
|
|
||||||
// Fall back to WebView2 (uses the shared browser session, not HttpClient)
|
|
||||||
if (!ok)
|
|
||||||
(limits, email, orgId) = await TryWebView2RefreshAsync();
|
|
||||||
|
|
||||||
// Fill in any blanks from cached values saved at login time
|
// Fill in any blanks from cached values saved at login time
|
||||||
if (string.IsNullOrEmpty(email)) email = AppSettings.Default.Email;
|
if (string.IsNullOrEmpty(email)) email = AppSettings.Default.Email;
|
||||||
if (string.IsNullOrEmpty(orgId)) orgId = AppSettings.Default.OrgId;
|
if (string.IsNullOrEmpty(orgId)) orgId = AppSettings.Default.OrgId;
|
||||||
@@ -131,12 +129,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 +187,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){
|
||||||
@@ -201,13 +196,14 @@ public class UsageViewModel : INotifyPropertyChanged
|
|||||||
if(Array.isArray(ol)&&ol.length>0)id=ol[0]?.uuid||null;}catch(e2){}
|
if(Array.isArray(ol)&&ol.length>0)id=ol[0]?.uuid||null;}catch(e2){}
|
||||||
}
|
}
|
||||||
if(!id){
|
if(!id){
|
||||||
try{const pu=await(await fetch('/api/usage',h)).json();
|
let pu=null;
|
||||||
if(pu&&!pu.error)return{email:em,orgId:null,usage:pu};}catch(e3){}
|
try{pu=await(await fetch('/api/usage',h)).json();}catch(e3){}
|
||||||
return{email:em,orgId:null,usage:null};
|
window.chrome.webview.postMessage({email:em,orgId:null,usage:(pu&&!pu.error?pu:null)});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const u=await(await fetch('/api/organizations/'+id+'/usage',h)).json();
|
const u=await(await fetch('/api/organizations/'+id+'/usage',h)).json();
|
||||||
return{email:em,orgId:id,usage:u};
|
window.chrome.webview.postMessage({email:em,orgId:id,usage:u});
|
||||||
}catch(ex){return null;}})()";
|
}catch(ex){window.chrome.webview.postMessage(null);}})();";
|
||||||
|
|
||||||
var resultJson = await Application.Current.Dispatcher.InvokeAsync(async () =>
|
var resultJson = await Application.Current.Dispatcher.InvokeAsync(async () =>
|
||||||
{
|
{
|
||||||
@@ -271,9 +267,10 @@ public class UsageViewModel : INotifyPropertyChanged
|
|||||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(email)) UserEmail = email;
|
if (!string.IsNullOrEmpty(email)) UserEmail = email;
|
||||||
if (limits.Count > 0) Limits = limits;
|
// Always show cards — real data if available, placeholders if not
|
||||||
|
Limits = limits.Count > 0 ? limits : LoadPlaceholderLimits();
|
||||||
IsSignedIn = true;
|
IsSignedIn = true;
|
||||||
ErrorMessage = limits.Count == 0 ? "Signed in — refreshing data…" : null;
|
ErrorMessage = null;
|
||||||
LastUpdated = limits.Count > 0 ? DateTime.Now : LastUpdated;
|
LastUpdated = limits.Count > 0 ? DateTime.Now : LastUpdated;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -326,6 +323,14 @@ public class UsageViewModel : INotifyPropertyChanged
|
|||||||
http.DefaultRequestHeaders.Add("User-Agent",
|
http.DefaultRequestHeaders.Add("User-Agent",
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
|
||||||
"(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36");
|
"(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36");
|
||||||
|
http.DefaultRequestHeaders.Add("Origin", "https://claude.ai");
|
||||||
|
http.DefaultRequestHeaders.Add("Referer", "https://claude.ai/");
|
||||||
|
http.DefaultRequestHeaders.Add("sec-fetch-dest", "empty");
|
||||||
|
http.DefaultRequestHeaders.Add("sec-fetch-mode", "cors");
|
||||||
|
http.DefaultRequestHeaders.Add("sec-fetch-site", "same-origin");
|
||||||
|
http.DefaultRequestHeaders.Add("sec-ch-ua", "\"Chromium\";v=\"124\", \"Google Chrome\";v=\"124\"");
|
||||||
|
http.DefaultRequestHeaders.Add("sec-ch-ua-mobile", "?0");
|
||||||
|
http.DefaultRequestHeaders.Add("sec-ch-ua-platform", "\"Windows\"");
|
||||||
var cookieHeader = string.Join("; ", cookies.Select(c => $"{c.Name}={c.Value}"));
|
var cookieHeader = string.Join("; ", cookies.Select(c => $"{c.Name}={c.Value}"));
|
||||||
http.DefaultRequestHeaders.Add("Cookie", cookieHeader);
|
http.DefaultRequestHeaders.Add("Cookie", cookieHeader);
|
||||||
return http;
|
return http;
|
||||||
@@ -358,8 +363,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) &&
|
||||||
@@ -367,7 +373,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)
|
||||||
{
|
{
|
||||||
@@ -455,16 +471,18 @@ public class UsageViewModel : INotifyPropertyChanged
|
|||||||
return $"{diff.Hours}h {diff.Minutes}m";
|
return $"{diff.Hours}h {diff.Minutes}m";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadPlaceholders()
|
private static List<AgentLimit> LoadPlaceholderLimits()
|
||||||
{
|
{
|
||||||
var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
Limits =
|
return
|
||||||
[
|
[
|
||||||
new() { Window = WindowKind.FiveHour, UsedPercent = 0, TimeRemaining = "—", ResetDate = now.AddHours(1) },
|
new() { Window = WindowKind.FiveHour, UsedPercent = 0, TimeRemaining = "—", ResetDate = now.AddHours(1) },
|
||||||
new() { Window = WindowKind.SevenDay, UsedPercent = 0, TimeRemaining = "—", ResetDate = now.AddDays(7) },
|
new() { Window = WindowKind.SevenDay, UsedPercent = 0, TimeRemaining = "—", ResetDate = now.AddDays(7) },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LoadPlaceholders() => Limits = LoadPlaceholderLimits();
|
||||||
|
|
||||||
private void LoadBurnHistory()
|
private void LoadBurnHistory()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -34,25 +34,34 @@ internal sealed class WebViewFetchWindow : Window
|
|||||||
|
|
||||||
await _wv.EnsureCoreWebView2Async(env);
|
await _wv.EnsureCoreWebView2Async(env);
|
||||||
|
|
||||||
var tcs = new TaskCompletionSource<string?>();
|
var tcs = new TaskCompletionSource<string?>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
|
||||||
EventHandler<CoreWebView2NavigationCompletedEventArgs>? handler = null;
|
// Use WebMessageReceived so the script can post back asynchronously without
|
||||||
handler = async (_, e) =>
|
// relying on Promise-awaiting support in the WebView2 runtime version.
|
||||||
|
EventHandler<CoreWebView2WebMessageReceivedEventArgs>? msgHandler = null;
|
||||||
|
msgHandler = (_, args) =>
|
||||||
{
|
{
|
||||||
_wv.CoreWebView2.NavigationCompleted -= handler;
|
_wv.CoreWebView2.WebMessageReceived -= msgHandler;
|
||||||
|
tcs.TrySetResult(args.WebMessageAsJson);
|
||||||
|
};
|
||||||
|
_wv.CoreWebView2.WebMessageReceived += msgHandler;
|
||||||
|
|
||||||
|
EventHandler<CoreWebView2NavigationCompletedEventArgs>? navHandler = null;
|
||||||
|
navHandler = async (_, e) =>
|
||||||
|
{
|
||||||
|
_wv.CoreWebView2.NavigationCompleted -= navHandler;
|
||||||
if (!e.IsSuccess) { tcs.TrySetResult(null); return; }
|
if (!e.IsSuccess) { tcs.TrySetResult(null); return; }
|
||||||
try
|
try { await _wv.CoreWebView2.ExecuteScriptAsync(script); }
|
||||||
{
|
|
||||||
var result = await _wv.CoreWebView2.ExecuteScriptAsync(script);
|
|
||||||
tcs.TrySetResult(result);
|
|
||||||
}
|
|
||||||
catch { tcs.TrySetResult(null); }
|
catch { tcs.TrySetResult(null); }
|
||||||
};
|
};
|
||||||
|
_wv.CoreWebView2.NavigationCompleted += navHandler;
|
||||||
_wv.CoreWebView2.NavigationCompleted += handler;
|
|
||||||
_wv.CoreWebView2.Navigate(navigateUrl);
|
_wv.CoreWebView2.Navigate(navigateUrl);
|
||||||
|
|
||||||
_ = Task.Delay(timeoutMs).ContinueWith(_ => tcs.TrySetResult(null));
|
_ = Task.Delay(timeoutMs).ContinueWith(_ =>
|
||||||
|
{
|
||||||
|
_wv.CoreWebView2.WebMessageReceived -= msgHandler;
|
||||||
|
tcs.TrySetResult(null);
|
||||||
|
});
|
||||||
|
|
||||||
return await tcs.Task;
|
return await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user