Run a virtual iPhone on an Apple Silicon Mac.
Swift
fix(launchpad): relaunch after the Host Setup sheet has closed
tylinux8e74ea7d92db
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadModel.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadModel.swiftindex a8b6505d..3419e328 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadModel.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadModel.swift@@ -37,6 +37,8 @@ final class VPhoneLaunchpadModel {var panel: Panel?/// The panel to open once the sheet on screen has closed.private var queuedPanel: Panel?+ /// Runs once the sheet on screen has finished closing.+ private var pendingAfterDismiss: (() -> Void)?private(set) var isStarted = falseinit() {@@ -66,11 +68,23 @@ final class VPhoneLaunchpadModel {/// `next` here would swap it into the closing sheet. The next turn of the/// main actor runs after the sheet has gone.func panelDidDismiss() {- guard let next = queuedPanel else {- return- }+ let next = queuedPanel+ let pending = pendingAfterDismissqueuedPanel = nil- Task { panel = next }+ pendingAfterDismiss = nil+ guard next != nil || pending != nil else { return }+ Task {+ if let next {+ panel = next+ }+ pending?()+ }+ }++ /// Runs `action` on the next turn after the sheet on screen has closed.+ /// The sheet is still attached when its dismiss handler runs.+ func afterSheetDismissed(_ action: @escaping () -> Void) {+ pendingAfterDismiss = action}// MARK: - Attentiondiff --git a/VPhoneLaunchpad/VPhoneLaunchpad/HostSetup/VPhoneLaunchpadHostSetup.swift b/VPhoneLaunchpad/VPhoneLaunchpad/HostSetup/VPhoneLaunchpadHostSetup.swiftindex 473fb834..6a2b42d4 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/HostSetup/VPhoneLaunchpadHostSetup.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/HostSetup/VPhoneLaunchpadHostSetup.swift@@ -199,6 +199,11 @@ final class VPhoneLaunchpadHostSetup {/// Quits and opens Launchpad again so a new Developer Tools grant/// applies. A detached waiter opens the app once this process has exited./// No machine can be in creation here: Core Bundle needs this access.+ ///+ /// Call this only after the sheet that triggered it has closed.+ /// Terminating while a sheet is still attached makes SwiftUI answer+ /// `.terminateLater` and never reply, so the quit stalls and every later+ /// attempt is ignored.func relaunch() {let waiter = Process()waiter.executableURL = URL(fileURLWithPath: "/bin/sh")diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/HostSetup/VPhoneLaunchpadHostSetupView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/HostSetup/VPhoneLaunchpadHostSetupView.swiftindex 0536a2ea..a9aeb12e 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/HostSetup/VPhoneLaunchpadHostSetupView.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/HostSetup/VPhoneLaunchpadHostSetupView.swift@@ -144,7 +144,10 @@ struct VPhoneLaunchpadHostSetupView: View {}if host.needsRelaunch {Button("Reopen") {- host.relaunch()+ // The sheet is still attached when its dismiss handler+ // runs; relaunch on the turn after it has gone.+ model.afterSheetDismissed { host.relaunch() }+ dismiss()}}}