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:
@@ -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.8</string>
|
<string>1.2.1-beta.9</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>56</string>
|
<string>57</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>13.0</string>
|
<string>13.0</string>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
|
|||||||
@@ -41,10 +41,12 @@ struct LoginWebView: NSViewRepresentable {
|
|||||||
// cookie domain or name.
|
// cookie domain or name.
|
||||||
webView.callAsyncJavaScript(
|
webView.callAsyncJavaScript(
|
||||||
"const r = await fetch('/api/bootstrap', {credentials: 'include'}); return r.status;",
|
"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
|
) { [weak self] result in
|
||||||
guard let self, !self.didAuthenticate else { return }
|
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
|
self.didAuthenticate = true
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
||||||
self.onAuthenticated()
|
self.onAuthenticated()
|
||||||
|
|||||||
Reference in New Issue
Block a user