Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,42 @@ extension MobileShellComposite {
await hideStoredPairedMacs(targets, scope: scope)
}

/// Disconnects the live session and hides every stored computer pairing.
///
/// Each tagged app instance is hidden separately so all retained pairing
/// rows remain available for later unhide or re-pairing.
public func forgetAllComputers() async {
let activeMacDeviceID = connectedMacDeviceID ?? activeTicket?.macDeviceID
disconnectLiveConnection()
storedMacReconnectGeneration &+= 1
isReconnectingStoredMac = false
didFinishStoredMacReconnectAttempt = false

if storedPairedMacsIncludingHidden.isEmpty {
await loadPairedMacs()
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
let knownPairings = storedPairedMacsIncludingHidden.sorted {
if $0.macDeviceID != $1.macDeviceID {
return $0.macDeviceID < $1.macDeviceID
}
return ($0.instanceTag ?? "") < ($1.instanceTag ?? "")
}
if !knownPairings.isEmpty || activeMacDeviceID != nil {
hasKnownPairedMac = true
}
for pairing in knownPairings {
await hideMac(
macDeviceID: pairing.macDeviceID,
instanceTag: pairing.instanceTag
)
}

if let activeMacDeviceID,
!knownPairings.contains(where: { $0.macDeviceID == activeMacDeviceID }) {
await hideMac(macDeviceID: activeMacDeviceID)
}
}

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
/// Hides exactly one stored paired-Mac row.
public func hideStoredMac(macDeviceID: String) async {
guard let scope = await currentScopeSnapshot() else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3309,9 +3309,9 @@ public final class MobileShellComposite: MobileTerminalOutputSinking {
clearRemoteConnectionContext(preservingOtherMacWorkspaceState: preservingOtherMacWorkspaceState)
}

/// Disconnect from and hide the currently paired Mac so the next session
/// starts from a fresh QR scan without deleting local or server state.
/// Backs the "Rescan QR" action.
/// Disconnect from and hide the currently paired Mac on this device without
/// deleting local or server pairing state.
/// Backs the "Forget This Computer" action.
public func disconnectAndHideActiveMac() {
let staleMacID = connectedMacDeviceID ?? activeTicket?.macDeviceID
disconnectLiveConnection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,60 @@ import Testing
#expect(store.hasKnownPairedMac)
}

@Test func forgetAllComputersDisconnectsAndHidesVisibleHiddenAndTaggedPairings() async throws {
let pairedStore = DelayedTeamPairedMacStore(
recordsByTeam: [
"team-a": [
try Self.pairedMac(
id: "mac-a",
displayName: "Desk Mac",
host: "100.82.214.112",
lastSeenAt: Date(timeIntervalSince1970: 30),
isActive: true
),
try Self.pairedMac(
id: "mac-a",
displayName: "Desk Mac Nightly",
host: "100.82.214.112",
port: 50923,
lastSeenAt: Date(timeIntervalSince1970: 20),
isActive: false,
instanceTag: "nightly"
),
try Self.pairedMac(
id: "mac-b",
displayName: "Laptop Mac",
host: "100.82.214.113",
lastSeenAt: Date(timeIntervalSince1970: 10),
isActive: false
),
],
],
blockedTeams: []
)
let store = MobileShellComposite(
isSignedIn: true,
connectionState: .connected,
pairedMacStore: pairedStore,
identityProvider: StaticIdentityProvider(userID: "user-1"),
teamIDProvider: { "team-a" },
hiddenMacStore: InMemoryPairedMacHiddenStore()
)
await store.loadPairedMacs()
await store.hideMac(macDeviceID: "mac-b", instanceTag: nil)

await store.forgetAllComputers()

#expect(store.connectionState == .disconnected)
#expect(store.pairedMacs.isEmpty)
#expect(store.displayPairedMacs.isEmpty)
#expect(Set(store.hiddenComputers.map(\.id)) == [
MobilePairedMac.pairingID(macDeviceID: "mac-a", instanceTag: nil),
MobilePairedMac.pairingID(macDeviceID: "mac-a", instanceTag: "nightly"),
MobilePairedMac.pairingID(macDeviceID: "mac-b", instanceTag: nil),
])
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

@Test func signOutThenNeverPairedReconnectClearsSavedMacHint() async throws {
let defaultsSuiteName = "never-paired-hint-\(UUID().uuidString)"
let defaults = try #require(UserDefaults(suiteName: defaultsSuiteName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct DeviceTreeView: View {
/// Present the add-device (pairing) flow. `nil` hides the add affordance.
var showAddDevice: (() -> Void)?
@Environment(\.dismiss) private var dismiss
@State private var showingForgetAllConfirmation = false

/// The user's computers as immutable snapshots, sourced from the paired-Mac
/// backup (`pairedMacs`) — this feature's source of truth, the same set that
Expand Down Expand Up @@ -62,6 +63,9 @@ struct DeviceTreeView: View {
if store.hasHiddenComputers {
hiddenComputersSection
}
if !computers.isEmpty || store.hasHiddenComputers {
forgetAllComputersSection
}
}
.listStyle(.insetGrouped)
.navigationDestination(for: String.self) { pairingID in
Expand Down Expand Up @@ -93,6 +97,33 @@ struct DeviceTreeView: View {
}
}
.refreshable { await reload() }
.confirmationDialog(
L10n.string(
"mobile.computers.forgetAll.title",
defaultValue: "Forget All Computers?"
),
isPresented: $showingForgetAllConfirmation,
titleVisibility: .visible
) {
Button(
L10n.string(
"mobile.computers.forgetAll",
defaultValue: "Forget All Computers"
),
role: .destructive
) {
Task { await store.forgetAllComputers() }
}
Button(
L10n.string("mobile.common.cancel", defaultValue: "Cancel"),
role: .cancel
) {}
} message: {
Text(L10n.string(
"mobile.computers.forgetAll.message",
defaultValue: "This phone disconnects and hides every computer. Computers reappear when they are paired again or unhidden."
))
}
.task {
// This screen is the user's connection-debug view. The online dots
// (presence) and secondary workspace counts already update live via
Expand Down Expand Up @@ -145,6 +176,26 @@ struct DeviceTreeView: View {
)
}

/// A quiet, footer-style destructive action: centered red text with no
/// icon and no card background, so the rare whole-phone action does not
/// compete with the computer rows above it.
private var forgetAllComputersSection: some View {
Section {
Button(role: .destructive) {
showingForgetAllConfirmation = true
} label: {
Text(L10n.string(
"mobile.computers.forgetAll",
defaultValue: "Forget All Computers"
))
.font(.subheadline)
.frame(maxWidth: .infinity)
}
.accessibilityIdentifier("MobileComputersForgetAll")
.listRowBackground(Color.clear)
}
}

@ViewBuilder
private var emptySection: some View {
Section {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,10 @@ struct DisconnectedWorkspaceShellView: View {
.accessibilityIdentifier("MobileDisconnectedWorkspaceShell")
.task {
// Load (and, via the backup decorator, restore) saved Macs so a
// known/restored Mac shows up here for one-tap reconnect. Only
// auto-present the pairing sheet when there is nothing to pick,
// so a returning user is not buried under the add-device flow.
// known/restored Mac shows up here for one-tap reconnect.
// Same-account discovery is the primary path; manual pairing
// remains available from the explicit Add Computer controls.
await store?.loadPairedMacs()
if shouldAutoPresentAddDeviceAfterLoadingSavedMacs {
showAddDevice()
return
}
#if os(iOS)
// Registry + presence enrich the rows (online dots, build
// labels). The loop then keeps presence and last-seen fresh
Expand Down Expand Up @@ -102,12 +98,11 @@ struct DisconnectedWorkspaceShellView: View {
}) {
// Reuse the same Settings sheet the workspace list opens from its
// Settings button so the no-devices screen's chrome matches. There is no
// connected host or QR to rescan here, but the store is forwarded so
// connected computer to forget here, but the store is forwarded so
// a user whose active Mac went offline can still switch to another
// paired Mac; the sheet also surfaces the account + Sign Out.
MobileSettingsView(
connectedHostName: "",
rescanQR: nil,
startPairingScanner: {
settingsPairingScannerHandoff.requestScannerAfterDismiss(
isSettingsPresented: $showingSettings
Expand Down Expand Up @@ -138,12 +133,6 @@ struct DisconnectedWorkspaceShellView: View {
store.map { MacComputerSnapshot.snapshots(from: $0) } ?? []
}

var shouldAutoPresentAddDeviceAfterLoadingSavedMacs: Bool {
guard let store else { return false }
return store.pairedMacLoadState == .loaded
&& store.pairedMacs.isEmpty
}

@ViewBuilder
private var content: some View {
if !savedComputers.isEmpty {
Expand Down Expand Up @@ -212,13 +201,13 @@ struct DisconnectedWorkspaceShellView: View {
private var emptyState: some View {
ContentUnavailableView {
Label(
L10n.string("mobile.devices.emptyTitle", defaultValue: "No devices"),
L10n.string("mobile.devices.emptyTitle", defaultValue: "No Computers"),
systemImage: "desktopcomputer.and.iphone"
)
} description: {
Text(L10n.string(
"mobile.devices.emptyDescription",
defaultValue: "Add a computer to start syncing terminal workspaces."
defaultValue: "Sign in to cmux on your computer with this account and it appears here automatically."
))
} actions: {
Button(action: showAddDevice) {
Expand Down Expand Up @@ -299,14 +288,17 @@ struct DisconnectedWorkspaceShellView: View {
ContentUnavailableView {
Label(
savedMacs.isEmpty
? L10n.string("mobile.devices.emptyTitle", defaultValue: "No devices")
? L10n.string("mobile.devices.emptyTitle", defaultValue: "No Computers")
: L10n.string("mobile.devices.savedTitle", defaultValue: "Your Computers"),
systemImage: "desktopcomputer.and.iphone"
)
} description: {
Text(
savedMacs.isEmpty
? L10n.string("mobile.devices.emptyDescription", defaultValue: "Add a computer to start syncing terminal workspaces.")
? L10n.string(
"mobile.devices.emptyDescription",
defaultValue: "Sign in to cmux on your computer with this account and it appears here automatically."
)
: L10n.string("mobile.devices.savedDescription", defaultValue: "Tap a saved computer to reconnect, or add another.")
)
} actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct MobileSettingsView: View {
@Environment(ToastCenter.self) private var toasts
@Environment(\.irohSettingsController) private var irohSettingsController
let connectedHostName: String
let rescanQR: (() -> Void)?
let startPairingScanner: (() -> Void)?
let signOut: (() -> Void)?
/// The shell store, used to drive the multi-Mac switcher. `nil` in previews,
Expand Down Expand Up @@ -87,8 +86,8 @@ struct MobileSettingsView: View {
}

// Hidden entirely when there is nothing to show (no connected
// Mac, no store to switch with, no rescan), so the no-devices
// screen's reuse of this sheet does not render an empty header.
// Mac and no store to switch with), so the no-devices screen's
// reuse of this sheet does not render an empty header.
if hasConnectionSection {
Section(L10n.string("mobile.settings.connection", defaultValue: "Connection")) {
if !connectedHostName.isEmpty {
Expand All @@ -108,18 +107,6 @@ struct MobileSettingsView: View {
}
.accessibilityIdentifier("MobileSettingsSwitchMac")
}
if let rescanQR {
Button {
rescanQR()
dismiss()
} label: {
Label(
L10n.string("mobile.workspaces.rescan", defaultValue: "Rescan QR"),
systemImage: "qrcode.viewfinder"
)
}
.accessibilityIdentifier("MobileSettingsRescanQR")
}
}
Button {
showingSetupHelp = true
Expand Down Expand Up @@ -514,10 +501,10 @@ struct MobileSettingsView: View {
}

/// Whether the Connection section has any rows to show. When this sheet is
/// reused from the no-devices screen there is no connected Mac, no store to
/// switch with, and no rescan action, so the section is omitted entirely.
/// reused from the no-devices screen there is no connected Mac or store to
/// switch with, so the section is omitted entirely.
private var hasConnectionSection: Bool {
!connectedHostName.isEmpty || store != nil || rescanQR != nil
!connectedHostName.isEmpty || store != nil
}

/// Drives the team Picker. Reads the EFFECTIVE current team (`resolvedTeamID`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ struct WorkspaceListView: View {
/// in previews, where pull-to-refresh is hidden. `@Sendable` to match
/// SwiftUI's `refreshable(action:)` action type under Swift 6.
var refresh: (@Sendable () async -> Void)?
/// Optional: when present, the toolbar shows a "settings" menu offering
/// "Rescan QR" (disconnect + re-pair) and "Sign out". When nil (e.g.
/// previews), the menu is hidden.
var rescanQR: (() -> Void)?
var signOut: (() -> Void)?
/// Manual reconnect for the offline status row. `nil` in previews.
var reconnect: (() -> Void)?
Expand Down Expand Up @@ -376,7 +372,6 @@ struct WorkspaceListView: View {
}) {
MobileSettingsView(
connectedHostName: host,
rescanQR: rescanQR,
startPairingScanner: {
settingsPairingScannerHandoff.requestScannerAfterDismiss(
isSettingsPresented: $showingSettings
Expand Down Expand Up @@ -717,17 +712,6 @@ struct WorkspaceListView: View {
)
}
.accessibilityIdentifier("MobileWorkspaceTerminalShortcutsMenuItem")
if let rescanQR {
Button {
rescanQR()
} label: {
Label(
L10n.string("mobile.workspaces.rescan", defaultValue: "Rescan QR"),
systemImage: "qrcode.viewfinder"
)
}
.accessibilityIdentifier("MobileWorkspaceRescanQRMenuItem")
}
if let signOut {
Button(role: .destructive) {
signOut()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ struct WorkspaceShellView: View {
}) {
MobileSettingsView(
connectedHostName: store.connectedHostName,
rescanQR: { store.disconnectAndHideActiveMac() },
startPairingScanner: {
settingsPairingScannerHandoff.requestScannerAfterDismiss(
isSettingsPresented: $showingRootSettings
Expand Down Expand Up @@ -505,7 +504,6 @@ struct WorkspaceShellView: View {
},
cancelMacSwitch: cancelMacSwitchFromWorkspacePicker,
refresh: refreshWorkspacesClosure,
rescanQR: { store.disconnectAndHideActiveMac() },
signOut: signOut,
reconnect: reconnectClosure,
showAddDevice: showAddDevice,
Expand Down
Loading