Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a950392a6f | ||
|
|
8087cc029d | ||
|
|
11f9e0c9b6 | ||
|
|
cc835ee2b0 |
@@ -15,9 +15,9 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.2.1-beta.12</string>
|
<string>1.2.1-beta.13</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>60</string>
|
<string>61</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>13.0</string>
|
<string>13.0</string>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ class UsageViewModel: ObservableObject {
|
|||||||
// Background WKWebView used for all API calls — runs fetch() in the page's auth context
|
// Background WKWebView used for all API calls — runs fetch() in the page's auth context
|
||||||
private var apiWebView: WKWebView?
|
private var apiWebView: WKWebView?
|
||||||
private var apiDelegate: APIWebViewDelegate?
|
private var apiDelegate: APIWebViewDelegate?
|
||||||
|
// Tracks whether the background WebView has finished its current navigation
|
||||||
|
private var apiWebViewLoaded = false
|
||||||
|
private var apiReadyContinuations: [CheckedContinuation<Void, Never>] = []
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
let saved = UserDefaults.standard.double(forKey: "refresh_interval")
|
let saved = UserDefaults.standard.double(forKey: "refresh_interval")
|
||||||
@@ -53,22 +56,46 @@ class UsageViewModel: ObservableObject {
|
|||||||
config.websiteDataStore = WKWebsiteDataStore.default()
|
config.websiteDataStore = WKWebsiteDataStore.default()
|
||||||
let wv = WKWebView(frame: CGRect(x: 0, y: 0, width: 1, height: 1), configuration: config)
|
let wv = WKWebView(frame: CGRect(x: 0, y: 0, width: 1, height: 1), configuration: config)
|
||||||
let del = APIWebViewDelegate()
|
let del = APIWebViewDelegate()
|
||||||
|
del.onNavigationEnd = { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
self.apiWebViewLoaded = true
|
||||||
|
self.resumeAPIReadyContinuations()
|
||||||
|
}
|
||||||
wv.navigationDelegate = del
|
wv.navigationDelegate = del
|
||||||
apiWebView = wv
|
apiWebView = wv
|
||||||
apiDelegate = del
|
apiDelegate = del
|
||||||
wv.load(URLRequest(url: URL(string: "https://claude.ai")!))
|
wv.load(URLRequest(url: URL(string: "https://claude.ai")!))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func resumeAPIReadyContinuations() {
|
||||||
|
let pending = apiReadyContinuations
|
||||||
|
apiReadyContinuations.removeAll()
|
||||||
|
pending.forEach { $0.resume() }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Suspends until the background WebView has finished loading.
|
||||||
|
private func waitForAPIWebViewReady() async {
|
||||||
|
guard !apiWebViewLoaded else { return }
|
||||||
|
await withCheckedContinuation { cont in
|
||||||
|
apiReadyContinuations.append(cont)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Called after login: reloads the background WebView to pick up the new session, then refreshes.
|
// Called after login: reloads the background WebView to pick up the new session, then refreshes.
|
||||||
func reloadAPIWebViewAndRefresh() async {
|
func reloadAPIWebViewAndRefresh() async {
|
||||||
guard let wv = apiWebView, let del = apiDelegate else {
|
guard let wv = apiWebView, let del = apiDelegate else {
|
||||||
await refresh()
|
await refresh()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await withCheckedContinuation { (cont: CheckedContinuation<Void, Never>) in
|
// Reset readiness and wire up the reload callback before starting the load
|
||||||
del.onDidFinish = { cont.resume() }
|
apiWebViewLoaded = false
|
||||||
wv.load(URLRequest(url: URL(string: "https://claude.ai")!))
|
del.onNavigationEnd = { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
self.apiWebViewLoaded = true
|
||||||
|
self.resumeAPIReadyContinuations()
|
||||||
}
|
}
|
||||||
|
wv.load(URLRequest(url: URL(string: "https://claude.ai")!))
|
||||||
|
await waitForAPIWebViewReady()
|
||||||
// Brief pause for the page's JS auth state to settle after navigation
|
// Brief pause for the page's JS auth state to settle after navigation
|
||||||
try? await Task.sleep(nanoseconds: 500_000_000)
|
try? await Task.sleep(nanoseconds: 500_000_000)
|
||||||
await refresh()
|
await refresh()
|
||||||
@@ -77,6 +104,8 @@ class UsageViewModel: ObservableObject {
|
|||||||
// Runs a fetch() call inside the background WebView's page context (same-origin, credentials included).
|
// Runs a fetch() call inside the background WebView's page context (same-origin, credentials included).
|
||||||
private func webViewFetch(_ path: String) async throws -> (statusCode: Int, body: String) {
|
private func webViewFetch(_ path: String) async throws -> (statusCode: Int, body: String) {
|
||||||
guard let wv = apiWebView else { throw AppError.networkError }
|
guard let wv = apiWebView else { throw AppError.networkError }
|
||||||
|
// Wait until the WebView has finished loading claude.ai so fetch() has a valid auth context
|
||||||
|
await waitForAPIWebViewReady()
|
||||||
let js = "const r = await fetch(path, {credentials:'include'}); return {s: r.status, b: await r.text()};"
|
let js = "const r = await fetch(path, {credentials:'include'}); return {s: r.status, b: await r.text()};"
|
||||||
let result = try await wv.callAsyncJavaScript(
|
let result = try await wv.callAsyncJavaScript(
|
||||||
js, arguments: ["path": path], in: nil, in: .page)
|
js, arguments: ["path": path], in: nil, in: .page)
|
||||||
@@ -107,6 +136,14 @@ class UsageViewModel: ObservableObject {
|
|||||||
prepaidCredits = nil
|
prepaidCredits = nil
|
||||||
overageSpendLimit = nil
|
overageSpendLimit = nil
|
||||||
// Reload background WebView to clear its session too
|
// Reload background WebView to clear its session too
|
||||||
|
apiWebViewLoaded = false
|
||||||
|
if let del = apiDelegate {
|
||||||
|
del.onNavigationEnd = { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
self.apiWebViewLoaded = true
|
||||||
|
self.resumeAPIReadyContinuations()
|
||||||
|
}
|
||||||
|
}
|
||||||
apiWebView?.load(URLRequest(url: URL(string: "https://claude.ai")!))
|
apiWebView?.load(URLRequest(url: URL(string: "https://claude.ai")!))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,16 +390,17 @@ class UsageViewModel: ObservableObject {
|
|||||||
// MARK: - API WebView Delegate
|
// MARK: - API WebView Delegate
|
||||||
|
|
||||||
private class APIWebViewDelegate: NSObject, WKNavigationDelegate {
|
private class APIWebViewDelegate: NSObject, WKNavigationDelegate {
|
||||||
var onDidFinish: (() -> Void)?
|
// Called on every didFinish / didFail — not cleared after firing, so subsequent navigations also trigger it
|
||||||
|
var onNavigationEnd: (() -> Void)?
|
||||||
|
|
||||||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
||||||
let cb = onDidFinish; onDidFinish = nil; cb?()
|
onNavigationEnd?()
|
||||||
}
|
}
|
||||||
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
||||||
let cb = onDidFinish; onDidFinish = nil; cb?()
|
onNavigationEnd?()
|
||||||
}
|
}
|
||||||
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
|
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
|
||||||
let cb = onDidFinish; onDidFinish = nil; cb?()
|
onNavigationEnd?()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
[](https://swift.org)
|
[](https://swift.org)
|
||||||
[](https://github.com/superdooper86/claudechecker/releases)
|
[](https://github.com/superdooper86/claudechecker/releases)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://github.com/superdooper86/claudechecker/releases/tag/v1.2.1-beta.11) <!-- BETA_BADGE -->
|
[](https://github.com/superdooper86/claudechecker/releases/tag/v1.2.1-beta.12) <!-- BETA_BADGE -->
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
## What's new in v1.2.1
|
## What's new in v1.2.1
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
- Fixed usage data not loading after sign-in — API calls now run inside a persistent background WebView using the page's own fetch(), so all credentials (cookies, localStorage tokens, etc.) are included automatically
|
- Fixed a timing race in the background API WebView — `refresh()` now correctly waits for the WebView to finish loading before making API calls, preventing silent failures on startup
|
||||||
|
- Fixed usage data not loading after sign-in — API calls now run inside a persistent background WebView using the page's own fetch(), so all credentials (cookies, httpOnly tokens, etc.) are included automatically
|
||||||
- Fixed "Not signed in" showing after login — the background WebView is now reloaded after sign-in to pick up the new session before the first data refresh
|
- Fixed "Not signed in" showing after login — the background WebView is now reloaded after sign-in to pick up the new session before the first data refresh
|
||||||
- Fixed "Not signed in" showing incorrectly on launch when the session was already active
|
- Fixed "Not signed in" showing incorrectly on launch when the session was already active
|
||||||
- Sign-in state is now detected immediately from stored cookies on startup, before the first data refresh completes
|
- Sign-in state is now detected immediately from stored cookies on startup, before the first data refresh completes
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "1.2.1-beta.11",
|
"version": "1.2.1-beta.12",
|
||||||
"url": "https://github.com/superdooper86/claudechecker/releases/download/v1.2.1-beta.11/ClaudeChecker.zip",
|
"url": "https://github.com/superdooper86/claudechecker/releases/download/v1.2.1-beta.12/ClaudeChecker.zip",
|
||||||
"notes": "## What's new in v1.2.1\n\n### Bug fixes\n- Fixed \"Not signed in\" showing incorrectly on launch when the session was already active\n- Sign-in state is now detected immediately from stored cookies on startup, before the first data refresh completes\n- Fixed login window auto-closing before the user could sign in — the login window now correctly loads the `/login` page so it only detects auth after the actual sign-in redirect\n- Fixed \"No API key configured\" showing after signing out — now correctly shows \"Not signed in\" with a prompt to sign in\n- Added `/api/organizations` as a final fallback for org ID resolution when the bootstrap API response doesn't include it\n- Fixed usage data not loading — API requests now include required browser-like headers (Origin, Referer, User-Agent)\n- Fixed Settings incorrectly showing \"Signed in\" after a failed refresh — sign-in state now resets when authentication fails\n- Rewrote login detection to use the WebView's own fetch call instead of inspecting cookie domains — correctly detects auth regardless of which domain the session token is stored on\n- Fixed API requests not including session cookies — now sends all cookies from the app's WebView store rather than filtering by domain"
|
"notes": "## What's new in v1.2.1\n\n### Bug fixes\n- Fixed usage data not loading after sign-in — API calls now run inside a persistent background WebView using the page's own fetch(), so all credentials (cookies, localStorage tokens, etc.) are included automatically\n- Fixed \"Not signed in\" showing after login — the background WebView is now reloaded after sign-in to pick up the new session before the first data refresh\n- Fixed \"Not signed in\" showing incorrectly on launch when the session was already active\n- Sign-in state is now detected immediately from stored cookies on startup, before the first data refresh completes\n- Fixed login window auto-closing before the user could sign in — the login window now correctly loads the `/login` page so it only detects auth after the actual sign-in redirect\n- Fixed \"No API key configured\" showing after signing out — now correctly shows \"Not signed in\" with a prompt to sign in\n- Added `/api/organizations` as a final fallback for org ID resolution when the bootstrap API response doesn't include it\n- Fixed Settings incorrectly showing \"Signed in\" after a failed refresh — sign-in state now resets when authentication fails\n- Rewrote login detection to use KVO on the WebView URL — correctly detects auth for Next.js SPA navigation (history.pushState) that doesn't trigger didFinish"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user