Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Rebuild app registrations from the Apps menu

Lakr794f3a335052
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings b/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings
index 9b394a92..08ce844f 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/Localizable.xcstrings
@@ -28892,6 +28892,176 @@
}
}
},
+ "Rebuild App Registrations" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Rebuild App Registrations"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "アプリ登録を再構築"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "앱 등록 재구성"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tạo lại đăng ký ứng dụng"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "重建应用注册"
+ }
+ }
+ }
+ },
+ "Unable to Rebuild App Registrations" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Unable to Rebuild App Registrations"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "アプリ登録を再構築できません"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "앱 등록을 재구성할 수 없음"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Không thể tạo lại đăng ký ứng dụng"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "无法重建应用注册"
+ }
+ }
+ }
+ },
+ "Registered %1$@, removed %2$@, %3$@ unchanged." : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Registered %1$@, removed %2$@, %3$@ unchanged."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "登録 %1$@ 件、削除 %2$@ 件、変更なし %3$@ 件。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "등록 %1$@개, 제거 %2$@개, 변경 없음 %3$@개."
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Đã đăng ký %1$@, đã xóa %2$@, %3$@ không đổi."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已注册 %1$@ 个,已移除 %2$@ 个,%3$@ 个未变化。"
+ }
+ }
+ }
+ },
+ "Unable to rebuild app registrations.\n\n%@" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Unable to rebuild app registrations.\n\n%@"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "アプリ登録を再構築できません。\n\n%@"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "앱 등록을 재구성할 수 없습니다.\n\n%@"
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Không thể tạo lại đăng ký ứng dụng.\n\n%@"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "无法重建应用注册。\n\n%@"
+ }
+ }
+ }
+ },
+ "Unable to rebuild app registrations. Check that the guest agent is connected, then try again." : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Unable to rebuild app registrations. Check that the guest agent is connected, then try again."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "アプリ登録を再構築できません。ゲストエージェントの接続を確認して再試行してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "앱 등록을 재구성할 수 없습니다. 게스트 에이전트 연결을 확인한 후 다시 시도하세요."
+ }
+ },
+ "vi" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Không thể tạo lại đăng ký ứng dụng. Hãy kiểm tra kết nối tác nhân máy khách rồi thử lại."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "无法重建应用注册。请检查客户机代理连接后重试。"
+ }
+ }
+ }
+ },
"Uninstall Bootstrap… (No Restart)" : {
"localizations" : {
"en" : {
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift
index 7b758d11..25d31329 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift
@@ -533,6 +533,15 @@ final class VPhoneGuestControl {
return try await call("bootstrap.uninstall", params: ["roots": roots, "reboot": reboot, "force": true])
}
+ /// `uicache -a` for the bootstrap: vphoned registers every app under the
+ /// bootstrap's /Applications again through LaunchServices.
+ func rebuildBootstrapAppRegistrations() async throws -> [String: Any] {
+ guard guestCapabilities.contains("bootstrap_uninstall") else {
+ throw ControlError.unsupportedCapability("bootstrap_uninstall")
+ }
+ return try await call("system.uicache")
+ }
+
/// Asks the guest to restart. The guest usually restarts before it can
/// reply, so a dropped connection is the expected result.
func restartGuest() async throws {
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuBootstrap.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuBootstrap.swift
index 337524be..3f91c270 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuBootstrap.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuBootstrap.swift
@@ -45,6 +45,15 @@ extension VPhoneMenuController {
uninstallNoRestart.isEnabled = false
uninstallBootstrapNoRestartItem = uninstallNoRestart
menu.addItem(uninstallNoRestart)
+
+ let rebuild = makeItem(
+ "Rebuild App Registrations",
+ action: #selector(rebuildAppRegistrations),
+ symbol: "arrow.clockwise.circle",
+ )
+ rebuild.isEnabled = false
+ rebuildAppRegistrationsItem = rebuild
+ menu.addItem(rebuild)
}
func updateBootstrapAvailability(available: Bool) {
@@ -57,6 +66,7 @@ extension VPhoneMenuController {
let enabled = available && !isInstallingBootstrap && !isUninstallingBootstrap
uninstallBootstrapItem?.isEnabled = enabled
uninstallBootstrapNoRestartItem?.isEnabled = enabled
+ rebuildAppRegistrationsItem?.isEnabled = enabled && !isRebuildingAppRegistrations
}
@objc func installBootstrap() {
@@ -141,6 +151,7 @@ extension VPhoneMenuController {
installBootstrapFromFileItem?.isEnabled = false
uninstallBootstrapItem?.isEnabled = false
uninstallBootstrapNoRestartItem?.isEnabled = false
+ rebuildAppRegistrationsItem?.isEnabled = false
let alert = NSAlert()
alert.messageText = VPhoneLocalization.text("Install Bootstrap")
alert.informativeText = if let localURL {
@@ -329,6 +340,58 @@ extension VPhoneMenuController {
)
}
+ // MARK: - App Registrations
+
+ /// `uicache -a`: registers apps added to or updated in the bootstrap's
+ /// /Applications and removes records of apps deleted from it.
+ @objc func rebuildAppRegistrations() {
+ guard !isInstallingBootstrap, !isUninstallingBootstrap, !isRebuildingAppRegistrations else { return }
+ isRebuildingAppRegistrations = true
+ rebuildAppRegistrationsItem?.isEnabled = false
+ Task {
+ defer {
+ isRebuildingAppRegistrations = false
+ updateBootstrapUninstallAvailability(
+ available: control.isConnected && control.guestCapabilities.contains("bootstrap_uninstall"),
+ )
+ }
+ guard await control.completedBootstrap() != nil else {
+ VPhoneAlert.present(
+ title: "Rebuild App Registrations",
+ message: "No bootstrap environment was found.",
+ style: .informational,
+ )
+ return
+ }
+ do {
+ let result = try await control.rebuildBootstrapAppRegistrations()
+ let count = { (key: String) in String((result[key] as? [Any])?.count ?? 0) }
+ VPhoneAlert.present(
+ title: "Rebuild App Registrations",
+ message: VPhoneLocalization.format(
+ "Registered %1$@, removed %2$@, %3$@ unchanged.",
+ count("registered"),
+ count("unregistered"),
+ count("unchanged"),
+ ),
+ style: .informational,
+ )
+ } catch let VPhoneGuestControl.ControlError.guestError(message) where !message.isEmpty {
+ VPhoneAlert.present(
+ title: "Unable to Rebuild App Registrations",
+ message: VPhoneLocalization.format("Unable to rebuild app registrations.\n\n%@", message),
+ style: .warning,
+ )
+ } catch {
+ VPhoneAlert.present(
+ title: "Unable to Rebuild App Registrations",
+ message: "Unable to rebuild app registrations. Check that the guest agent is connected, then try again.",
+ style: .warning,
+ )
+ }
+ }
+ }
+
private func updateBootstrapProgress(
_ status: [String: Any], label: NSTextField, indicator: NSProgressIndicator,
) {
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuController.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuController.swift
index e96df424..935b1e46 100644
--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuController.swift
+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/Menu/VPhoneMenuController.swift
@@ -20,6 +20,7 @@ class VPhoneMenuController {
}
}
}
+
var hardwareKeyboardItem: NSMenuItem?
var onHardwareKeyboardChange: ((Bool) async throws -> Void)?
@@ -36,8 +37,10 @@ class VPhoneMenuController {
var installBootstrapFromFileItem: NSMenuItem?
var uninstallBootstrapItem: NSMenuItem?
var uninstallBootstrapNoRestartItem: NSMenuItem?
+ var rebuildAppRegistrationsItem: NSMenuItem?
var isInstallingBootstrap = false
var isUninstallingBootstrap = false
+ var isRebuildingAppRegistrations = false
var installPackageItem: NSMenuItem?
var clipboardGetItem: NSMenuItem?
var clipboardSetItem: NSMenuItem?