Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a74d0cece5 | ||
|
|
b5cd7b1bc9 | ||
|
|
3249dbd4aa | ||
|
|
189c513677 | ||
|
|
05e66b22d1 | ||
|
|
48e6f64c9a | ||
|
|
d55a92623c | ||
|
|
c70a090983 | ||
|
|
cc0270326e | ||
|
|
7601452f93 | ||
|
|
5a78a021cb | ||
|
|
7d465c13d8 | ||
|
|
ca67039e3e | ||
|
|
1e4cdc09b3 |
@@ -14,6 +14,7 @@ public class AppSettings
|
||||
public int RefreshInterval { get; set; } = 120;
|
||||
public bool ShowInTaskbar { get; set; } = true;
|
||||
public bool BetaChannel { get; set; } = false;
|
||||
public string DebugInfo { get; set; } = "";
|
||||
|
||||
private static readonly string FilePath = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
|
||||
@@ -47,8 +47,8 @@ public partial class LoginWindow : Window
|
||||
: "Complete sign-in, then click Done.";
|
||||
});
|
||||
|
||||
// Auto-close as soon as we detect sign-in on any claude.ai page
|
||||
if (signedIn && !uri.Contains("/login") && !uri.Contains("/signin"))
|
||||
// Auto-close once we land on any claude.ai page that isn't the login flow
|
||||
if (!uri.Contains("/login") && !uri.Contains("/signin") && signedIn)
|
||||
await SaveAndClose(cookies);
|
||||
};
|
||||
}
|
||||
@@ -71,12 +71,25 @@ public partial class LoginWindow : Window
|
||||
try
|
||||
{
|
||||
const string script = @"(async()=>{try{
|
||||
const b=await(await fetch('/api/bootstrap',{headers:{accept:'application/json'}})).json();
|
||||
const id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid||null;
|
||||
const e=b?.account?.email_address||null;
|
||||
if(!id)return{email:e,orgId:null,usage:null};
|
||||
const u=await(await fetch('/api/organizations/'+id+'/usage',{headers:{accept:'application/json'}})).json();
|
||||
return{email:e,orgId:id,usage:u};
|
||||
const h={headers:{accept:'application/json'}};
|
||||
const b=await(await fetch('/api/bootstrap',h)).json();
|
||||
const bkeys=Object.keys(b||{}).join(',');
|
||||
const akeys=Object.keys(b?.account||{}).join(',');
|
||||
let id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid
|
||||
||b?.default_organization?.uuid||null;
|
||||
const e=b?.account?.email_address||b?.account?.email||b?.email||null;
|
||||
let orgSrc='bootstrap';
|
||||
if(!id){
|
||||
try{const ol=await(await fetch('/api/organizations',h)).json();
|
||||
if(Array.isArray(ol)&&ol.length>0){id=ol[0]?.uuid||null;orgSrc='orgs-list';}}catch(e2){}
|
||||
}
|
||||
if(!id){
|
||||
try{const pu=await(await fetch('/api/usage',h)).json();
|
||||
if(pu&&!pu.error)return{email:e,orgId:null,usage:pu,debug:'no-org|bkeys:'+bkeys+'|akeys:'+akeys};}catch(e3){}
|
||||
return{email:e,orgId:null,usage:null,debug:'no-org|bkeys:'+bkeys+'|akeys:'+akeys};
|
||||
}
|
||||
const u=await(await fetch('/api/organizations/'+id+'/usage',h)).json();
|
||||
return{email:e,orgId:id,usage:u,debug:'orgSrc:'+orgSrc+'|bkeys:'+bkeys+'|akeys:'+akeys};
|
||||
}catch(ex){return{error:String(ex)};}})()";
|
||||
|
||||
var json = await Browser.CoreWebView2.ExecuteScriptAsync(script);
|
||||
@@ -94,6 +107,11 @@ public partial class LoginWindow : Window
|
||||
if (root.TryGetProperty("usage", out var us) && us.ValueKind == JsonValueKind.Object)
|
||||
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 = "error:" + err.GetRawText();
|
||||
|
||||
AppSettings.Default.Save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,12 +173,22 @@
|
||||
<TextBlock Text="Built by superdooper86 & claude"
|
||||
FontSize="11" Foreground="{DynamicResource SecondaryBrush}"/>
|
||||
</StackPanel>
|
||||
<Button Grid.Column="2" x:Name="CheckUpdateButton"
|
||||
Style="{StaticResource SmallButton}"
|
||||
Click="CheckUpdate_Click" VerticalAlignment="Center"/>
|
||||
<StackPanel Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right">
|
||||
<Button x:Name="CheckUpdateButton"
|
||||
Style="{StaticResource SmallButton}"
|
||||
Click="CheckUpdate_Click"/>
|
||||
<TextBlock x:Name="UpdateAvailableText" FontSize="10"
|
||||
Foreground="{DynamicResource BlueBrush}"
|
||||
HorizontalAlignment="Center"
|
||||
Visibility="Collapsed" Margin="0,4,0,0"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<TextBlock x:Name="DebugText" FontSize="10" Foreground="{DynamicResource SecondaryBrush}"
|
||||
TextWrapping="Wrap" Margin="0,12,0,0" FontFamily="Consolas"
|
||||
Visibility="Collapsed"/>
|
||||
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</DockPanel>
|
||||
|
||||
@@ -199,7 +199,10 @@ public partial class PopupWindow : Window
|
||||
private void OnUpdaterChanged(string? prop)
|
||||
{
|
||||
if (prop is nameof(UpdateManager.UpdateAvailable) or nameof(UpdateManager.LatestVersion))
|
||||
{
|
||||
UpdateBannerState();
|
||||
UpdateAboutSection();
|
||||
}
|
||||
if (prop is nameof(UpdateManager.DownloadProgress))
|
||||
UpdateProgress.Value = Updater.DownloadProgress * 100;
|
||||
if (prop is nameof(UpdateManager.StatusMessage))
|
||||
@@ -208,6 +211,21 @@ public partial class PopupWindow : Window
|
||||
InstallButton.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void UpdateAboutSection()
|
||||
{
|
||||
if (Updater.UpdateAvailable)
|
||||
{
|
||||
UpdateAvailableText.Text = $"v{Updater.LatestVersion} available";
|
||||
UpdateAvailableText.Visibility = Visibility.Visible;
|
||||
CheckUpdateButton.Content = "Install";
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateAvailableText.Visibility = Visibility.Collapsed;
|
||||
CheckUpdateButton.Content = "Check";
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateBannerState()
|
||||
{
|
||||
var visible = Updater.UpdateAvailable;
|
||||
@@ -236,7 +254,7 @@ public partial class PopupWindow : Window
|
||||
{
|
||||
VersionLabel.Text = $"v{Updater.CurrentVersion}";
|
||||
BetaToggle.IsChecked = Updater.BetaChannel;
|
||||
CheckUpdateButton.Content = Updater.UpdateAvailable ? "Install" : "Check";
|
||||
UpdateAboutSection();
|
||||
|
||||
var intervals = new[] { ("1 min", 60), ("2 min", 120), ("3 min", 180),
|
||||
("4 min", 240), ("5 min", 300), ("10 min", 600) };
|
||||
@@ -265,6 +283,17 @@ public partial class PopupWindow : Window
|
||||
|
||||
SignOutButton.Visibility = VM.IsSignedIn ? Visibility.Visible : Visibility.Collapsed;
|
||||
SignInButton.Content = VM.IsSignedIn ? "Re-authenticate" : "Sign In";
|
||||
|
||||
var dbg = AppSettings.Default.DebugInfo;
|
||||
if (!string.IsNullOrEmpty(dbg))
|
||||
{
|
||||
DebugText.Text = dbg;
|
||||
DebugText.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugText.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Event handlers ───────────────────────────────────────────────
|
||||
@@ -315,8 +344,18 @@ public partial class PopupWindow : Window
|
||||
var login = new LoginWindow { Owner = this };
|
||||
if (login.ShowDialog() == true)
|
||||
{
|
||||
await VM.RefreshAsync();
|
||||
// Show cached data from SaveAndClose immediately (no WebView2 needed)
|
||||
await VM.LoadFromCacheAsync();
|
||||
InitSettings();
|
||||
ShowMain();
|
||||
|
||||
// Full refresh in background after WebView2 folder is definitely released
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(3000);
|
||||
await VM.RefreshAsync();
|
||||
await Application.Current.Dispatcher.InvokeAsync(InitSettings);
|
||||
});
|
||||
}
|
||||
Show();
|
||||
Activate();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
## What's new in beta.22
|
||||
## What's new in beta.25
|
||||
|
||||
- Fixed build error: Task unwrap for Dispatcher.InvokeAsync with async lambda
|
||||
- Removed unused field warning
|
||||
- Debug: Settings panel now shows bootstrap diagnostic info after sign-in (helps diagnose missing data)
|
||||
|
||||
+65
-30
@@ -78,7 +78,13 @@ public class UsageViewModel : INotifyPropertyChanged
|
||||
try
|
||||
{
|
||||
var cookies = await GetCookiesAsync();
|
||||
if (cookies.Count == 0)
|
||||
|
||||
// Check if we have any persistent proof that the user authenticated
|
||||
bool hasCookies = cookies.Count > 0;
|
||||
bool hasCachedAuth = !string.IsNullOrEmpty(AppSettings.Default.Email) ||
|
||||
!string.IsNullOrEmpty(AppSettings.Default.OrgId);
|
||||
|
||||
if (!hasCookies && !hasCachedAuth)
|
||||
{
|
||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
@@ -89,20 +95,18 @@ public class UsageViewModel : INotifyPropertyChanged
|
||||
return;
|
||||
}
|
||||
|
||||
// Try HttpClient first (fast path)
|
||||
var (limits, overage, prepaid, email, orgId, ok) = await TryHttpRefreshAsync(cookies);
|
||||
// Try HttpClient first (fast path) — may be rejected by server CORS/header checks
|
||||
var (limits, overage, prepaid, email, orgId, ok) = hasCookies
|
||||
? await TryHttpRefreshAsync(cookies)
|
||||
: ([], null, null, null, null, false);
|
||||
|
||||
// If HttpClient failed, fall back to WebView2 (uses existing browser session)
|
||||
// Fall back to WebView2 (uses the shared browser session, not HttpClient)
|
||||
if (!ok)
|
||||
(limits, email, orgId) = await TryWebView2RefreshAsync();
|
||||
|
||||
// Still no org ID? Use cached values from last successful login
|
||||
if (string.IsNullOrEmpty(orgId) && !string.IsNullOrEmpty(AppSettings.Default.OrgId))
|
||||
orgId = AppSettings.Default.OrgId;
|
||||
if (string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(AppSettings.Default.Email))
|
||||
email = AppSettings.Default.Email;
|
||||
|
||||
// If we have cached usage from login and still got nothing live, use that
|
||||
// Fill in any blanks from cached values saved at login time
|
||||
if (string.IsNullOrEmpty(email)) email = AppSettings.Default.Email;
|
||||
if (string.IsNullOrEmpty(orgId)) orgId = AppSettings.Default.OrgId;
|
||||
if (limits.Count == 0 && !string.IsNullOrEmpty(AppSettings.Default.UsageJson))
|
||||
{
|
||||
try
|
||||
@@ -114,19 +118,6 @@ public class UsageViewModel : INotifyPropertyChanged
|
||||
catch { }
|
||||
}
|
||||
|
||||
bool isAuth = !string.IsNullOrEmpty(email) || !string.IsNullOrEmpty(orgId) || limits.Count > 0;
|
||||
if (!isAuth && cookies.Count > 0)
|
||||
{
|
||||
// Cookies exist but nothing worked — session likely expired
|
||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
IsSignedIn = false;
|
||||
ErrorMessage = "Session expired — click Sign In to re-authenticate.";
|
||||
IsLoading = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var limit in limits)
|
||||
{
|
||||
var key = limit.Window.ToString();
|
||||
@@ -144,6 +135,8 @@ public class UsageViewModel : INotifyPropertyChanged
|
||||
Overage = overage;
|
||||
Prepaid = prepaid;
|
||||
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;
|
||||
ErrorMessage = null;
|
||||
LastUpdated = DateTime.Now;
|
||||
@@ -198,11 +191,21 @@ public class UsageViewModel : INotifyPropertyChanged
|
||||
try
|
||||
{
|
||||
const string script = @"(async()=>{try{
|
||||
const b=await(await fetch('/api/bootstrap',{headers:{accept:'application/json'}})).json();
|
||||
const id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid||null;
|
||||
const em=b?.account?.email_address||null;
|
||||
if(!id)return{email:em,orgId:null,usage:null};
|
||||
const u=await(await fetch('/api/organizations/'+id+'/usage',{headers:{accept:'application/json'}})).json();
|
||||
const h={headers:{accept:'application/json'}};
|
||||
const b=await(await fetch('/api/bootstrap',h)).json();
|
||||
let id=b?.memberships?.[0]?.organization?.uuid||b?.organizations?.[0]?.uuid
|
||||
||b?.default_organization?.uuid||null;
|
||||
const em=b?.account?.email_address||b?.account?.email||b?.email||null;
|
||||
if(!id){
|
||||
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(!id){
|
||||
try{const pu=await(await fetch('/api/usage',h)).json();
|
||||
if(pu&&!pu.error)return{email:em,orgId:null,usage:pu};}catch(e3){}
|
||||
return{email:em,orgId:null,usage:null};
|
||||
}
|
||||
const u=await(await fetch('/api/organizations/'+id+'/usage',h)).json();
|
||||
return{email:em,orgId:id,usage:u};
|
||||
}catch(ex){return null;}})()";
|
||||
|
||||
@@ -243,6 +246,38 @@ public class UsageViewModel : INotifyPropertyChanged
|
||||
catch { return ([], null, null); }
|
||||
}
|
||||
|
||||
public async Task LoadFromCacheAsync()
|
||||
{
|
||||
var email = AppSettings.Default.Email;
|
||||
var orgId = AppSettings.Default.OrgId;
|
||||
var cookie = AppSettings.Default.CookieStore;
|
||||
|
||||
bool isAuth = !string.IsNullOrEmpty(email) || !string.IsNullOrEmpty(orgId)
|
||||
|| !string.IsNullOrEmpty(cookie);
|
||||
if (!isAuth) return;
|
||||
|
||||
List<AgentLimit> limits = [];
|
||||
if (!string.IsNullOrEmpty(AppSettings.Default.UsageJson))
|
||||
{
|
||||
try
|
||||
{
|
||||
var cached = JsonSerializer.Deserialize<UsageResponse>(
|
||||
AppSettings.Default.UsageJson, JsonOpts);
|
||||
limits = BuildLimits(cached);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(email)) UserEmail = email;
|
||||
if (limits.Count > 0) Limits = limits;
|
||||
IsSignedIn = true;
|
||||
ErrorMessage = limits.Count == 0 ? "Signed in — refreshing data…" : null;
|
||||
LastUpdated = limits.Count > 0 ? DateTime.Now : LastUpdated;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task SignOutAsync()
|
||||
{
|
||||
AppSettings.Default.CookieStore = "";
|
||||
@@ -276,7 +311,7 @@ public class UsageViewModel : INotifyPropertyChanged
|
||||
public static void SaveCookies(IEnumerable<CoreWebView2Cookie> cookies)
|
||||
{
|
||||
var entries = cookies
|
||||
.Where(c => c.Domain.Contains("claude.ai"))
|
||||
.Where(c => c.Domain.Contains("claude.ai") || c.Domain.Contains("anthropic.com"))
|
||||
.Select(c => new CookieEntry { Name = c.Name, Value = c.Value, Domain = c.Domain, Path = c.Path })
|
||||
.ToList();
|
||||
AppSettings.Default.CookieStore = JsonSerializer.Serialize(entries);
|
||||
|
||||
Reference in New Issue
Block a user