Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Keep Launchpad running when a machine leaves the list

Jacky62d788060964
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadApp.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadApp.swift
index 9b5189dd..1e81437e 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadApp.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadApp.swift
@@ -7,6 +7,14 @@ struct VPhoneLaunchpadApp: App {
@State private var model = VPhoneLaunchpadModel()
@AppStorage(VPhoneLaunchpadMenuBar.key) private var showsInMenuBar = false
+ init() {
+ // AppKit must not restore saved window state. Everything starts from
+ // the window's task, so a launch that restores a state with no window
+ // in it never opens the control socket, and after a crash AppKit
+ // holds the launch at an alert about reopening windows.
+ UserDefaults.standard.register(defaults: ["ApplePersistenceIgnoreState": true])
+ }
+
var body: some Scene {
Window(Text(verbatim: "vphone-launchpad"), id: "main") {
VPhoneLaunchpadRootView()
@@ -14,6 +22,8 @@ struct VPhoneLaunchpadApp: App {
.onAppear { delegate.model = model }
}
.windowToolbarStyle(.unified(showsTitle: false))
+ // Nor is any saved: the window's frame is kept under its own name.
+ .restorationBehavior(.disabled)
.commands {
CommandGroup(replacing: .newItem) {}
CommandGroup(after: .appSettings) {
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift
index d6592e6f..063120bb 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift
@@ -71,6 +71,12 @@
model.machines.selection = [path("research-01")]
await shot("05-machines", suffix)
+ // A deleted machine takes its table row with it. A cell that
+ // reads the model from the environment crashes the run here
+ // unless the column injects it.
+ model.machines.applyPreview(removing: labMachine)
+ await shot("05c-machines-after-delete", suffix)
+ model.machines.applyPreview(creation: creation)
model.showsInspector = false
await shot("05a-machines-no-inspector", suffix)
model.showsInspector = true
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift
index bdbcdf94..f639f2d4 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift
@@ -739,5 +739,12 @@ final class VPhoneLaunchpadMachineLibrary {
return (machine.path, binding)
})
}
+
+ /// The mock list without one machine, as a refresh leaves it after
+ /// the machine is deleted.
+ func applyPreview(removing machine: Path) {
+ machines.removeAll { $0.path == machine }
+ selection.remove(machine)
+ }
}
#endif
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift
index 30d2793a..3ca28a77 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift
@@ -366,7 +366,11 @@ struct VPhoneLaunchpadMachinesView: View {
}
.width(min: 110, ideal: 120)
TableColumn("Core Bundle") { machine in
+ // Each cell is a hosting view of its own. When its row leaves
+ // the table, the cell is updated once more with an empty
+ // environment, where reading the model is a fatal error.
VPhoneLaunchpadMachineBundleLabel(machine: machine.path)
+ .environment(model)
}
.width(min: 70, ideal: 90)
TableColumn("State") { machine in