Compare commits

...
4 changed files with 71 additions and 19 deletions
+1
View File
@@ -37,6 +37,7 @@ public partial class App : Application
_ = Task.Run(async () => _ = Task.Run(async () =>
{ {
await ViewModel.LoadFromCacheAsync();
await Task.Delay(1000); await Task.Delay(1000);
await ViewModel.RefreshAsync(); await ViewModel.RefreshAsync();
await Updater.CheckForUpdatesAsync(); await Updater.CheckForUpdatesAsync();
+3
View File
@@ -15,6 +15,9 @@ public class AppSettings
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; } = ""; public string DebugInfo { get; set; } = "";
public string PlanLabel { get; set; } = "";
public string OverageJson { get; set; } = "";
public string PrepaidJson { 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),
+6 -4
View File
@@ -1,6 +1,8 @@
## What's new in beta.10 ## What's new in beta.36
### Bug fixes ### Bug fixes
- Limits now update correctly on each refresh cycle - Settings no longer incorrectly shows "Not signed in" when limits are working
- Session expiry is detected and prompts re-authentication instead of silently showing stale data - Session Diary now shows correctly after the first successful refresh
- Plan name (e.g. Pro, Max) is now read from the API instead of being hardcoded - Extra Usage Credits section now restored from cache on startup
- Plan name, overage, and prepaid credits are now cached and shown immediately on launch
- App now loads cached state instantly on startup before the background refresh completes
+61 -15
View File
@@ -117,17 +117,6 @@ public class UsageViewModel : INotifyPropertyChanged
catch (Exception ex) catch (Exception ex)
{ {
refreshError = ex.Message; refreshError = ex.Message;
bool authFailed = ex.Message.Contains("re-authenticate");
if (authFailed)
{
await Application.Current.Dispatcher.InvokeAsync(() =>
{
IsSignedIn = false;
ErrorMessage = ex.Message;
IsLoading = false;
});
return;
}
} }
} }
@@ -189,7 +178,35 @@ public class UsageViewModel : INotifyPropertyChanged
if (!bootstrapResp.IsSuccessStatusCode) if (!bootstrapResp.IsSuccessStatusCode)
throw new Exception($"Bootstrap failed ({(int)bootstrapResp.StatusCode})."); throw new Exception($"Bootstrap failed ({(int)bootstrapResp.StatusCode}).");
var (email, orgId, planLabel) = ParseBootstrap(await bootstrapResp.Content.ReadAsStringAsync()); var bootstrapJson = await bootstrapResp.Content.ReadAsStringAsync();
// Targeted debug: log org property names + capabilities value so we can see
// exactly what the HttpClient bootstrap response contains
try
{
using var dbgDoc = System.Text.Json.JsonDocument.Parse(bootstrapJson);
var dbgRoot = dbgDoc.RootElement;
var dbg = $"len:{bootstrapJson.Length}";
if (dbgRoot.TryGetProperty("account", out var dbgAcct) &&
dbgAcct.TryGetProperty("memberships", out var dbgMems) &&
dbgMems.GetArrayLength() > 0 &&
dbgMems[0].TryGetProperty("organization", out var dbgOrg))
{
var keys = string.Join(",", dbgOrg.EnumerateObject().Select(p => p.Name));
dbg += $"|org_keys:{keys}";
if (dbgOrg.TryGetProperty("capabilities", out var dbgCaps))
dbg += $"|caps:{dbgCaps.GetRawText()}";
else
dbg += "|caps:MISSING";
}
else
{
dbg += "|no_memberships";
}
AppSettings.Default.DebugInfo = dbg;
AppSettings.Default.Save();
}
catch { /* debug only — never block refresh */ }
var (email, orgId, planLabel) = ParseBootstrap(bootstrapJson);
if (string.IsNullOrEmpty(orgId)) if (string.IsNullOrEmpty(orgId))
orgId = await FetchOrgIdFromListAsync(http); orgId = await FetchOrgIdFromListAsync(http);
@@ -217,6 +234,9 @@ public class UsageViewModel : INotifyPropertyChanged
// Persist fresh usage so cache reflects live data // Persist fresh usage so cache reflects live data
AppSettings.Default.UsageJson = usageJson; AppSettings.Default.UsageJson = usageJson;
if (!string.IsNullOrEmpty(planLabel)) AppSettings.Default.PlanLabel = planLabel;
if (ot.Result != null) AppSettings.Default.OverageJson = JsonSerializer.Serialize(ot.Result);
if (pt.Result != null) AppSettings.Default.PrepaidJson = JsonSerializer.Serialize(pt.Result);
AppSettings.Default.Save(); AppSettings.Default.Save();
return (BuildLimits(usage), ot.Result, pt.Result, usage?.ExtraUsage, email, orgId, planLabel, true); return (BuildLimits(usage), ot.Result, pt.Result, usage?.ExtraUsage, email, orgId, planLabel, true);
@@ -297,22 +317,48 @@ public class UsageViewModel : INotifyPropertyChanged
if (!isAuth) return; if (!isAuth) return;
List<AgentLimit> limits = []; List<AgentLimit> limits = [];
ExtraUsage? extraUsage = null;
OverageSpendLimit? overage = null;
PrepaidCredits? prepaid = null;
if (!string.IsNullOrEmpty(AppSettings.Default.UsageJson)) if (!string.IsNullOrEmpty(AppSettings.Default.UsageJson))
{ {
try try
{ {
var cached = JsonSerializer.Deserialize<UsageResponse>( var cached = JsonSerializer.Deserialize<UsageResponse>(
AppSettings.Default.UsageJson, JsonOpts); AppSettings.Default.UsageJson, JsonOpts);
limits = BuildLimits(cached); limits = BuildLimits(cached);
extraUsage = cached?.ExtraUsage;
} }
catch { } catch { }
} }
if (!string.IsNullOrEmpty(AppSettings.Default.OverageJson))
{
try { overage = JsonSerializer.Deserialize<OverageSpendLimit>(AppSettings.Default.OverageJson, JsonOpts); }
catch { }
}
if (!string.IsNullOrEmpty(AppSettings.Default.PrepaidJson))
{
try { prepaid = JsonSerializer.Deserialize<PrepaidCredits>(AppSettings.Default.PrepaidJson, JsonOpts); }
catch { }
}
// Attach persisted burn history to cached limits
foreach (var limit in limits)
{
var key = limit.Window.ToString();
if (_burnHistory.TryGetValue(key, out var hist) && hist.Count > 0)
limit.BurnHistory = [.. hist];
}
await Application.Current.Dispatcher.InvokeAsync(() => await Application.Current.Dispatcher.InvokeAsync(() =>
{ {
if (!string.IsNullOrEmpty(email)) UserEmail = email; if (!string.IsNullOrEmpty(email)) UserEmail = email;
// Always show cards — real data if available, placeholders if not if (!string.IsNullOrEmpty(AppSettings.Default.PlanLabel)) PlanLabel = AppSettings.Default.PlanLabel;
Limits = limits.Count > 0 ? limits : LoadPlaceholderLimits(); Limits = limits.Count > 0 ? limits : LoadPlaceholderLimits();
Overage = overage;
Prepaid = prepaid;
ExtraUsage = extraUsage;
IsSignedIn = true; IsSignedIn = true;
ErrorMessage = null; ErrorMessage = null;
LastUpdated = limits.Count > 0 ? DateTime.Now : LastUpdated; LastUpdated = limits.Count > 0 ? DateTime.Now : LastUpdated;