👾 Open Computer Use – Open-Source Alternative to Codex Computer Use
Swift accessibilityai-agentai-agentsclaude-codecodexcodex-computer-usecomputer-usecomputer-use-agentcross-platformcuadesktop-automationgemini-cligui-automationmacosmcpmodel-context-protocolopen-computer-useopen-computer-use-mcpopenai-codexopencode
Refresh permission onboarding after grants
Leo7a74afe8e596
diff --git a/apps/OpenComputerUse/Sources/OpenComputerUse/PermissionOnboardingApp.swift b/apps/OpenComputerUse/Sources/OpenComputerUse/PermissionOnboardingApp.swiftindex f699592..3afe26c 100644--- a/apps/OpenComputerUse/Sources/OpenComputerUse/PermissionOnboardingApp.swift+++ b/apps/OpenComputerUse/Sources/OpenComputerUse/PermissionOnboardingApp.swift@@ -114,6 +114,11 @@ extension PermissionWindowController: PermissionContentControllerDelegate {accessoryPanelController.hide()}+ func permissionContentControllerDidRequestRelaunch(_ controller: PermissionContentController) {+ accessoryPanelController.hide()+ relaunchCurrentAppBundle()+ }+func permissionContentControllerDidCompleteAllPermissions(_ controller: PermissionContentController) {accessoryPanelController.hide()close()@@ -129,6 +134,18 @@ extension PermissionWindowController: PermissionContentControllerDelegate {window?.makeKeyAndOrderFront(nil)NSApp.activate(ignoringOtherApps: true)}++ private func relaunchCurrentAppBundle() {+ guard let appURL = PermissionSupport.currentAppBundleURL() else {+ return+ }++ let configuration = NSWorkspace.OpenConfiguration()+ configuration.activates = true+ configuration.createsNewApplicationInstance = true+ NSWorkspace.shared.openApplication(at: appURL, configuration: configuration) { _, _ in }+ NSApp.terminate(nil)+ }}@MainActor@@ -139,6 +156,7 @@ protocol PermissionContentControllerDelegate: AnyObject {sourceFrameInScreen: CGRect?)func permissionContentControllerDidResolveGuidance(_ controller: PermissionContentController)+ func permissionContentControllerDidRequestRelaunch(_ controller: PermissionContentController)func permissionContentControllerDidCompleteAllPermissions(_ controller: PermissionContentController)}@@ -166,16 +184,18 @@ final class PermissionContentController: NSViewController {private let backgroundView = GradientBackgroundView()private let stackView = NSStackView()private let iconView = AppGlyphView()- private let titleLabel = NSTextField(labelWithString: "Enable Open Computer Use")- private let subtitleLabel = NSTextField(wrappingLabelWithString: "Open Computer Use needs these permissions to use apps on your Mac.\nThese permissions are only used when you ask it to perform tasks.")+ private let titleLabel = NSTextField(labelWithString: "Enable \(PermissionSupport.currentBundleDisplayName())")+ private let subtitleLabel = NSTextField(wrappingLabelWithString: "\(PermissionSupport.currentBundleDisplayName()) needs these permissions to use apps on your Mac.\nThese permissions are only used when you ask it to perform tasks.")private let cardsContainer = NSStackView()private let completionLabel = NSTextField(labelWithString: "All required permissions are enabled.")private let refreshTimerInterval: TimeInterval = 0.25+ private let relaunchPromptDelay: TimeInterval = 1.5private var activeGuidance: SystemPermissionKind?private var refreshTimer: Timer?private var diagnostics = PermissionDiagnostics.current()private var hasReportedCompletion = false+ private var requestedPermissions: [SystemPermissionKind: Date] = [:]override func loadView() {view = NSView()@@ -212,6 +232,10 @@ final class PermissionContentController: NSViewController {self.activeGuidance = nil}+ for permission in SystemPermissionKind.allCases where updated.isGranted(permission) {+ requestedPermissions[permission] = nil+ }+refreshUI()if previousGuidance != nil, activeGuidance == nil {@@ -289,18 +313,26 @@ final class PermissionContentController: NSViewController {let orderedPermissions = SystemPermissionKind.allCasesfor permission in orderedPermissions {- if activeGuidance == permission, !diagnostics.isGranted(permission) {+ let restartRequired = restartRequired(for: permission)+ if activeGuidance == permission, !diagnostics.isGranted(permission), !restartRequired {let placeholder = GuidancePlaceholderView()cardsContainer.addArrangedSubview(placeholder)placeholder.widthAnchor.constraint(equalToConstant: PermissionOnboardingLayout.cardWidth).isActive = truecontinue}- let card = PermissionCardView(permission: permission, diagnostics: diagnostics)+ let card = PermissionCardView(permission: permission, diagnostics: diagnostics, restartRequired: restartRequired)card.onAllow = { [weak self] requestedPermission, sourceFrameInScreen inguard let self else {return}++ if self.restartRequired(for: requestedPermission) {+ self.delegate?.permissionContentControllerDidRequestRelaunch(self)+ return+ }++ self.requestedPermissions[requestedPermission] = Date()self.delegate?.permissionContentController(self,didRequestPermission: requestedPermission,@@ -313,6 +345,14 @@ final class PermissionContentController: NSViewController {completionLabel.isHidden = !diagnostics.allGranted}++ private func restartRequired(for permission: SystemPermissionKind) -> Bool {+ guard !diagnostics.isGranted(permission), let requestedAt = requestedPermissions[permission] else {+ return false+ }++ return Date().timeIntervalSince(requestedAt) >= relaunchPromptDelay+ }}@MainActor@@ -321,11 +361,13 @@ final class PermissionCardView: NSView {private let permission: SystemPermissionKindprivate let diagnostics: PermissionDiagnostics+ private let restartRequired: Boolprivate weak var actionButton: PrimaryActionButton?- init(permission: SystemPermissionKind, diagnostics: PermissionDiagnostics) {+ init(permission: SystemPermissionKind, diagnostics: PermissionDiagnostics, restartRequired: Bool = false) {self.permission = permissionself.diagnostics = diagnostics+ self.restartRequired = restartRequiredsuper.init(frame: .zero)translatesAutoresizingMaskIntoConstraints = falseconfigure()@@ -379,7 +421,7 @@ final class PermissionCardView: NSView {title.font = NSFont.systemFont(ofSize: 20, weight: .bold)title.textColor = NSColor(calibratedWhite: 0.18, alpha: 1)- let subtitle = NSTextField(labelWithString: permission.subtitle)+ let subtitle = NSTextField(labelWithString: restartRequired ? "Restart to finish enabling this permission" : permission.subtitle)subtitle.font = NSFont.systemFont(ofSize: 14, weight: .regular)subtitle.textColor = NSColor(calibratedWhite: 0.42, alpha: 1)@@ -397,7 +439,7 @@ final class PermissionCardView: NSView {let done = StatusChipView(text: "Done", foreground: NSColor(calibratedRed: 0.16, green: 0.50, blue: 0.23, alpha: 1), background: NSColor(calibratedRed: 0.93, green: 0.98, blue: 0.94, alpha: 1))content.addArrangedSubview(done)} else {- let button = PrimaryActionButton(title: "Allow", target: self, action: #selector(handleAllow))+ let button = PrimaryActionButton(title: restartRequired ? "Restart" : "Allow", target: self, action: #selector(handleAllow))actionButton = buttoncontent.addArrangedSubview(button)button.widthAnchor.constraint(equalToConstant: PermissionOnboardingLayout.actionButtonWidth).isActive = truediff --git a/docs/histories/2026-05/20260507-2040-refresh-permission-onboarding.md b/docs/histories/2026-05/20260507-2040-refresh-permission-onboarding.mdnew file mode 100644index 0000000..3e5eb59--- /dev/null+++ b/docs/histories/2026-05/20260507-2040-refresh-permission-onboarding.md@@ -0,0 +1,28 @@+# Dev 权限引导刷新++## 用户诉求++Dev 版在系统设置里已经授权后,权限引导窗口仍停留在 `Allow`,看起来像授权没有生效。++## 主要改动++- 权限引导标题和说明改为使用当前 bundle 名称,Dev 版显示 `Open Computer Use (Dev)`。+- 用户点击 `Allow` 后,如果当前进程仍未看到权限刷新,短暂等待后将对应卡片切换为 `Restart`。+- 点击 `Restart` 会重新拉起当前 app bundle,让 macOS 对新进程刷新 Accessibility / Screen Recording 权限状态。++## 设计动机++macOS 对已经运行的 app agent 不一定会即时刷新新授予的 TCC 权限。系统设置里已经授权时,继续显示 `Allow` 会误导用户反复操作。显式切换到 `Restart` 更符合实际状态,也避免需要手动找进程并重启。++## 验证++- `swift test`+- `./scripts/build-open-computer-use-app.sh debug`+- `./scripts/run-tool-smoke-tests.sh`+- `./scripts/check-docs.sh`+- `git diff --check`++## 受影响文件++- `apps/OpenComputerUse/Sources/OpenComputerUse/PermissionOnboardingApp.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swift`diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swiftindex e20a61c..d3d5db5 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swift@@ -17,11 +17,12 @@ public enum SystemPermissionKind: String, CaseIterable, Sendable {}public var subtitle: String {+ let appName = PermissionSupport.currentBundleDisplayName()switch self {case .accessibility:- return "Allows Open Computer Use to access app interfaces"+ return "Allows \(appName) to access app interfaces"case .screenRecording:- return "Open Computer Use uses screenshots to know where to click"+ return "\(appName) uses screenshots to know where to click"}}