From c5a8d098f75233ede7f4864162faff3b6b534372 Mon Sep 17 00:00:00 2001 From: apkc5 Date: Sat, 28 Nov 2026 11:23:47 +0900 Subject: [PATCH] v0.4.12 fix: TabTearOff helpers are @MainActor (diag run 38 errors) + remove DiagTypecheck phase --- .../SnapBrowser.xcodeproj/project.pbxproj | 23 ------------- SnapBrowser/SnapBrowser/ContentView.swift | 34 +++++++++++++------ 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/SnapBrowser/SnapBrowser.xcodeproj/project.pbxproj b/SnapBrowser/SnapBrowser.xcodeproj/project.pbxproj index 8964433..242d595 100644 --- a/SnapBrowser/SnapBrowser.xcodeproj/project.pbxproj +++ b/SnapBrowser/SnapBrowser.xcodeproj/project.pbxproj @@ -148,7 +148,6 @@ isa = PBXNativeTarget; buildConfigurationList = 110000000000000000000002 /* Build configuration list for PBXNativeTarget "SnapBrowser" */; buildPhases = ( - 0F0000000000000000000004 /* DiagTypecheck */, 0F0000000000000000000001 /* Sources */, 0F0000000000000000000002 /* Frameworks */, 0F0000000000000000000003 /* Resources */, @@ -209,28 +208,6 @@ -/* Begin PBXShellScriptBuildPhase section */ - 0F0000000000000000000004 /* DiagTypecheck */ = { - isa = PBXShellScriptBuildPhase; - alwaysOutOfDate = 1; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - ); - name = DiagTypecheck; - outputFileListPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "set +e\nERR=/tmp/diag_errors.txt\n{\necho \"DiagTypecheck run ${GITHUB_RUN_NUMBER:-?} target ios17.0\"\nxcrun swiftc --version\nSDKPATH=\"$(xcrun --sdk iphoneos --show-sdk-path)\"\necho \"SDK: $SDKPATH\"\nls \"$SRCROOT/SnapBrowser\"\nxcrun swiftc -typecheck -sdk \"$SDKPATH\" -target arm64-apple-ios17.0 -module-name SnapBrowser \"$SRCROOT\"/SnapBrowser/*.swift\necho \"typecheck exit: $?\"\n} > \"$ERR\" 2>&1\nREPO=\"$(cd \"$SRCROOT/..\" && pwd)\"\ncd \"$REPO\" || exit 0\ngit fetch origin diag >/dev/null 2>&1\nWT=\"$(mktemp -d)/diagwt\"\nif git show-ref --verify --quiet refs/remotes/origin/diag; then\n git worktree add \"$WT\" -B diag origin/diag >/dev/null 2>&1\nelse\n git worktree add \"$WT\" -B diag >/dev/null 2>&1\nfi\nif [ -d \"$WT\" ]; then\n cp \"$ERR\" \"$WT/errors.txt\"\n cd \"$WT\" || exit 0\n git add errors.txt >/dev/null 2>&1\n git -c user.email=diag@local -c user.name=diag commit -m \"diag typecheck\" >/dev/null 2>&1\n git push origin diag >/dev/null 2>&1\n cd \"$REPO\" || exit 0\n git worktree remove --force \"$WT\" >/dev/null 2>&1\nfi\nexit 0\n"; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ 0F0000000000000000000001 /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/SnapBrowser/SnapBrowser/ContentView.swift b/SnapBrowser/SnapBrowser/ContentView.swift index f2b4d81..db8e794 100644 --- a/SnapBrowser/SnapBrowser/ContentView.swift +++ b/SnapBrowser/SnapBrowser/ContentView.swift @@ -1473,6 +1473,10 @@ enum TabTearOff { /// archive folder, else its URL, else nothing (a start-page tab /// reopens as a start page). The privacy flag always rides /// along so the receiver can rebuild the tab in the same class. + /// @MainActor because BrowserTab's state is main-actor isolated + /// (the old in-View tearOff got that isolation from View itself; + /// this enum does not). + @MainActor static func activity(for tab: BrowserTab) -> NSUserActivity { let activity = NSUserActivity(activityType: activityType) activity.title = "タブを新しいウィンドウで開く" @@ -1488,16 +1492,23 @@ enum TabTearOff { /// Tear-off proper: ask UIKit for a NEW scene carrying this tab. /// The error handler is the only failure signal the API gives, - /// so the original tab is closed (move, not copy) by a work item - /// that the error handler cancels if activation fails. + /// so the original tab is closed (move, not copy) by a delayed + /// task that stands down if the handler reported an error first. + /// (Up to v0.4.11 this was a DispatchWorkItem scheduled from the + /// View; as a nonisolated static here it must schedule through a + /// @MainActor Task instead — see the v0.4.12 diag round.) + @MainActor static func moveToNewWindow(_ tab: BrowserTab, manager: BrowserModel) { - let closeWork = DispatchWorkItem { manager.closeTab(tab) } + var activationFailed = false UIApplication.shared.requestSceneSessionActivation( nil, userActivity: activity(for: tab), options: nil ) { error in - if error != nil { closeWork.cancel() } + if error != nil { activationFailed = true } + } + Task { @MainActor in + try? await Task.sleep(nanoseconds: 800_000_000) + if !activationFailed { manager.closeTab(tab) } } - DispatchQueue.main.asyncAfter(deadline: .now() + 0.8, execute: closeWork) } /// A new window showing a fresh start page, in the requested @@ -1521,12 +1532,13 @@ enum TabTearOff { /// same class. Splitting never crosses the privacy line: the /// `isPrivate` tray only ever spawns private tabs. Activations /// are staggered so UIKit takes them one at a time; each moved - /// tab still closes through moveToNewWindow's error-cancelled - /// work item. NOTE: no public API lets an app propose a window + /// tab still closes through moveToNewWindow's error-aware + /// delayed close. NOTE: no public API lets an app propose a window /// frame on iPadOS (UIWindowScene.GeometryPreferences has no /// iPad variant with a frame, and activation options carry no /// geometry), so the windows open wherever the system puts /// them — the final snap into a tile stays an OS gesture. + @MainActor static func splitWindows(count: Int, isPrivate: Bool, manager: BrowserModel) { let tray = manager.tabs.filter { $0.isPrivate == isPrivate } guard count >= 2, !tray.isEmpty else { return } @@ -1537,14 +1549,16 @@ enum TabTearOff { else { return } let followers = Array(tray.dropFirst(keepIndex + 1)) for slot in 0..<(count - 1) { - let delay = 0.25 * Double(slot) + let delay = UInt64(slot) * 250_000_000 if slot < followers.count { let tab = followers[slot] - DispatchQueue.main.asyncAfter(deadline: .now() + delay) { + Task { @MainActor in + if delay > 0 { try? await Task.sleep(nanoseconds: delay) } moveToNewWindow(tab, manager: manager) } } else { - DispatchQueue.main.asyncAfter(deadline: .now() + delay) { + Task { @MainActor in + if delay > 0 { try? await Task.sleep(nanoseconds: delay) } spawnStartPageWindow(isPrivate: isPrivate) } }