Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apple/TablePro/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
PluginNotificationService.shared.setUp()
OperationCompletionReporter.shared.setUp()
AgentAttentionNotifier.shared.setUp()
ApprovalRequestNotifier.shared.setUp()
ChatToolBootstrap.register()

// Not post-launch work: a crashed run's tunnel still holds its port when a restored connection reconnects.
Expand Down Expand Up @@ -163,6 +164,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
ProviderMoves.shared.start()
SyncApprovalsModel.shared.start()
SyncPassFollower.shared.start(host: .shared)
ApprovalRequestNotifier.shared.start()
// Its gate reads the sign-in the core restores after launch.
Task {
await AccountServices.shared.waitUntilRestored()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal protocol UserNotificationPresenting: AnyObject {
func setCategories(_ categories: Set<UNNotificationCategory>)
func post(_ request: UNNotificationRequest) async throws
func removeDelivered(identifiers: [String])
func deliveredIdentifiers() async -> [String]
}

@MainActor
Expand Down Expand Up @@ -51,4 +52,8 @@ internal final class SystemNotificationPresenter: UserNotificationPresenting {
internal func removeDelivered(identifiers: [String]) {
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiers)
}

internal func deliveredIdentifiers() async -> [String] {
await UNUserNotificationCenter.current().deliveredNotifications().map(\.request.identifier)
}
}
6 changes: 6 additions & 0 deletions apple/TablePro/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -111675,6 +111675,9 @@
}
}
}
},
"It asked for your keys at %@. Approve it only if you're signing in to it right now." : {

},
"It can finish on %@, unless one of your devices or your old recovery key cancels it first. Come back to this Mac then to finish it." : {

Expand Down Expand Up @@ -247604,6 +247607,9 @@
}
}
}
},
"When long-running work finishes out of sight, an agent needs your answer or its reply fails, an extension can't load or update, or another device asks for your account's keys." : {

},
"When long-running work finishes out of sight, an agent needs your answer or its reply fails, or an extension can't load or update." : {
"localizations" : {
Expand Down
7 changes: 4 additions & 3 deletions apple/TablePro/Views/Settings/NotificationsSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ struct NotificationsSettingsView: View {
Section {
Toggle(isOn: $settings.isEnabled) {
Text("Show notifications")
Text(
"When long-running work finishes out of sight, an agent needs your answer or its reply fails, or an extension can't load or update."
)
Text("""
When long-running work finishes out of sight, an agent needs your answer or its reply fails, an \
extension can't load or update, or another device asks for your account's keys.
""")
}
.accessibilityIdentifier("notifications-enabled-toggle")

Expand Down
31 changes: 31 additions & 0 deletions apple/TablePro/Views/Settings/SettingsWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ internal final class SettingsWindowController: NSWindowController, NSWindowDeleg
private static var shared: SettingsWindowController?

internal let split: SettingsSplitViewController
// The request a notice asked to review while a sheet was up.
private var reviewAfterSheet: String?

internal static func present(_ request: SettingsRequest) {
switch request {
Expand Down Expand Up @@ -39,6 +41,29 @@ internal final class SettingsWindowController: NSWindowController, NSWindowDeleg
controller.showAndActivate()
}

// A request's notice opens End-to-End Encryption, and that request's approval once the page lists it. A sheet
// already up keeps the window where it is, so the page and the approval follow once it closes.
internal static func reviewApprovalRequest(_ request: String) {
let location = SettingsLocation(page: .accountEncryption)
let controller = sharedController(opening: location)
let navigated = controller.prepareToShow(location)
controller.showAndActivate()
guard navigated else {
controller.reviewAfterSheet = request
return
}
controller.reviewAfterSheet = nil
controller.split.models.accountKeys.review(request: request)
}

// The page is where the person looks: in the key window of the app in front.
internal static func isShowing(_ page: SettingsPage) -> Bool {
guard NSApp.isActive, let shared, let window = shared.window, window.isKeyWindow, window.isVisible else {
return false
}
return shared.split.model.location.routes.last == .page(page)
}

private static func sharedController(opening location: SettingsLocation?) -> SettingsWindowController {
if let shared { return shared }
let controller = SettingsWindowController(
Expand Down Expand Up @@ -160,6 +185,12 @@ internal final class SettingsWindowController: NSWindowController, NSWindowDeleg
}
}

internal func windowDidEndSheet(_ notification: Notification) {
guard let request = reviewAfterSheet, window?.attachedSheet == nil else { return }
reviewAfterSheet = nil
Self.reviewApprovalRequest(request)
}

internal func windowDidBecomeKey(_ notification: Notification) {
split.detail.windowDidBecomeKey()
}
Expand Down
19 changes: 19 additions & 0 deletions apple/TablePro/Views/Sync/Keys/AccountKeysModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ internal final class AccountKeysModel: ObservableObject {
@Published var sheet: Sheet?
@Published var pendingRemoval: PendingRemoval?
@Published var actionFailure: AccountActionFailure?
// The request a notice's Approve… named, whose approval opens once a read lists it.
private(set) var pendingReview: String?
// Each device row this model removed, once the server took it.
let rowRemoved = PassthroughSubject<String, Never>()
// The removal whose confirmation timed out, which the failure's Try Again starts again.
Expand Down Expand Up @@ -195,6 +197,20 @@ internal final class AccountKeysModel: ObservableObject {
sheet = .approval(AccountApprovalFlow(role: .approver(request), flows: environment.flows, clock: environment.clock))
}

// From a notice. A request that ended meanwhile opens nothing, and the page lists what is still open. One asked
// for while another sheet is up waits for it to close, since closing it reads again.
func review(request: String) {
pendingReview = request
Task { await reload() }
}

private func openPendingReview() {
guard let pending = pendingReview, sheet == nil else { return }
pendingReview = nil
guard let request = requests.first(where: { $0.request == pending }) else { return }
approve(request)
}

func useRecoveryKey() {
sheet = .recover(AccountRecoverFlow(flows: environment.flows))
}
Expand Down Expand Up @@ -415,6 +431,7 @@ internal final class AccountKeysModel: ObservableObject {
pendingRemoval = nil
actionFailure = nil
removalToRetry = nil
pendingReview = nil
state = AccountRemote()
devices = AccountRemote()
requests = []
Expand Down Expand Up @@ -443,6 +460,8 @@ internal final class AccountKeysModel: ObservableObject {
requests = []
}
await readNotices()
guard started == generation else { return }
openPendingReview()
}

private func readDevices() async {
Expand Down
Loading
Loading