Skip to content

Commit ace7ab8

Browse files
committed
Fix MainActor bridge: use withCheckedThrowingContinuation for WKWebView fetch
1 parent 65b121d commit ace7ab8

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

Sources/CodexBarCore/Providers/StepFun/StepFunDashboardFetcher.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,22 @@ public struct StepFunDashboardFetcher {
179179

180180
return ScrapeResult(isLoginPage: false, bodyText: bodyText, snapshot: snapshot)
181181
}
182+
183+
/// Bridge for calling from non-MainActor contexts (e.g. ProviderFetchStrategy).
184+
public nonisolated static func fetchFromMainActor(
185+
timeout: TimeInterval = 30) async throws -> DashboardSnapshot
186+
{
187+
try await withCheckedThrowingContinuation { continuation in
188+
Task { @MainActor in
189+
do {
190+
let fetcher = StepFunDashboardFetcher()
191+
let snapshot = try await fetcher.fetchDashboard(timeout: timeout)
192+
continuation.resume(returning: snapshot)
193+
} catch {
194+
continuation.resume(throwing: error)
195+
}
196+
}
197+
}
198+
}
182199
}
183200
#endif

Sources/CodexBarCore/Providers/StepFun/StepFunProviderDescriptor.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ struct StepFunWebFetchStrategy: ProviderFetchStrategy {
6464
#if os(macOS)
6565
if context.settings?.stepfun?.cookieSource != .off {
6666
do {
67-
dashboardSnapshot = try await MainActor.run {
68-
let fetcher = StepFunDashboardFetcher()
69-
return try await fetcher.fetchDashboard(timeout: 20)
70-
}
67+
dashboardSnapshot = try await StepFunDashboardFetcher.fetchFromMainActor(timeout: 20)
7168
Self.log.debug("Got StepFun plan data from WKWebView dashboard")
7269
} catch {
7370
Self.log.debug("StepFun dashboard fetch failed: \(error.localizedDescription)")

0 commit comments

Comments
 (0)