fix: NSNumber cast and use .page world in callAsyncJavaScript auth check

callAsyncJavaScript returns JS numbers as NSNumber (Double-backed).
'val as? Int' silently returns nil for 200.0, so onAuthenticated never
fired. Fixed with 'val as? NSNumber then .intValue == 200'.

Also switched content world from .defaultClient to .page so the fetch
runs in the same JS context as the loaded page.
This commit is contained in:
superdooper86
2026-05-11 10:22:59 +02:00
parent 2a0de269ff
commit b8826ace9b
2 changed files with 6 additions and 4 deletions
+2 -2
View File
@@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.1-beta.8</string>
<string>1.2.1-beta.9</string>
<key>CFBundleVersion</key>
<string>56</string>
<string>57</string>
<key>LSMinimumSystemVersion</key>
<string>13.0</string>
<key>LSUIElement</key>
+4 -2
View File
@@ -41,10 +41,12 @@ struct LoginWebView: NSViewRepresentable {
// cookie domain or name.
webView.callAsyncJavaScript(
"const r = await fetch('/api/bootstrap', {credentials: 'include'}); return r.status;",
arguments: [:], in: nil, in: .defaultClient
arguments: [:], in: nil, in: .page
) { [weak self] result in
guard let self, !self.didAuthenticate else { return }
if case .success(let val) = result, let status = val as? Int, status == 200 {
// JS numbers arrive as NSNumber (Double-backed), not Swift Int
if case .success(let val) = result,
let n = val as? NSNumber, n.intValue == 200 {
self.didAuthenticate = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.onAuthenticated()