Run a virtual iPhone on an Apple Silicon Mac.
Swift
Unlock a guest at startup when its machine asks for it
Jacky40440b1358f9
diff --git a/Documents/Downloads/README.md b/Documents/Downloads/README.mdindex cd5a5451..822f5497 100644--- a/Documents/Downloads/README.md+++ b/Documents/Downloads/README.md@@ -29,6 +29,7 @@ Use a `VPhone.bundle` from the same series as Launchpad. The series is the first| Launchpad | VPhone.bundle || --- | --- |+| 2.6.x | 2.6.x || 2.5.x | 2.5.x || 2.4.x | 2.4.x || 2.3.x | 2.3.x |diff --git a/Research/Guest/screen_unlock.md b/Research/Guest/screen_unlock.mdindex e9b4d4ac..ed669f18 100644--- a/Research/Guest/screen_unlock.md+++ b/Research/Guest/screen_unlock.md@@ -79,6 +79,32 @@ All on `unlocktest-iphone`, each followed by `device.screen` andSo the device is actually usable afterwards, not merely reporting unlocked.+## Unlock at startup++A machine whose `config.plist` has `unlocksAtStartup` (`vm config <name>+--unlock-at-startup on`, Device > Unlock at Startup, or Launchpad's machine+Settings) has `vphone-vm` call `screen.unlock` with a 60 s timeout when a+vphoned that has just started connects. vphoned's `/v1/health` carries+`instance`, a UUID made when it starts; the host keeps the last one it saw+across disconnects, so a probe that drops and reconnects to the same vphoned+is not unlocked again. A guest still in Setup Assistant is skipped, and a+passcode guest stays locked (the call refuses without a passcode, and none is+stored).++Measured on 2026-10-04 on `autounlock-iphone` (iPhone17,3, iOS 27.0 24A435,+no passcode, Auto-Lock 1 minute), bundle 2.6.0-local:++| Run | Setting | `device.screen` after boot |+| --- | --- | --- |+| VM start | off | locked at 5 s, dark from then on |+| VM start | on | locked at 4 s, unlocked and lit by 16 s; log `[unlock] dismissed the Lock Screen at startup` |+| `system.reboot {userspace: true}` in the running VM | on | new vphoned, unlocked and lit, then locked again by Auto-Lock after a minute |++The re-lock after a minute is the guest's own Auto-Lock acting on an unlocked+device, not a failed unlock. The very first reading after a boot can say+"unlocked, lit" before SpringBoard has started (see step 1 above), so a check+has to watch for a while, not trust one sample.+## Not yet measured- **Passcode guests.** Setting a passcode on a research guest is notdiff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.mdindex c2c9cc1a..022f5633 100644--- a/Research/vphoned_http_api.md+++ b/Research/vphoned_http_api.md@@ -330,6 +330,16 @@ at once; a dark but unlocked one is only woken. A guest with a passcode needsany key is sent. It needs no private entitlement. `timeout` is 1–60 seconds,10 by default. Measurements: `Research/Guest/screen_unlock.md`.+A machine with `unlocksAtStartup` in its `config.plist` (`vphone-cli vm config+<name> --unlock-at-startup on`, Device > Unlock at Startup in the VM window, or+the Startup section of a machine's Settings in Launchpad) has `vphone-vm` call+`screen.unlock` with a 60 s timeout when a vphoned that has just started+connects. `/v1/health` carries `instance`, a UUID vphoned makes when it starts,+so the host tells a start (guest boot, userspace reboot, a vphoned update) from+a probe it lost and found again; only a new instance is unlocked. A guest still+in Setup Assistant is left alone, and a guest with a passcode stays locked: the+passcode is never stored.+`time.timezone` (capability `timezone`; REST `GET/PUT /v1/timezone`) returns`{identifier, automatic, seconds_from_gmt}`: the Olson name`/var/db/timezone/localtime` points to under `/var/db/timezone/zoneinfo`, anddiff --git a/Skills/vphone-guest-control/references/guest-socket.md b/Skills/vphone-guest-control/references/guest-socket.mdindex d8631319..f794c6c1 100644--- a/Skills/vphone-guest-control/references/guest-socket.md+++ b/Skills/vphone-guest-control/references/guest-socket.md@@ -77,6 +77,8 @@ paste for long or non-ASCII text.- **Wake and unlock:** `vphone-launchpad-cli guest unlock myphone` (add`--passcode` when the guest has one). It works from any state; the keys onlytoggle. Check with `ping`, then `screenshot` to a file and look at it.+ A machine with `vm config <name> --unlock-at-startup on` (run through+ `vphone-launchpad-cli exec`) is unlocked by the host each time it starts.- **Home:** `{"t":"key","name":"home"}`; **power** wakes or locks.- **Open an app without hunting for its icon:** `apps.launch` with the bundle id.- **Scroll a list:** swipe from lower to upper y, e.g. 2600 → 1400 at x 645.diff --git a/VPhoneDaemon/Daemon/GuestAPI.swift b/VPhoneDaemon/Daemon/GuestAPI.swiftindex 77cd99f7..1d27a013 100644--- a/VPhoneDaemon/Daemon/GuestAPI.swift+++ b/VPhoneDaemon/Daemon/GuestAPI.swift@@ -47,6 +47,11 @@ enum GuestAPI {return sha256Hex(data)}()+ /// New each time vphoned starts: after a guest boot, a userspace reboot, an+ /// update or a crash. A host tells a vphoned that just started from a+ /// connection it lost and found again by this, not by reconnecting.+ static let instance = UUID().uuidString+static func sha256Hex(_ data: Data) -> String {SHA256.hash(data: data).map { String(format: "%02x", $0) }.joined()}@@ -76,6 +81,7 @@ enum GuestAPI {"api_version": 1,"status": "ok","binary_hash": binaryHash,+ "instance": instance,"ios": "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)","ip": ip ?? "","setup_pending": setupAssistantPending(),diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/VirtualMachine/VPhoneVirtualMachineCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/VirtualMachine/VPhoneVirtualMachineCommand.swiftindex 2faea210..5166debe 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/VirtualMachine/VPhoneVirtualMachineCommand.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/VirtualMachine/VPhoneVirtualMachineCommand.swift@@ -158,6 +158,7 @@ struct VPhoneVirtualMachineInfoCommand: ParsableCommand {print("mem: \(report.memoryMB) MB")print("disk: \(report.diskSizeBytes) bytes")print("net: \(describeNetwork(report.network))")+ print("unlock: \(report.unlocksAtStartup ? "on" : "off")")if let udid = report.udid {print("udid: \(udid)")}@@ -207,7 +208,7 @@ struct VPhoneVirtualMachineNewCommand: ParsableCommand {struct VPhoneVirtualMachineConfigCommand: ParsableCommand {static let configuration = CommandConfiguration(commandName: "config",- abstract: "Edit VM manifest fields (cpu/memory/network)",+ abstract: "Edit VM manifest fields (cpu/memory/network/startup)",discussion: """Network settings are read when the VM starts, so a change applies from the next launch.@@ -228,6 +229,10 @@ struct VPhoneVirtualMachineConfigCommand: ParsableCommand {address, usually 192.168.64.1; tunnel: the gateway, which leads to the Mac's loopback; \bridged: the Mac's address on that interface), instead of racing mDNS answers. \--mac-name off withdraws it. Applied each time vphone-vm connects to the guest.++ --unlock-at-startup on has vphone-vm wake the guest and dismiss its Lock Screen each time \+ vphoned starts in it: after the VM starts and after the guest reboots. A guest with a \+ passcode stays locked; the passcode is never stored. Applies from the next connect.""",)@@ -256,16 +261,20 @@ struct VPhoneVirtualMachineConfigCommand: ParsableCommand {var mdns: String?@Option(name: .long, help: "Have the guest resolve this Mac's .local name locally: on (default) | off")var macName: String?+ @Option(name: .long, help: "Unlock the guest when it starts: on | off (default)")+ var unlockAtStartup: String?func run() throws {let name = try VPhoneVirtualMachineSelection.resolveExisting(name, in: lib.library)let edit = try networkEdit(vmName: name)+ let unlocks = try unlockAtStartup.map { try Self.parseSwitch($0, option: "--unlock-at-startup") }let updated = try VPhoneBundleOperations.updateConfig(bundleNamed: name,in: lib.library,cpuCount: cpu,memoryMB: memory,networkEdit: edit,+ unlocksAtStartup: unlocks,)let m = updated.manifestprint(@@ -321,6 +330,14 @@ struct VPhoneVirtualMachineConfigCommand: ParsableCommand {return edit}+ private static func parseSwitch(_ value: String, option: String) throws -> Bool {+ switch value.lowercased() {+ case "on": return true+ case "off": return false+ default: throw ValidationError("\(option) takes on or off.")+ }+ }+private static func parseMode(_ s: String)throws -> VPhoneVirtualMachineManifest.NetworkConfig.NetworkMode{diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/Info.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/Info.plistindex 83dbb5f7..2f3f84c6 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/Info.plist+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/Info.plist@@ -11,7 +11,7 @@<key>CFBundleVersion</key><string>31</string><key>CFBundleShortVersionString</key>- <string>2.5.1</string>+ <string>2.6.0</string><key>NSMicrophoneUsageDescription</key><string>Shares this Mac's microphone with the virtual iPhone so apps running inside it can record.</string></dict>diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings b/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstringsindex 0f3fd3d8..b0350384 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings@@ -137,6 +137,111 @@}}},+ "Unable to Change Unlock at Startup" : {+ "extractionState" : "manual",+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Unable to Change Unlock at Startup"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "起動時のロック解除を変更できません"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "시작 시 잠금 해제를 변경할 수 없음"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Không thể thay đổi Mở khóa khi khởi động"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "无法更改启动时解锁"+ }+ }+ }+ },+ "Unlock at Startup" : {+ "extractionState" : "manual",+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Unlock at Startup"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "起動時にロックを解除"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "시작 시 잠금 해제"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Mở khóa khi khởi động"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "启动时解锁"+ }+ }+ }+ },+ "Wake the guest and dismiss its Lock Screen each time it starts. A guest with a passcode stays locked." : {+ "extractionState" : "manual",+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Wake the guest and dismiss its Lock Screen each time it starts. A guest with a passcode stays locked."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "ゲストが起動するたびに画面をスリープ解除し、ロック画面を閉じます。パスコードを設定したゲストはロックされたままです。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "게스트가 시작될 때마다 화면을 깨우고 잠금 화면을 닫습니다. 암호가 설정된 게스트는 잠긴 상태로 유지됩니다."+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Đánh thức máy khách và đóng Màn hình khóa mỗi khi khởi động. Máy khách có mật mã vẫn bị khóa."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "客户机每次启动时唤醒屏幕并关闭锁定屏幕。设有密码的客户机仍保持锁定。"+ }+ }+ }+ },"The virtual machine stopped and the keyboard setting was saved. Launch this machine again. Unable to restart: %@" : {"extractionState" : "manual","localizations" : {diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swiftindex 25d31329..bf53fca2 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift@@ -59,6 +59,14 @@ final class VPhoneGuestControl {/// name or a bridged address can change while the VM runs). Nil sends/// nothing.@ObservationIgnored var guestStaticNames: (() -> [VPhoneNetworking.StaticName])?+ /// Whether to wake the guest and dismiss its Lock Screen when a vphoned+ /// that has just started connects, from the manifest. Read at each connect,+ /// so a change from the menu holds from the next guest start.+ @ObservationIgnored var unlocksAtStartup = false+ /// The `instance` of the last vphoned connected to. Kept across+ /// disconnects: a lost probe reconnects to the same vphoned, which is not+ /// a start.+ @ObservationIgnored private var connectedInstance: String?/// Called whenever the address the guest reports changes, nil on disconnect.@ObservationIgnored var onGuestIPAddressChange: ((String?) -> Void)?@@ -201,6 +209,16 @@ final class VPhoneGuestControl {isConnected = trueprint("[control] connected to vphoned HTTP API (iOS \(guestIOSVersion ?? "?"))")onConnect?(guestCapabilities)+ let instance = info["instance"] as? String+ let started = instance == nil || instance != connectedInstance+ connectedInstance = instance+ if started, unlocksAtStartup, capabilities.contains("screen_unlock") {+ if setupPending {+ print("[unlock] Setup Assistant is pending; leaving the guest as it is")+ } else {+ Task { await unlockAtStartup() }+ }+ }if capabilities.contains("environment_update") {Task { await syncEnvironment() }}diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlSystem.swift b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlSystem.swiftindex 2a4bb2c6..a90da89d 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlSystem.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControlSystem.swift@@ -57,4 +57,24 @@ extension VPhoneGuestControl {let result = try await call("audio.host_latency", params: ["seconds": seconds])return result["changed"] as? Bool ?? false}++ // MARK: - Unlock at Startup++ /// Wakes a guest whose vphoned has just started and dismisses its Lock+ /// Screen through `screen.unlock`. vphoned can come up well before+ /// SpringBoard on a cold boot; the method waits for SpringBoard itself, so+ /// it is given the longest timeout it takes. A guest with a passcode+ /// refuses without one and stays locked: the passcode is never stored.+ func unlockAtStartup() async {+ do {+ let result = try await call("screen.unlock", params: ["timeout": 60])+ if result["was_locked"] as? Bool == true {+ print("[unlock] dismissed the Lock Screen at startup")+ } else {+ print("[unlock] the guest was already unlocked")+ }+ } catch {+ print("[unlock] could not unlock the guest at startup: \(error)")+ }+ }}diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuController.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuController.swiftindex 36da28e2..64b72698 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuController.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuController.swift@@ -24,6 +24,9 @@ class VPhoneMenuController {var hardwareKeyboardItem: NSMenuItem?var onHardwareKeyboardChange: ((Bool) async throws -> Void)?var onFrameRateDisplayChange: ((Bool) -> Void)?+ /// Saves the unlock-at-startup setting to this machine's config.plist.+ var onUnlockAtStartupChange: ((Bool) throws -> Void)?+ var unlockAtStartupItem: NSMenuItem?var onFilesPressed: (() -> Void)?var onKeychainPressed: (() -> Void)?diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuDevice.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuDevice.swiftindex 420b4dac..db83d5c8 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuDevice.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuDevice.swift@@ -104,6 +104,14 @@ extension VPhoneMenuController {addUDIDItems(to: menu)menu.addItem(NSMenuItem.separator())addSetupAssistantItem(to: menu)+ // Saved to this machine and read when vphoned next starts in the guest.+ let unlockItem = makeItem("Unlock at Startup", action: #selector(toggleUnlockAtStartup), symbol: "lock.open")+ unlockItem.state = control.unlocksAtStartup ? .on : .off+ unlockItem.toolTip = VPhoneLocalization.text(+ "Wake the guest and dismiss its Lock Screen each time it starts. A guest with a passcode stays locked.",+ )+ unlockAtStartupItem = unlockItem+ menu.addItem(unlockItem)let restart = makeItem("Restart Guest…", action: #selector(restartGuest), symbol: "arrow.clockwise")restart.isEnabled = falserestartGuestItem = restart@@ -262,6 +270,23 @@ extension VPhoneMenuController {captureView?.trackpadGesturesEnabled = enabled}+ /// Saved to this machine's config.plist; it takes effect from the next+ /// guest start and does not unlock the guest now.+ @objc func toggleUnlockAtStartup() {+ let enabled = !control.unlocksAtStartup+ do {+ try onUnlockAtStartupChange?(enabled)+ control.unlocksAtStartup = enabled+ unlockAtStartupItem?.state = enabled ? .on : .off+ } catch {+ VPhoneAlert.present(+ title: "Unable to Change Unlock at Startup",+ message: error.localizedDescription,+ style: .warning,+ )+ }+ }+/// Shows the guest's frame rate in the window subtitle. Persisted.@objc func toggleFrameRateDisplay(_ sender: NSMenuItem) {let enabled = !VPhoneFrameRateDisplay.isEnableddiff --git a/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneVirtualMachineAppDelegate.swift b/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneVirtualMachineAppDelegate.swiftindex 4717fd2b..29a10585 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneVirtualMachineAppDelegate.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneVirtualMachineAppDelegate.swift@@ -95,6 +95,7 @@ class VPhoneVirtualMachineAppDelegate: NSObject, NSApplicationDelegate {let control = VPhoneGuestControl()self.control = controlif !command.dfu {+ control.unlocksAtStartup = vm.unlocksAtStartupstartNetworkServices(vm: vm, control: control)let vphonedURL = URL(fileURLWithPath: command.vphonedBin)if FileManager.default.fileExists(atPath: vphonedURL.path) {@@ -169,6 +170,11 @@ class VPhoneVirtualMachineAppDelegate: NSObject, NSApplicationDelegate {mc.onFrameRateDisplayChange = { [weak wc] enabled inwc?.setFrameRateDisplay(enabled)}+ mc.onUnlockAtStartupChange = { [config = command.config] enabled in+ let manifest = try VPhoneVirtualMachineManifest.load(from: config)+ try manifest.updating(unlocksAtStartup: enabled).write(to: config)+ try VPhoneHostFilePermissions.makeAccessible(at: config)+ }mc.captureView = wc.captureViewmc.touchIDMonitor = wc.touchIDMonitormc.onFilesPressed = { [weak fileWC, weak control] indiff --git a/VPhoneExecutable/VPhoneVirtualization/UI/VirtualMachine/VPhoneVirtualMachine.swift b/VPhoneExecutable/VPhoneVirtualization/UI/VirtualMachine/VPhoneVirtualMachine.swiftindex b711f672..d3881051 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/VirtualMachine/VPhoneVirtualMachine.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/VirtualMachine/VPhoneVirtualMachine.swift@@ -9,6 +9,8 @@ class VPhoneVirtualMachine: NSObject, VZVirtualMachineDelegate {let virtualMachine: VZVirtualMachine/// The configuration actually used by this VM, rather than a pending preference.let usesHardwareKeyboard: Bool+ /// The manifest's unlock-at-startup setting as the VM started with it.+ let unlocksAtStartup: Bool/// ECID hex string resolved from machineIdentifier (e.g. "0x0012345678ABCDEF").let ecidHex: String?/// Read handle for VM serial output.@@ -245,6 +247,7 @@ class VPhoneVirtualMachine: NSObject, VZVirtualMachineDelegate {config.entropyDevices = [obj]print("[vphone] Entropy device configured")+ unlocksAtStartup = manifest.unlocksScreenAtStartupusesHardwareKeyboard = manifest.usesHardwareKeyboardconfig.keyboards = usesHardwareKeyboard ? [VZUSBKeyboardConfiguration()] : []print("[vphone] Hardware keyboard: \(usesHardwareKeyboard ? "enabled" : "disabled")")diff --git a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleOperations.swift b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleOperations.swiftindex d2c40d34..71d8bd34 100644--- a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleOperations.swift+++ b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleOperations.swift@@ -108,6 +108,7 @@ public enum VPhoneBundleOperations {networkMode: VPhoneVirtualMachineManifest.NetworkConfig.NetworkMode? = nil,bridgeInterface: String? = nil,networkEdit: VPhoneNetworkEdit = VPhoneNetworkEdit(),+ unlocksAtStartup: Bool? = nil,) throws -> VPhoneBundle {let bundle = try library.bundle(named: name)var edit = networkEdit@@ -120,6 +121,7 @@ public enum VPhoneBundleOperations {cpuCount: cpuCount,memorySize: memoryMB.map { $0 * 1024 * 1024 },networkConfig: network,+ unlocksAtStartup: unlocksAtStartup,)try updated.write(to: bundle.configURL)try VPhoneHostFilePermissions.makeAccessible(at: bundle.configURL)diff --git a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleReport.swift b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleReport.swiftindex da606e94..5675a89f 100644--- a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleReport.swift+++ b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleReport.swift@@ -10,6 +10,10 @@ public struct VPhoneBundleReport: Codable, Equatable, Sendable {/// `false` when the last `cfw install` did not finish; `nil` when unknown.public let customFirmwareInstalled: Bool?public let udid: String?+ /// Whether vphone-vm unlocks the guest each time it starts. Always+ /// present, so a client can tell a bundle that knows the setting from one+ /// that does not.+ public let unlocksAtStartup: Boolpublic init(bundle: VPhoneBundle) {name = bundle.name@@ -20,5 +24,6 @@ public struct VPhoneBundleReport: Codable, Equatable, Sendable {restoreInfo = VPhoneRestoreInfo.load(fromBundle: bundle)customFirmwareInstalled = VPhoneRestoreInfo.customFirmwareInstalled(inBundle: bundle)udid = VPhoneRestoreOperations.resolveUDID(bundle: bundle)+ unlocksAtStartup = bundle.manifest.unlocksScreenAtStartup}}diff --git a/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneVirtualMachineManifest.swift b/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneVirtualMachineManifest.swiftindex d8157062..d25976d7 100644--- a/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneVirtualMachineManifest.swift+++ b/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneVirtualMachineManifest.swift@@ -99,6 +99,17 @@ public struct VPhoneVirtualMachineManifest: Codable, Sendable {hardwareKeyboardEnabled ?? true}+ // MARK: - Startup++ /// Whether vphone-vm wakes the guest and dismisses its Lock Screen each+ /// time it connects to a freshly started vphoned. Missing in older+ /// manifests, which leave the guest at the Lock Screen.+ public let unlocksAtStartup: Bool?++ public var unlocksScreenAtStartup: Bool {+ unlocksAtStartup ?? false+ }+// MARK: - Display/// Screen configuration@@ -339,6 +350,7 @@ public struct VPhoneVirtualMachineManifest: Codable, Sendable {sepStorage: String = "SEPStorage",guestProductType: String? = nil,hardwareKeyboardEnabled: Bool? = nil,+ unlocksAtStartup: Bool? = nil,) {schemaVersion = Self.currentSchemaVersionself.platformType = platformType@@ -354,6 +366,7 @@ public struct VPhoneVirtualMachineManifest: Codable, Sendable {self.sepStorage = sepStorageself.guestProductType = guestProductTypeself.hardwareKeyboardEnabled = hardwareKeyboardEnabled+ self.unlocksAtStartup = unlocksAtStartup}// MARK: - Creation@@ -521,6 +534,7 @@ public struct VPhoneVirtualMachineManifest: Codable, Sendable {machineIdentifier: Data? = nil,networkConfig: NetworkConfig? = nil,hardwareKeyboardEnabled: Bool? = nil,+ unlocksAtStartup: Bool? = nil,) -> VPhoneVirtualMachineManifest {VPhoneVirtualMachineManifest(platformType: platformType,@@ -536,6 +550,7 @@ public struct VPhoneVirtualMachineManifest: Codable, Sendable {sepStorage: sepStorage,guestProductType: guestProductType,hardwareKeyboardEnabled: hardwareKeyboardEnabled ?? self.hardwareKeyboardEnabled,+ unlocksAtStartup: unlocksAtStartup ?? self.unlocksAtStartup,)}@@ -557,6 +572,7 @@ public struct VPhoneVirtualMachineManifest: Codable, Sendable {sepStorage: sepStorage,guestProductType: device == .default ? nil : device.productType,hardwareKeyboardEnabled: hardwareKeyboardEnabled,+ unlocksAtStartup: unlocksAtStartup,)}}diff --git a/VPhoneKit/VPhoneCoreKitTests/Bundle/BundleOperationsTests.swift b/VPhoneKit/VPhoneCoreKitTests/Bundle/BundleOperationsTests.swiftindex 6533b701..9d09dfd3 100644--- a/VPhoneKit/VPhoneCoreKitTests/Bundle/BundleOperationsTests.swift+++ b/VPhoneKit/VPhoneCoreKitTests/Bundle/BundleOperationsTests.swift@@ -139,6 +139,32 @@ struct BundleOperationsTests {#expect(updated.manifest.networkConfig.mode == .nat)}+ @Test func `update config persists unlock at startup`() throws {+ let root = try makeRoot()+ defer { try? FileManager.default.removeItem(at: root) }+ let rom = try fakeROM(); let seprom = try fakeROM()+ defer { try? FileManager.default.removeItem(at: rom); try? FileManager.default.removeItem(at: seprom) }+ let lib = VPhoneLibrary(root: root)+ _ = try VPhoneBundleOperations.create(+ .init(name: "unlock", cpuCount: 8, memoryMB: 8192, diskSizeGB: 1, romSource: rom, sepromSource: seprom),+ in: lib,+ )+ #expect(VPhoneBundleReport(bundle: try lib.bundle(named: "unlock")).unlocksAtStartup == false)++ _ = try VPhoneBundleOperations.updateConfig(+ bundleNamed: "unlock", in: lib, cpuCount: nil, memoryMB: nil, unlocksAtStartup: true,+ )+ #expect(VPhoneBundleReport(bundle: try lib.bundle(named: "unlock")).unlocksAtStartup)++ // Another edit leaves it alone; off turns it off.+ _ = try VPhoneBundleOperations.updateConfig(bundleNamed: "unlock", in: lib, cpuCount: 4, memoryMB: nil)+ #expect(try lib.bundle(named: "unlock").manifest.unlocksScreenAtStartup)+ _ = try VPhoneBundleOperations.updateConfig(+ bundleNamed: "unlock", in: lib, cpuCount: nil, memoryMB: nil, unlocksAtStartup: false,+ )+ #expect(try !lib.bundle(named: "unlock").manifest.unlocksScreenAtStartup)+ }+@Test func `update config persists network`() throws {let root = try makeRoot()defer { try? FileManager.default.removeItem(at: root) }diff --git a/VPhoneKit/VPhoneCoreKitTests/VirtualMachine/ManifestTests.swift b/VPhoneKit/VPhoneCoreKitTests/VirtualMachine/ManifestTests.swiftindex 31bf56d0..16d46ec7 100644--- a/VPhoneKit/VPhoneCoreKitTests/VirtualMachine/ManifestTests.swift+++ b/VPhoneKit/VPhoneCoreKitTests/VirtualMachine/ManifestTests.swift@@ -60,6 +60,26 @@ struct ManifestTests {#expect(edited.updating(hardwareKeyboardEnabled: !enabled).usesHardwareKeyboard == !enabled)}+ @Test func `old manifests do not unlock at startup`() throws {+ let data = try PropertyListEncoder().encode(sampleManifest())+ let plist = try #require(PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any])+ #expect(plist["unlocksAtStartup"] == nil)+ let loaded = try PropertyListDecoder().decode(VPhoneVirtualMachineManifest.self, from: data)+ #expect(!loaded.unlocksScreenAtStartup)+ }++ @Test(arguments: [true, false])+ func `unlock setting survives plist and unrelated edits`(enabled: Bool) throws {+ let original = sampleManifest().updating(unlocksAtStartup: enabled)+ let data = try PropertyListEncoder().encode(original)+ let loaded = try PropertyListDecoder().decode(VPhoneVirtualMachineManifest.self, from: data)+ #expect(loaded.unlocksAtStartup == enabled)+ let edited = loaded.updating(cpuCount: 4, hardwareKeyboardEnabled: !enabled)+ #expect(edited.unlocksScreenAtStartup == enabled)+ #expect(edited.updating(guestDevice: .default).unlocksScreenAtStartup == enabled)+ #expect(edited.updating(unlocksAtStartup: !enabled).unlocksScreenAtStartup == !enabled)+ }+@Test func `network config round trips through plist`() throws {let dir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)diff --git a/VPhoneLaunchpad/Configuration/Version.xcconfig b/VPhoneLaunchpad/Configuration/Version.xcconfigindex 2066de5a..f3b02434 100644--- a/VPhoneLaunchpad/Configuration/Version.xcconfig+++ b/VPhoneLaunchpad/Configuration/Version.xcconfig@@ -1,4 +1,4 @@-MARKETING_VERSION = 2.5.0+MARKETING_VERSION = 2.6.0// Bump whenever the helper changes. The app blesses the helper again when the// installed helper's version or bytes differ from the copy it embeds.CURRENT_PROJECT_VERSION = 12diff --git a/VPhoneLaunchpad/Tests/BundleNamesTests.swift b/VPhoneLaunchpad/Tests/BundleNamesTests.swiftindex 14bd8e7b..38960f1b 100644--- a/VPhoneLaunchpad/Tests/BundleNamesTests.swift+++ b/VPhoneLaunchpad/Tests/BundleNamesTests.swift@@ -17,14 +17,14 @@ struct BundleNamesTests {// `-local` (legacy), `-local.<8+ lowercase hex>` or `-ci.<7+ hex>`.// Anything else is kept whole, so it never parses as a version.let expectations: [Expectation] = [- Expectation(name: "2.5.2", bundleVersion: "2.5.2", isLocalBuild: false, isCompatible: true, isValid: true),- Expectation(name: "2.5.2-local", bundleVersion: "2.5.2", isLocalBuild: true, isCompatible: true, isValid: true),- Expectation(name: "2.5.2-local.ab12cd34", bundleVersion: "2.5.2", isLocalBuild: true, isCompatible: true, isValid: true),+ Expectation(name: "2.6.2", bundleVersion: "2.6.2", isLocalBuild: false, isCompatible: true, isValid: true),+ Expectation(name: "2.6.2-local", bundleVersion: "2.6.2", isLocalBuild: true, isCompatible: true, isValid: true),+ Expectation(name: "2.6.2-local.ab12cd34", bundleVersion: "2.6.2", isLocalBuild: true, isCompatible: true, isValid: true),// The build identifier is lowercase hex; uppercase is no build.- Expectation(name: "2.5.2-local.AB12CD34", bundleVersion: "2.5.2-local.AB12CD34", isLocalBuild: false, isCompatible: false, isValid: true),- Expectation(name: "2.5.2-local.ab12", bundleVersion: "2.5.2-local.ab12", isLocalBuild: false, isCompatible: false, isValid: true),- Expectation(name: "2.5.2-ci.abcdef1", bundleVersion: "2.5.2", isLocalBuild: false, isCompatible: true, isValid: true),- Expectation(name: "2.4.9-local.ab12cd34", bundleVersion: "2.4.9", isLocalBuild: true, isCompatible: false, isValid: true),+ Expectation(name: "2.6.2-local.AB12CD34", bundleVersion: "2.6.2-local.AB12CD34", isLocalBuild: false, isCompatible: false, isValid: true),+ Expectation(name: "2.6.2-local.ab12", bundleVersion: "2.6.2-local.ab12", isLocalBuild: false, isCompatible: false, isValid: true),+ Expectation(name: "2.6.2-ci.abcdef1", bundleVersion: "2.6.2", isLocalBuild: false, isCompatible: true, isValid: true),+ Expectation(name: "2.5.9-local.ab12cd34", bundleVersion: "2.5.9", isLocalBuild: true, isCompatible: false, isValid: true),Expectation(name: "../x", bundleVersion: "../x", isLocalBuild: false, isCompatible: false, isValid: false),Expectation(name: "", bundleVersion: "", isLocalBuild: false, isCompatible: false, isValid: false),]diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swiftindex 37c4b08e..186ae6f7 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swift@@ -302,6 +302,7 @@ struct VPhoneLaunchpadControlCommands {if let udid = machine.udid {report["udid"] = udid}+ report["unlocksAtStartup"] = machine.unlocksAtStartup ?? falseif let info = machine.restoreInfo {report["ios"] = "\(info.ios.version) (\(info.ios.build))"report["cloudOS"] = "\(info.cloudOS.version) (\(info.cloudOS.build))"diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstringsindex 87528d71..d3fbdc5b 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings@@ -13024,6 +13024,42 @@"zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "在客户机内解析这台 Mac 的名称" } }}},+ "Startup" : {+ "localizations" : {+ "en" : { "stringUnit" : { "state" : "translated", "value" : "Startup" } },+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "起動" } },+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "시작" } },+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Khởi động" } },+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "启动" } }+ }+ },+ "Unlock at startup" : {+ "localizations" : {+ "en" : { "stringUnit" : { "state" : "translated", "value" : "Unlock at startup" } },+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "起動時にロックを解除" } },+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "시작 시 잠금 해제" } },+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Mở khóa khi khởi động" } },+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "启动时解锁" } }+ }+ },+ "Unlock at Startup" : {+ "localizations" : {+ "en" : { "stringUnit" : { "state" : "translated", "value" : "Unlock at Startup" } },+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "起動時にロックを解除" } },+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "시작 시 잠금 해제" } },+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Mở khóa khi khởi động" } },+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "启动时解锁" } }+ }+ },+ "Each time the guest starts, its screen is turned on and the Lock Screen dismissed. A guest with a passcode stays locked." : {+ "localizations" : {+ "en" : { "stringUnit" : { "state" : "translated", "value" : "Each time the guest starts, its screen is turned on and the Lock Screen dismissed. A guest with a passcode stays locked." } },+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "ゲストが起動するたびに画面をオンにし、ロック画面を閉じます。パスコードを設定したゲストはロックされたままです。" } },+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "게스트가 시작될 때마다 화면을 켜고 잠금 화면을 닫습니다. 암호가 설정된 게스트는 잠긴 상태로 유지됩니다." } },+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Mỗi khi máy khách khởi động, màn hình được bật và Màn hình khóa được đóng. Máy khách có mật mã vẫn bị khóa." } },+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "客户机每次启动时点亮屏幕并关闭锁定屏幕。设有密码的客户机仍保持锁定。" } }+ }+ },"%@ (Default)" : {"localizations" : {"en" : { "stringUnit" : { "state" : "translated", "value" : "%@ (Default)" } },diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swiftindex e3e1d194..3dc8e0ee 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift@@ -93,11 +93,14 @@ nonisolated struct VPhoneLaunchpadMachine: Decodable, Hashable, Identifiable, Se/// `false` when the last CFW install did not finish, `nil` when unknown.let customFirmwareInstalled: Bool?let udid: String?+ /// Whether vphone-vm unlocks the guest each time it starts. Nil from a+ /// bundle older than the setting.+ let unlocksAtStartup: Bool?/// The library `vm list` was run on. Not part of the JSON.var libraryRoot = ""private enum CodingKeys: String, CodingKey {- case name, cpuCount, memoryMB, diskSizeBytes, network, restoreInfo, customFirmwareInstalled, udid+ case name, cpuCount, memoryMB, diskSizeBytes, network, restoreInfo, customFirmwareInstalled, udid, unlocksAtStartup}/// The inspector's firmware line. A restore whose CFW install neverdiff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swiftindex fe215722..a385b257 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift@@ -134,6 +134,9 @@ struct VPhoneLaunchpadMachineInspector: View {ForEach(machine.network.portForwards ?? [], id: \.self) { forward inLabeledContent("Port Forward", value: "\(forward.transport.uppercased()) \(forward.hostAddress ?? "127.0.0.1"):\(forward.hostPort) → \(forward.guestPort)")}+ if machine.unlocksAtStartup == true {+ LabeledContent("Unlock at Startup", value: String(localized: "On"))+ }}Section("Identity") {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swiftindex f639f2d4..6bd2efc5 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift@@ -543,6 +543,7 @@ final class VPhoneLaunchpadMachineLibrary {network: String?,bridgeInterface: String?,networkArguments: [String] = [],+ unlocksAtStartup: Bool? = nil,) async {var arguments = ["vm", "config", machine.name] + machine.libraryArgumentsif let cpu {@@ -558,6 +559,9 @@ final class VPhoneLaunchpadMachineLibrary {arguments += ["--bridge-interface", bridgeInterface]}arguments += networkArguments+ if let unlocksAtStartup {+ arguments += ["--unlock-at-startup", unlocksAtStartup ? "on" : "off"]+ }await perform(String(localized: "Saving settings…"), on: machine, arguments)}diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swiftindex 36af2f6e..6085e2b9 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swift@@ -3,14 +3,14 @@ import SwiftUI// MARK: - Settings-/// Hardware and network for one machine, or for several at once. The fields-/// start from the first machine; only the ones edited are written, to every-/// machine, so values the machines do not share are left alone. A fixed+/// Hardware, network and startup for one machine, or for several at once. The+/// fields start from the first machine; only the ones edited are written, to+/// every machine, so values the machines do not share are left alone. A fixed/// address, a MAC and forwarded ports belong to one machine, so they are only/// offered when one is selected.struct VPhoneLaunchpadMachineSettingsView: View {private enum Field {- case cpu, memory, network, address, mac, forwards, mdns, macName+ case cpu, memory, network, address, mac, forwards, mdns, macName, unlock}let machines: [VPhoneLaunchpadMachine]@@ -28,6 +28,7 @@ struct VPhoneLaunchpadMachineSettingsView: View {@State private var forwards: [String]@State private var advertisesName: Bool@State private var resolvesMacName: Bool+ @State private var unlocksAtStartup: Bool@State private var newTransport = "tcp"@State private var newHostPort = ""@State private var newGuestPort = ""@@ -50,6 +51,7 @@ struct VPhoneLaunchpadMachineSettingsView: View {_forwards = State(initialValue: first?.network.portForwards?.map(\.argument) ?? [])_advertisesName = State(initialValue: first?.network.localHostName != nil)_resolvesMacName = State(initialValue: first?.network.resolvesMacName != false)+ _unlocksAtStartup = State(initialValue: first?.unlocksAtStartup == true)}private var title: Text {@@ -141,6 +143,14 @@ struct VPhoneLaunchpadMachineSettingsView: View {if single, forwardsSupported {forwardsSection}+ Section {+ Toggle("Unlock at startup", isOn: $unlocksAtStartup)+ } header: {+ Text("Startup")+ } footer: {+ Text("Each time the guest starts, its screen is turned on and the Lock Screen dismissed. A guest with a passcode stays locked.")+ .foregroundStyle(.secondary)+ }}.formStyle(.grouped)} actions: {@@ -164,6 +174,7 @@ struct VPhoneLaunchpadMachineSettingsView: View {.onChange(of: forwards) { edited.insert(.forwards) }.onChange(of: advertisesName) { edited.insert(.mdns) }.onChange(of: resolvesMacName) { edited.insert(.macName) }+ .onChange(of: unlocksAtStartup) { edited.insert(.unlock) }}private var addressSection: some View {@@ -271,6 +282,7 @@ struct VPhoneLaunchpadMachineSettingsView: View {let memoryMB = edited.contains(.memory) ? memoryMB : nillet network = edited.contains(.network) ? network : nillet bridgeInterface = network == "bridged" ? bridgeInterface : nil+ let unlocksAtStartup = edited.contains(.unlock) ? unlocksAtStartup : nilvar networkArguments: [String] = []if single {if edited.contains(.address) {@@ -313,6 +325,7 @@ struct VPhoneLaunchpadMachineSettingsView: View {network: network,bridgeInterface: bridgeInterface,networkArguments: networkArguments,+ unlocksAtStartup: unlocksAtStartup,)}}diff --git a/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadBundleStore.swift b/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadBundleStore.swiftindex 33901784..4a81eb3d 100644--- a/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadBundleStore.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadBundleStore.swift@@ -76,8 +76,9 @@ nonisolated enum VPhoneLaunchpadNames {/// the helper passes. 2.4.0 added the network options of `vm config`/// (`--ip`, `--mac`, `--forward`, `--mdns`, `--mac-name`), which a/// machine's Settings pass. 2.5.0 added `vm leases`, which Host Setup- /// lists and the helper runs to release orphaned DHCP leases.- private static let minimumBundleComponents = (2, 5, 0)+ /// lists and the helper runs to release orphaned DHCP leases. 2.6.0 added+ /// `vm config --unlock-at-startup`, which a machine's Settings pass.+ private static let minimumBundleComponents = (2, 6, 0)static let minimumBundleVersion ="\(minimumBundleComponents.0).\(minimumBundleComponents.1).\(minimumBundleComponents.2)"