Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Post Darwin notifications from the Controls panel (#517)

Lakre3c0d3f1c9aa
diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.md
index df892b79..ba199283 100644
--- a/Research/vphoned_http_api.md
+++ b/Research/vphoned_http_api.md
@@ -228,7 +228,7 @@ correlate them by `id`. The socket also sends
receive pong frames. JSON WebSocket frames are limited to 1 MiB after
fragment reassembly.
-SwiftNIO handles parsing, upgrade, masking, and backpressure. IcliKit 0.6.8
+SwiftNIO handles parsing, upgrade, masking, and backpressure. IcliKit 0.7.0
owns general device operations. Each HTTP or WebSocket request runs independently
on a concurrent worker queue, so a stalled system service does not block HID,
file browsing, or unrelated requests. The host serializes the input events it
@@ -273,6 +273,7 @@ request carries `"force": true`.
| Processes | `processes.list {filter?}`, `processes.kill {pid, signal?}` **force**, `memory.jetsam`, `memory.pressure` (only the three kernel memory sysctls, for polling) |
| launchd | `services.list`, `status`, `print`, `dump`, `disabled`, `start`, `enable`, `load`; `services.stop`, `disable`, `remove`, `signal`, `unload` **force**; `launchd.getenv`, `setenv`, `unsetenv` |
| Logs | `logs.syslog {seconds, process?, level?, max_lines?}` (a bounded capture of at most 60 s), `logs.crashes {bundle_id?}`, `logs.crash {path}` |
+| Darwin notifications | `notify.post {name, state?}` (`postDarwinNotification`; `state` is a UInt64, as a number or a decimal string, stored before the post), `notify.state {name}` (`darwinNotificationState`) |
| Network, security | `network.capture {seconds, interface?, filter?}` (writes a pcap in the guest scratch directory and returns its path), `security.ssl_killswitch` |
| Apps | `apps.list`, `search`, `refresh`, `launch`, `terminate`, `foreground`, `open_url`, `install`, `info`, `binary`, `data_dir`, `url_schemes`, `handlers`, `registration`, `register`, `network_policy {repair?}`; `apps.uninstall`, `unregister`, `unregister_dir` **force** |
| System | `system.uicache`, `system.system_apps {visible?}`, `system.respring` **force**, `system.reboot {userspace?}` **force**, `developer_mode.status`, `developer_mode.enable`, `power.low_power_mode`, `diagnostics.self_test` |
diff --git a/VPhone.xcworkspace/xcshareddata/swiftpm/Package.resolved b/VPhone.xcworkspace/xcshareddata/swiftpm/Package.resolved
index 50f3904e..c6afde35 100644
--- a/VPhone.xcworkspace/xcshareddata/swiftpm/Package.resolved
+++ b/VPhone.xcworkspace/xcshareddata/swiftpm/Package.resolved
@@ -24,8 +24,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/owngoal-dev/icli.git",
"state" : {
- "revision" : "74843a56df54936c3949239a4ffb3ddcbe37dee4",
- "version" : "0.6.9"
+ "revision" : "9916a4f8b90c7b9c8585df3d98956ccc80e35365",
+ "version" : "0.7.0"
}
},
{
diff --git a/VPhoneDaemon/Daemon/GuestAPI+Device.swift b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
index cee6af72..f5a4fb34 100644
--- a/VPhoneDaemon/Daemon/GuestAPI+Device.swift
+++ b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
@@ -61,6 +61,11 @@ extension GuestAPI {
return sslKillswitchStatus()
case "diagnostics.self_test":
return try runSelfTests()
+ case "notify.post":
+ let state = try params["state"].map(notificationState)
+ return try postDarwinNotification(string(params, "name"), state: state)
+ case "notify.state":
+ return try darwinNotificationState(string(params, "name"))
default:
return nil
}
@@ -69,4 +74,16 @@ extension GuestAPI {
private static func brightnessState() -> [String: Any] {
["value": brightness(), "auto": autoBrightness().map { $0 as Any } ?? NSNull()]
}
+
+ /// A notify(3) state is a full UInt64, beyond what a JSON double holds
+ /// exactly, so a decimal string is accepted as well as a number. A JSON
+ /// boolean also decodes as NSNumber and is refused.
+ private static func notificationState(_ value: Any) throws -> UInt64 {
+ let number = (value as? NSNumber).flatMap { CFGetTypeID($0) == CFBooleanGetTypeID() ? nil : $0 }
+ let text = (value as? String) ?? number?.stringValue
+ guard let text, let state = UInt64(text) else {
+ throw GuestAPIError.invalidRequest("state must be an unsigned 64-bit integer")
+ }
+ return state
+ }
}
diff --git a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj
index 414abd95..26f0e8f2 100644
--- a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj
+++ b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj
@@ -345,7 +345,7 @@
repositoryURL = "https://github.com/owngoal-dev/icli.git";
requirement = {
kind = exactVersion;
- version = 0.6.9;
+ version = 0.7.0;
};
};
C10000000000000000000072 /* XCRemoteSwiftPackageReference "swift-nio" */ = {
diff --git a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
index 18e9f688..eb7c4de6 100644
--- a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
+++ b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
@@ -6,8 +6,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/owngoal-dev/icli.git",
"state" : {
- "revision" : "74843a56df54936c3949239a4ffb3ddcbe37dee4",
- "version" : "0.6.9"
+ "revision" : "9916a4f8b90c7b9c8585df3d98956ccc80e35365",
+ "version" : "0.7.0"
}
},
{
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings b/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings
index 0c1fd440..b4b9044b 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings
@@ -1633,6 +1633,34 @@
}
}
},
+ "A UInt64 the guest stores before posting, read by observers through notify_get_state. Leave empty to post without a state." : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "投稿の前にゲストが保存する UInt64 値です。オブザーバは notify_get_state で読み取ります。空欄のままにすると状態なしで投稿します。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "게시하기 전에 게스트가 저장하는 UInt64 값입니다. 관찰자는 notify_get_state로 읽습니다. 비워 두면 상태 없이 게시합니다."
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Giá trị UInt64 mà máy khách lưu trước khi gửi; bên quan sát đọc giá trị này qua notify_get_state. Để trống để gửi không kèm trạng thái."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "客户机在发送前存储的 UInt64 值,观察者通过 notify_get_state 读取。留空则不带状态发送。"
+ }
+ }
+ }
+ },
"Access Group" : {
"localizations" : {
"en" : {
@@ -4469,6 +4497,34 @@
}
}
},
+ "Choose a notification name the system posts or observes" : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "システムが投稿または監視する通知名を選択"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "시스템이 게시하거나 관찰하는 알림 이름 선택"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Chọn tên thông báo mà hệ thống gửi hoặc theo dõi"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "选择系统发送或监听的通知名称"
+ }
+ }
+ }
+ },
"Choose accessibility elements or text recognized in the screenshot" : {
"localizations" : {
"ja" : {
@@ -7199,6 +7255,34 @@
}
}
},
+ "Darwin Notification" : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Darwin 通知"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Darwin 알림"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Thông báo Darwin"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Darwin 通知"
+ }
+ }
+ }
+ },
"Data" : {
"localizations" : {
"en" : {
@@ -16615,6 +16699,152 @@
}
}
},
+ "Post" : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "投稿"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "게시"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Gửi"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "发送"
+ }
+ }
+ }
+ },
+ "Post the notification in the guest" : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ゲストで通知を投稿"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "게스트에서 알림 게시"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Gửi thông báo trong máy khách"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在客户机中发送该通知"
+ }
+ }
+ }
+ },
+ "Posted %@ with state %@." : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "new",
+ "value" : "Posted %1$@ with state %2$@."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ を状態 %2$@ で投稿しました。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@을(를) 상태 %2$@(으)로 게시했습니다."
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Đã gửi %1$@ với trạng thái %2$@."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已发送 %1$@,状态为 %2$@。"
+ }
+ }
+ }
+ },
+ "Posted %@." : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ を投稿しました。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@을(를) 게시했습니다."
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Đã gửi %@."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已发送 %@。"
+ }
+ }
+ }
+ },
+ "Posting %@…" : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ を投稿中…"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ 게시 중…"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Đang gửi %@…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在发送 %@…"
+ }
+ }
+ }
+ },
"Power" : {
"localizations" : {
"en" : {
@@ -16887,6 +17117,34 @@
}
}
},
+ "Presets" : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "プリセット"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "프리셋"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mẫu có sẵn"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "预设"
+ }
+ }
+ }
+ },
"Press the Home button" : {
"localizations" : {
"ja" : {
@@ -17513,6 +17771,34 @@
}
}
},
+ "Read State" : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "状態を読み取る"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "상태 읽기"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Đọc trạng thái"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "读取状态"
+ }
+ }
+ }
+ },
"Read one preference key, or leave the key empty to read all keys in the domain." : {
"localizations" : {
"en" : {
@@ -17671,6 +17957,62 @@
}
}
},
+ "Read the notification's current state from the guest" : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ゲストから通知の現在の状態を読み取る"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "게스트에서 알림의 현재 상태 읽기"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Đọc trạng thái hiện tại của thông báo từ máy khách"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "从客户机读取该通知的当前状态"
+ }
+ }
+ }
+ },
+ "Reading %@…" : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ を読み取り中…"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ 읽는 중…"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Đang đọc %@…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在读取 %@…"
+ }
+ }
+ }
+ },
"Reading accessibility elements…" : {
"localizations" : {
"ja" : {
@@ -24345,6 +24687,68 @@
}
}
},
+ "The state must be a whole number from 0 to %@." : {
+ "localizations" : {
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "状態には 0 から %@ までの整数を入力してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "상태는 0부터 %@ 사이의 정수여야 합니다."
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Trạng thái phải là số nguyên từ 0 đến %@."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "状态必须是 0 到 %@ 之间的整数。"
+ }
+ }
+ }
+ },
+ "The state of %@ is %@." : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "new",
+ "value" : "The state of %1$@ is %2$@."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ の状態は %2$@ です。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@의 상태는 %2$@입니다."
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Trạng thái của %1$@ là %2$@."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ 的状态为 %2$@。"
+ }
+ }
+ }
+ },
"This app declares no URL schemes." : {
"localizations" : {
"ja" : {
@@ -26231,6 +26635,40 @@
}
}
},
+ "Unable to post %@. %@" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "new",
+ "value" : "Unable to post %1$@. %2$@"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ を投稿できません。%2$@"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@을(를) 게시할 수 없습니다. %2$@"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Không thể gửi %1$@. %2$@"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "无法发送 %1$@。%2$@"
+ }
+ }
+ }
+ },
"Unable to press %@. %@" : {
"localizations" : {
"en" : {
@@ -26333,6 +26771,40 @@
}
}
},
+ "Unable to read %@. %@" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "new",
+ "value" : "Unable to read %1$@. %2$@"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@ を読み取れません。%2$@"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%1$@을(를) 읽을 수 없습니다. %2$@"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Không thể đọc %1$@. %2$@"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "无法读取 %1$@。%2$@"
+ }
+ }
+ }
+ },
"Unable to read Developer Mode status. Check that the guest agent is connected, then try again." : {
"localizations" : {
"en" : {
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsModel.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsModel.swift
index cd820f02..13fda8f9 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsModel.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsModel.swift
@@ -1,6 +1,7 @@
import Foundation
-/// Display, audio, power, hardware button and keyboard controls for the guest.
+/// Display, audio, power, hardware button, keyboard and Darwin notification
+/// controls for the guest.
/// Every write reads the guest's value back; a failed write restores the
/// control from the guest.
@MainActor
@@ -13,6 +14,8 @@ final class VPhoneControlsModel {
case sendingKey(String)
case typing(Int)
case pasting
+ case posting(String)
+ case readingNotification(String)
var title: String {
switch self {
@@ -28,6 +31,10 @@ final class VPhoneControlsModel {
String(localized: "Typing \(count) characters…", bundle: VPhoneLocalization.bundle)
case .pasting:
String(localized: "Pasting text…", bundle: VPhoneLocalization.bundle)
+ case let .posting(name):
+ String(localized: "Posting \(name)…", bundle: VPhoneLocalization.bundle)
+ case let .readingNotification(name):
+ String(localized: "Reading \(name)…", bundle: VPhoneLocalization.bundle)
}
}
}
@@ -63,6 +70,12 @@ final class VPhoneControlsModel {
var keyboardText = ""
var modifiers: Set<VPhoneControlsModifier> = []
+ // MARK: - Notification State
+
+ var notificationName = ""
+ /// Empty posts without a state; otherwise a UInt64 in decimal.
+ var notificationState = ""
+
var isBusy: Bool {
activity != nil
}
@@ -75,6 +88,14 @@ final class VPhoneControlsModel {
canWrite && !keyboardText.isEmpty && keyboardText.utf8.count <= 64 * 1024
}
+ var canUseNotification: Bool {
+ canWrite && !trimmedNotificationName.isEmpty
+ }
+
+ private var trimmedNotificationName: String {
+ notificationName.trimmingCharacters(in: .whitespacesAndNewlines)
+ }
+
init(control: VPhoneGuestControl) {
self.control = control
isConnected = control.isConnected
@@ -346,6 +367,53 @@ final class VPhoneControlsModel {
}
}
+ // MARK: - Darwin Notification
+
+ /// Posts the notification; with a state, the guest stores it first so
+ /// observers read it through notify_get_state.
+ func postNotification() async {
+ guard canUseNotification else { return }
+ let name = trimmedNotificationName
+ let stateText = notificationState.trimmingCharacters(in: .whitespaces)
+ guard stateText.isEmpty || UInt64(stateText) != nil else {
+ fail(String(localized: "The state must be a whole number from 0 to \(String(UInt64.max)).", bundle: VPhoneLocalization.bundle))
+ return
+ }
+ var params: [String: Any] = ["name": name]
+ if !stateText.isEmpty {
+ // A decimal string keeps all 64 bits, which a JSON double does not.
+ params["state"] = stateText
+ }
+ activity = .posting(name)
+ do {
+ _ = try await control.call("notify.post", params: params)
+ activity = nil
+ succeed(stateText.isEmpty
+ ? String(localized: "Posted \(name).", bundle: VPhoneLocalization.bundle)
+ : String(localized: "Posted \(name) with state \(stateText).", bundle: VPhoneLocalization.bundle))
+ } catch {
+ activity = nil
+ fail(String(localized: "Unable to post \(name). \(Self.guestMessage(error))", bundle: VPhoneLocalization.bundle))
+ }
+ }
+
+ /// Reads the notification's current state into the state field.
+ func readNotificationState() async {
+ guard canUseNotification else { return }
+ let name = trimmedNotificationName
+ activity = .readingNotification(name)
+ do {
+ let result = try await control.call("notify.state", params: ["name": name])
+ let state = (result["state"] as? NSNumber)?.stringValue ?? "0"
+ notificationState = state
+ activity = nil
+ succeed(String(localized: "The state of \(name) is \(state).", bundle: VPhoneLocalization.bundle))
+ } catch {
+ activity = nil
+ fail(String(localized: "Unable to read \(name). \(Self.guestMessage(error))", bundle: VPhoneLocalization.bundle))
+ }
+ }
+
// MARK: - Write
/// Sends one setting, applies the guest's answer, and on failure restores
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsNotification.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsNotification.swift
new file mode 100644
index 00000000..ec1573ab
--- /dev/null
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsNotification.swift
@@ -0,0 +1,38 @@
+import Foundation
+
+/// Darwin notification names the Controls window offers as presets, grouped
+/// by the part of the system that posts or observes them. Any other name can
+/// be typed in.
+enum VPhoneControlsNotification {
+ static let presets: [[String]] = [
+ [
+ "com.apple.springboard.lockcomplete",
+ "com.apple.springboard.lockstate",
+ "com.apple.springboard.hasBlankedScreen",
+ "com.apple.iokit.hid.displayStatus",
+ ],
+ [
+ "com.apple.system.lowpowermode",
+ "com.apple.system.thermalpressurelevel",
+ "com.apple.system.lowdiskspace",
+ "com.apple.system.timezone",
+ "com.apple.system.clock_set",
+ "com.apple.system.config.network_change",
+ "com.apple.system.hostname",
+ "com.apple.language.changed",
+ ],
+ [
+ "com.apple.mobile.application_installed",
+ "com.apple.mobile.application_uninstalled",
+ "com.apple.mobile.keybagd.lock_status",
+ "com.apple.mobile.keybagd.first_unlock",
+ ],
+ [
+ "com.apple.mobile.lockdown.device_name_changed",
+ "com.apple.mobile.lockdown.activation_state",
+ "com.apple.mobile.lockdown.host_attached",
+ "com.apple.mobile.lockdown.host_detached",
+ "com.apple.mobile.developer_image_mounted",
+ ],
+ ]
+}
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsView.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsView.swift
index be126f54..79064965 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsView.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Panels/Controls/VPhoneControlsView.swift
@@ -11,6 +11,7 @@ struct VPhoneControlsView: View {
powerSection
buttonsSection
keyboardSection
+ notificationSection
}
.formStyle(.grouped)
.disabled(!model.isConnected)
@@ -225,6 +226,41 @@ struct VPhoneControlsView: View {
.disabled(!model.canWrite)
}
+ // MARK: - Darwin Notification
+
+ private var notificationSection: some View {
+ Section("Darwin Notification") {
+ HStack(spacing: 8) {
+ TextField("Name", text: $model.notificationName, prompt: Text(verbatim: "com.apple.springboard.lockcomplete"))
+ .font(.system(size: 11, design: .monospaced))
+ Menu("Presets") {
+ ForEach(VPhoneControlsNotification.presets, id: \.self) { group in
+ Section {
+ ForEach(group, id: \.self) { name in
+ Button(name) { model.notificationName = name }
+ }
+ }
+ }
+ }
+ .fixedSize()
+ .help("Choose a notification name the system posts or observes")
+ }
+
+ TextField("State", text: $model.notificationState, prompt: Text("None"))
+ .font(.system(size: 11, design: .monospaced))
+ .help("A UInt64 the guest stores before posting, read by observers through notify_get_state. Leave empty to post without a state.")
+
+ HStack(spacing: 8) {
+ Spacer(minLength: 8)
+ Button("Read State") { Task { await model.readNotificationState() } }
+ .help("Read the notification's current state from the guest")
+ Button("Post") { Task { await model.postNotification() } }
+ .help("Post the notification in the guest")
+ }
+ .disabled(!model.canUseNotification)
+ }
+ }
+
// MARK: - Bindings
private var orientationBinding: Binding<VPhoneControlsOrientation?> {