Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Merge branch 'main' into feat/mobile-ios-android

tonyf95db4a22ec5
diff --cc mobile/lib/phone/device_detail_page.dart
index bd690d55b,7e45a77fc..6e965f557
--- a/mobile/lib/phone/device_detail_page.dart
+++ b/mobile/lib/phone/device_detail_page.dart
@@@ -94,106 -98,92 +99,114 @@@ class _DeviceDetailPageState extends St
backgroundColor: tty.ground,
body: SafeArea(
bottom: false,
- child: ListView(
- padding: EdgeInsets.fromLTRB(
- Tty.origin,
- 12,
- Tty.origin,
- MediaQuery.paddingOf(context).bottom + 24,
- ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- TtyText(_name, size: TtySize.title, weight: FontWeight.w600),
- const SizedBox(height: 12),
- SettingsGroup(
- children: [
- SettingsRow(
- title: 'Kind',
- value: isMachine ? 'Computer' : 'App',
+ // Always pushed — from Your devices, the new-device banner or its notification — so it
+ // carries the way back as Your devices does: above the title, outside the list.
+ if (canPop)
+ Align(
+ alignment: Alignment.centerLeft,
+ child: TtyBackButton(
+ onPressed: () => Navigator.of(context).maybePop(),
),
- SettingsRow(
- title: 'Added',
- value: fullDateTime(
- DateTime.fromMillisecondsSinceEpoch(member.addedAt),
- ),
+ ),
+ Expanded(
+ child: ListView(
+ padding: EdgeInsets.fromLTRB(
+ Tty.origin,
+ canPop ? 8 : 12,
+ Tty.origin,
+ MediaQuery.paddingOf(context).bottom + 24,
),
- if (lastSeen != null)
- SettingsRow(
- title: 'Last active',
- value: relativeAgo(
- DateTime.fromMillisecondsSinceEpoch(lastSeen),
- now,
- ),
+ children: [
+ TtyText(_name, size: TtySize.title, weight: FontWeight.w600),
+ const SizedBox(height: 12),
+ SettingsGroup(
+ children: [
+ SettingsRow(
+ title: 'Kind',
+ value: isMachine ? 'Computer' : 'App',
+ ),
+ SettingsRow(
+ title: 'Added',
+ value: fullDateTime(
+ DateTime.fromMillisecondsSinceEpoch(member.addedAt),
+ ),
+ ),
+ if (lastSeen != null)
+ SettingsRow(
+ title: 'Last active',
+ value: relativeAgo(
+ DateTime.fromMillisecondsSinceEpoch(lastSeen),
+ now,
+ ),
+ ),
+ if (isMachine && member.machineId.isNotEmpty)
+ SettingsRow(
+ title: 'Machine',
+ value: member.machineId.substring(
+ 0,
+ member.machineId.length < 8
+ ? member.machineId.length
+ : 8,
+ ),
+ ),
+ ],
),
- if (isMachine && member.machineId.isNotEmpty)
- SettingsRow(
- title: 'Machine',
- value: member.machineId.substring(
- 0,
- member.machineId.length < 8 ? member.machineId.length : 8,
+ if (fp.isNotEmpty) ...[
+ const SizedBox(height: 16),
+ FingerprintBlock(
+ fp,
+ large: true,
+ copyKey: const Key('device-detail-copy'),
),
- ),
- ],
- ),
- if (fp.isNotEmpty) ...[
- const SizedBox(height: 16),
- FingerprintBlock(
- fp,
- large: true,
- copyKey: const Key('device-detail-copy'),
- ),
- const SizedBox(height: 8),
- // Wraps: the explanation is a sentence, not a terminal line.
- Text(
- fingerprintHowToCompare(computer: isMachine),
- style: tty.style(color: tty.dim),
- ),
- ],
- if (_row.suspended) ...[
- const SizedBox(height: 12),
- Text(
- 'Not trusted here: added after this device’s list and another’s split. '
- 'Review the list to trust it again.',
- style: tty.style(color: tty.red),
- ),
- ],
- if (_error case final error?) ...[
- const SizedBox(height: 12),
- Text(error, style: tty.style(color: tty.red)),
- ],
- if (widget.isNew || !_row.self) ...[
- const SizedBox(height: 16),
- SettingsGroup(
- children: [
- if (widget.isNew)
- SettingsRow(
- key: const Key('device-detail-mine'),
- title: 'It’s mine',
- onTap: _removing ? null : _mine,
+ const SizedBox(height: 8),
+ // Wraps: the explanation is a sentence, not a terminal line.
+ Text(
+ fingerprintHowToCompare(computer: isMachine),
+ style: tty.style(color: tty.dim),
+ ),
+ ],
++ if (_row.suspended) ...[
++ const SizedBox(height: 12),
++ Text(
++ 'Not trusted here: added after this device’s list and another’s split. '
++ 'Review the list to trust it again.',
++ style: tty.style(color: tty.red),
+ ),
- if (!_row.self)
- SettingsRow(
- key: const Key('device-detail-remove'),
- title: _removing ? 'Removing…' : 'Remove this device',
- destructive: true,
- onTap: _removing ? null : () => unawaited(_remove()),
++ ],
+ if (_error case final error?) ...[
+ const SizedBox(height: 12),
- TtyText(error, color: tty.red),
++ Text(error, style: tty.style(color: tty.red)),
+ ],
+ if (widget.isNew || !_row.self) ...[
+ const SizedBox(height: 16),
+ SettingsGroup(
+ children: [
+ if (widget.isNew)
+ SettingsRow(
+ key: const Key('device-detail-mine'),
+ title: 'It’s mine',
+ onTap: _removing ? null : _mine,
+ ),
+ if (!_row.self)
+ SettingsRow(
+ key: const Key('device-detail-remove'),
+ title: _removing
+ ? 'Removing…'
+ : 'Remove this device',
+ destructive: true,
+ onTap: _removing
+ ? null
+ : () => unawaited(_remove()),
+ ),
+ ],
),
+ ],
],
),
- ],
+ ),
],
),
),
diff --cc mobile/lib/phone/devices_page.dart
index c207c9d0f,d90152750..e8c74efa1
--- a/mobile/lib/phone/devices_page.dart
+++ b/mobile/lib/phone/devices_page.dart
@@@ -174,129 -316,140 +317,157 @@@ class _DevicesPageState extends State<D
backgroundColor: tty.ground,
body: SafeArea(
bottom: false,
- child: ListView(
- padding: EdgeInsets.fromLTRB(
- Tty.origin,
- 12,
- Tty.origin,
- MediaQuery.paddingOf(context).bottom + 24,
- ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- const TtyText(
- 'Your devices',
- size: TtySize.title,
- weight: FontWeight.w600,
- ),
- const SizedBox(height: 8),
- Text(
- 'Every computer and app signed in to your account. Each reaches your machines '
- 'end to end encrypted. Remove one you do not recognise.',
- style: tty.style(color: tty.dim),
- ),
- if (frozen) ...[
- const SizedBox(height: 12),
- SettingsGroup(
- children: [
- SettingsRow(
- title: 'The device list froze',
- detail: listing.frozen != null
- ? 'Harness served a list that does not match what this phone verified. '
- 'No device is added until you review it.'
- : 'Frozen on ${listing.frozenPeers.join(', ')}. Review it on that computer.',
- destructive: true,
- detailLines: null,
- onTap: listing.frozen != null
- ? () => unawaited(_trustAgain())
- : null,
- value: listing.frozen != null ? 'Review' : null,
- ),
- ],
- ),
- ],
- if (listing != null &&
- !listing.baselineSeen &&
- !_baselineHidden) ...[
- if (_baseline(listing) case final baseline
- when baseline.isNotEmpty) ...[
- const SizedBox(height: 12),
- _BaselinePanel(
- key: const Key('account-devices-baseline'),
- rows: baseline,
- onGotIt: () => unawaited(_gotIt()),
+ // Always pushed — from Settings, the new-device banner or its notification — so it
+ // carries the way back as Settings does: above the title, and outside the list, so a
+ // long list scrolled down keeps it.
+ if (canPop)
+ Align(
+ alignment: Alignment.centerLeft,
+ child: TtyBackButton(
+ onPressed: () => Navigator.of(context).maybePop(),
),
- ],
- ],
- if (_error case final error?) ...[
- const SizedBox(height: 12),
- Text(
- error,
- key: const Key('account-devices-error'),
- // Amber when the person has something to act on (another account, a list that moved):
- // the same severity as the desktop. A failure is red.
- style: tty.style(color: _errorWarns ? tty.yellow : tty.red),
),
- ],
- if (listing != null && _unused(listing).isNotEmpty) ...[
- const SizedBox(height: 12),
- SettingsGroup(
+ Expanded(
+ child: ListView(
+ padding: EdgeInsets.fromLTRB(
+ Tty.origin,
+ canPop ? 8 : 12,
+ Tty.origin,
+ MediaQuery.paddingOf(context).bottom + 24,
+ ),
children: [
- SettingsRow(
- key: const Key('account-devices-unused'),
- title:
- '${_unused(listing).length} app${_unused(listing).length == 1 ? '' : 's'} not used in 90 days',
- detail: 'Most likely a browser whose data was cleared.',
- value: _removingUnused ? 'Removing…' : 'Remove',
- destructive: true,
- onTap: _removingUnused
- ? null
- : () => unawaited(_removeUnused(_unused(listing))),
+ const TtyText(
+ 'Your devices',
+ size: TtySize.title,
+ weight: FontWeight.w600,
),
- ],
- ),
- ],
- const SizedBox(height: 12),
- if (listing == null)
- const SizedBox.shrink()
- else ...[
- if (selfRow(listing.members) case final self?) ...[
- SettingsGroup(
- children: [
- _ThisDeviceCard(
- key: const Key('account-device-this'),
- row: self,
+ const SizedBox(height: 8),
- // Wraps: the explanation is a sentence, not a terminal line — a [TtyText] clipped
- // it at the screen's edge.
+ Text(
+ 'Every computer and app signed in to your account. Each reaches your machines '
+ 'end to end encrypted. Remove one you do not recognise.',
+ style: tty.style(color: tty.dim),
+ ),
+ if (frozen) ...[
+ const SizedBox(height: 12),
+ SettingsGroup(
+ children: [
+ SettingsRow(
+ title: 'The device list froze',
+ detail: listing.frozen != null
+ ? 'Harness served a list that does not match what this phone verified. '
+ 'No device is added until you review it.'
+ : 'Frozen on ${listing.frozenPeers.join(', ')}. Review it on that computer.',
+ destructive: true,
++ detailLines: null,
+ onTap: listing.frozen != null
+ ? () => unawaited(_trustAgain())
+ : null,
+ value: listing.frozen != null ? 'Review' : null,
+ ),
+ ],
),
],
- ),
- const SizedBox(height: 12),
- ],
- SettingsGroup(
- children: [
- for (final row in orderDeviceRows(
- listing.members,
- _seen,
- _newPubs,
- ))
- SettingsRow(
- key: ValueKey('account-device-${row.member.pub}'),
- title: row.member.label.trim().isEmpty
- ? 'Unnamed device'
- : row.member.label,
- detail: deviceDetailLine(
- row,
- _seen[row.member.pub],
- DateTime.now(),
- sameName: sharedNames(listing.members)
- .contains(row.member.label.trim()),
++ if (listing != null &&
++ !listing.baselineSeen &&
++ !_baselineHidden) ...[
++ if (_baseline(listing) case final baseline
++ when baseline.isNotEmpty) ...[
++ const SizedBox(height: 12),
++ _BaselinePanel(
++ key: const Key('account-devices-baseline'),
++ rows: baseline,
++ onGotIt: () => unawaited(_gotIt()),
+ ),
- value: row.suspended
- ? 'Suspended'
- : _newPubs.contains(row.member.pub)
- ? 'New'
- : null,
- onTap: () => _open(row),
++ ],
++ ],
+ if (_error case final error?) ...[
+ const SizedBox(height: 12),
- TtyText(error, color: tty.red),
++ Text(
++ error,
++ key: const Key('account-devices-error'),
++ // Amber when the person has something to act on (another account, a list that moved):
++ // the same severity as the desktop. A failure is red.
++ style: tty.style(color: _errorWarns ? tty.yellow : tty.red),
+ ),
+ ],
+ if (listing != null && _unused(listing).isNotEmpty) ...[
+ const SizedBox(height: 12),
+ SettingsGroup(
+ children: [
+ SettingsRow(
+ key: const Key('account-devices-unused'),
+ title:
+ '${_unused(listing).length} app${_unused(listing).length == 1 ? '' : 's'} not used in 90 days',
- detail:
- 'Most likely a browser whose data was cleared.',
++ detail: 'Most likely a browser whose data was cleared.',
+ value: _removingUnused ? 'Removing…' : 'Remove',
+ destructive: true,
+ onTap: _removingUnused
+ ? null
- : () =>
- unawaited(_removeUnused(_unused(listing))),
++ : () => unawaited(_removeUnused(_unused(listing))),
+ ),
+ ],
+ ),
+ ],
+ const SizedBox(height: 12),
+ if (listing == null)
+ const SizedBox.shrink()
+ else ...[
+ if (selfRow(listing.members) case final self?) ...[
+ SettingsGroup(
+ children: [
+ _ThisDeviceCard(
+ key: const Key('account-device-this'),
+ row: self,
+ ),
+ ],
+ ),
+ const SizedBox(height: 12),
+ ],
+ SettingsGroup(
+ children: [
+ for (final row in orderDeviceRows(
+ listing.members,
+ _seen,
+ _newPubs,
+ ))
+ SettingsRow(
+ key: ValueKey('account-device-${row.member.pub}'),
+ title: row.member.label.trim().isEmpty
+ ? 'Unnamed device'
+ : row.member.label,
+ detail: deviceDetailLine(
+ row,
+ _seen[row.member.pub],
+ DateTime.now(),
+ sameName: sharedNames(listing.members)
+ .contains(row.member.label.trim()),
+ ),
- value: _newPubs.contains(row.member.pub)
++ value: row.suspended
++ ? 'Suspended'
++ : _newPubs.contains(row.member.pub)
+ ? 'New'
+ : null,
+ onTap: () => _open(row),
+ ),
+ ],
+ ),
++ const SizedBox(height: 12),
++ SettingsGroup(
++ children: [
++ SettingsRow(
++ key: const Key('account-devices-history'),
++ title: 'History',
++ onTap: _openHistory,
++ ),
++ ],
++ ),
+ ],
],
),
- const SizedBox(height: 12),
- SettingsGroup(
- children: [
- SettingsRow(
- key: const Key('account-devices-history'),
- title: 'History',
- onTap: _openHistory,
- ),
- ],
- ),
- ],
+ ),
],
),
),
diff --cc mobile/lib/phone/phone_shell.dart
index 214b335cf,e9ade5b6e..385498a2c
--- a/mobile/lib/phone/phone_shell.dart
+++ b/mobile/lib/phone/phone_shell.dart
@@@ -6,13 -8,7 +6,9 @@@ import 'package:harness_mobile/state/ap
import '../p2p/phone_terminal_p2p.dart';
import 'agent_home.dart';
- import 'device_detail_page.dart';
- import 'device_rows.dart';
import 'devices_page.dart';
+import 'exit_app.dart';
+import 'new_device_banner.dart';
- import 'phone_navigation.dart' show phoneRoute;
import 'phone_shell_scope.dart';
/// The signed-in phone app: one page stack, rooted in [AgentHome] — the terminal the phone opens
diff --cc mobile/lib/state/app_state.dart
index 4ffb653d2,e45826ef7..f1f8636b7
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@@ -1477,15 -1387,11 +1488,16 @@@ class AppNotifier extends ChangeNotifie
_invalidateAuthWork();
currentUser = null;
signingIn = false;
+ signInProvider = null;
// The code was scanned into the session that just ended — see [logout].
pendingPairing = null;
+ _clearDeviceNotices();
_desk.reset();
zoo.reset();
+ _forgetLaunchHold();
+ // Signed out from elsewhere: the kept screens go as on a sign-out here (see [logout]).
+ _keptScreens.clear();
+ _keptScreenStore?.clear();
unawaited(_pool?.closeAll());
_pool = null;
_lastError = message;
@@@ -1701,10 -1535,11 +1713,13 @@@
// Not awaited: sign-out must not wait on a disk write, and the cache is only
// ever read after a sign-in that this clears the way for.
unawaited(_machineCache?.clear());
+ // The kept screens are this account's terminals — they go with it, as the cache does.
+ _keptScreenStore?.clear();
sessionPreviews.clear();
agentNotices.reset();
+ // The account's device notices go with it: the next sign-in may be another account's, and what
+ // is still pending comes back from its own log once it registers.
+ _clearDeviceNotices();
expandedMachines.clear();
selectedMachineId = null;
status = AppStatus.unauthenticated;
@@@ -1875,6 -1704,37 +1893,34 @@@
}
}
+ /// Tell the device log who is signed in, once per sign-in, synchronously (see
+ /// [ViewerDeviceLog.beginSignIn]); [_registerDeviceLog] then finds it done.
+ void _beginDeviceLogSignIn(int revision) {
+ if (_deviceLogBegun == revision) return;
+ _deviceLogBegun = revision;
+ _deviceLog?.beginSignIn(fresh: viewer.auth.consumeFreshSignIn());
+ }
+
+ /// The account's device key log: this phone's key joins it (an existing sign-in too, from
+ /// before the log existed), and every machine it names is reached with no password. Once per
+ /// sign-in, the moment the app is authenticated ([_finishBootstrapSignedIn]) — before the machine
+ /// list and the profile, and not waiting for either. Which account the log belongs to is a local
+ /// fact the log keeps itself ([_beginDeviceLogSignIn]), never something the backend says, so
+ /// there is nothing to read first.
+ void _registerDeviceLog(int revision) {
+ if (!_authWorkCurrent(revision) || status != AppStatus.authenticated || _deviceLogRegistered == revision) {
+ return;
+ }
+ _deviceLogRegistered = revision;
+ final log = _deviceLog;
+ if (log == null) return;
+ // Normally already begun at the top of [_finishBootstrapSignedIn]; a no-op then.
+ _beginDeviceLogSignIn(revision);
- unawaited(
- log
- .register()
- // Then what is still pending from before (a restart) comes back as the banner.
- .whenComplete(_syncPendingDevices),
- );
++ // Through [_registerDevice], which holds [deviceTrustSettling] while it runs and stamps the
++ // moment a machine the log vouches for may still not have read this key ([_redialOnceVouched]).
++ unawaited(_registerDevice(log, revision));
+ }
+
Future<void> _refreshMachines(int revision) async {
// No machine is "this computer" to a viewer, which has no local CLI: every one — even the one
// it runs on — is reached through the relay.
@@@ -2227,17 -2139,15 +2359,18 @@@
newDevices.add(m);
devicesRevision++;
final name = m.label.isEmpty ? 'A device' : m.label;
- unawaited(agentNotices.system.showAccountNotice(
- key: m.pub,
- title: 'New device on your account',
- body: '$name ${m.kind == 'machine' ? 'joined' : 'signed in to'} your account and can reach '
- 'your machines. Not yours? Remove it in Settings ▸ Your devices.',
- ));
+ unawaited(
+ agentNotices.system.showAccountNotice(
+ key: m.pub,
+ title: 'New device on your account',
+ body:
+ '$name ${m.kind == 'machine' ? 'joined' : 'signed in to'} your account and can reach '
+ 'your machines. Not yours? Remove it in Settings ▸ Your devices.',
+ ),
+ );
if (!_disposed) notifyListeners();
- },
+ }),
+ onRemoved: (n) => _whenSignedIn(() => announceDeviceRemoval(n)),
onSignedOut: () async {
// Sign out first: it takes this phone's key out of the log, which needs the key it is about.
await logout();
@@@ -2253,104 -2164,76 +2387,177 @@@
if (links is DirectLink) links.deviceLog = log;
}
+ /// True while trust between this phone and the account's machines is still being settled by the
+ /// device key log: this phone reading the log and putting its own key into it
+ /// ([ViewerDeviceLog.register]), or a machine the log vouches for being dialled again because it
+ /// had not caught up with this phone's key yet ([_redialOnceVouched]).
+ ///
+ /// ⚠️ **A machine is "locked" the moment a fresh phone dials it, and that is not yet an answer.**
+ /// With nothing pinned, the relay codec refuses the dial on the spot (`NO_PEER_LINK`, 16ms in), long
+ /// before the log has been read and verified — seconds on a phone; and once it is, the machine
+ /// itself still has to read this phone's new key before it stops answering `e2e_denied`. The home
+ /// screen fell through to the machines list, "locked · scan its code", in between. While this is
+ /// set it waits on a locked machine instead (`phone/agent_home.dart` `_loadingMessage`); once it
+ /// clears, a machine still locked really wants its password.
+ bool get deviceTrustSettling =>
+ _registeringDevice || _awaitingVouched.isNotEmpty;
+
+ bool _registeringDevice = false;
+
+ /// When this phone's key last went into the log, in this sign-in — see [_vouchedRedialWindow].
+ DateTime? _deviceRegisteredAt;
+
+ /// Machines waiting out a [_vouchedRedialDelays] step, and how many each has been through.
+ final Set<String> _awaitingVouched = {};
+ final Map<String, int> _vouchedRedials = {};
+
+ /// [_deviceTrustSettleCap]: a log that never answers still lets the screen move on.
+ static const _deviceTrustSettleCap = Duration(seconds: 20);
+
+ /// How long after this phone's key went into the log a machine the log vouches for may still not
+ /// have read it — its CLI hears `device_keys_changed` and reads the log itself, a few seconds.
+ static const _vouchedRedialWindow = Duration(minutes: 1);
+ static const _vouchedRedialDelays = [
+ Duration(milliseconds: 1500),
+ Duration(seconds: 3),
+ Duration(seconds: 5),
+ Duration(seconds: 8),
+ Duration(seconds: 12),
+ ];
+
+ Future<void> _registerDevice(ViewerDeviceLog log, int revision) async {
+ _registeringDevice = true;
+ notifyListeners();
+ try {
++ // Whether the sign-in is fresh was told the log already ([_beginDeviceLogSignIn]).
+ await log
- .register(freshSignIn: viewer.auth.consumeFreshSignIn())
++ .register()
++ // Then what is still pending from before (a restart) comes back as the banner.
++ .whenComplete(_syncPendingDevices)
+ .timeout(_deviceTrustSettleCap);
+ } catch (_) {
+ // Timed out: the register goes on by itself, and a machine it vouches for is still redialled.
+ } finally {
+ if (_authWorkCurrent(revision)) {
+ _registeringDevice = false;
+ _deviceRegisteredAt = DateTime.now();
+ notifyListeners();
+ }
+ }
+ }
+
+ /// A machine refused this phone ([_onLocalFailure]) although the device key log vouches for it —
+ /// this phone pins it — while this phone's own key is new to the log: the machine has most likely
+ /// just not read that key yet, so it is dialled again, a few times, a little later each time.
+ ///
+ /// ⚠️ **Nothing else would ever dial it again.** [_redialNewlyTrusted] runs when the log CHANGES,
+ /// and from this phone's side it already has: the pin landed, the dial went out, and THEN the
+ /// phone's key went in — so the machine, still behind, answered `e2e_denied` to a dial nobody
+ /// retried, and a fresh sign-in sat on "locked" over a machine that would have let it in seconds
+ /// later. Outside [_vouchedRedialWindow] a refusal stands: that is trust revoked, not trust late.
+ Future<void> _redialOnceVouched(String machineId) async {
+ final revision = _authRevision;
+ final attempt = _vouchedRedials[machineId] ?? 0;
+ if (attempt >= _vouchedRedialDelays.length) return;
+ final registeredAt = _deviceRegisteredAt;
+ final keyIsNew =
+ _registeringDevice ||
+ (registeredAt != null &&
+ DateTime.now().difference(registeredAt) < _vouchedRedialWindow);
+ if (!keyIsNew) return;
+ if (await viewer.keys.peer(machineId) == null) return;
+ if (!_authWorkCurrent(revision) || _awaitingVouched.contains(machineId)) {
+ return;
+ }
+ _vouchedRedials[machineId] = attempt + 1;
+ _awaitingVouched.add(machineId);
+ notifyListeners();
+ await Future<void>.delayed(_vouchedRedialDelays[attempt]);
+ // A sign-out meanwhile emptied the set and moved the revision on: nothing here is ours.
+ if (!_authWorkCurrent(revision)) return;
+ _awaitingVouched.remove(machineId);
+ final state = machineStates[machineId];
+ if (state != null && state.needsLink && state.nodeOnline != false) {
+ // Unlocked before the socket goes, as [_redialNewlyTrusted] does: the screen reads it as
+ // connecting from here on, never as locked in between.
+ state.needsLink = false;
+ state.agentLoadStatus = AgentLoadStatus.idle;
+ await _pool?.closeMachine(machineId);
+ _connectMachine(state);
+ }
+ notifyListeners();
+ }
+
+ /// A device was taken out of the account (not by this phone): say so, once. A removal by a new
+ /// device nobody looked at is the alarming one; its notice opens that signer, the rest open the list.
+ void announceDeviceRemoval(DeviceRemovalNotice n) {
+ if (deviceRemovals.any((r) => r.pub == n.pub)) return;
+ deviceRemovals.add(n);
+ devicesRevision++;
+ unawaited(agentNotices.system.showAccountNotice(
+ key: n.red ? 'removedBy:${n.signer}:${n.pub}' : 'removed:${n.pub}',
+ title: n.title,
+ body: n.sentence,
+ ));
+ if (!_disposed) notifyListeners();
+ }
+
+ void dismissDeviceRemoval(String pub) {
+ // Only the notice. The same event may also be kept by the log as "left before you looked" (the
+ // departed band, which has its own "Got it" and is a durable mark): a notice dismissed here —
+ // however benign it reads, e.g. a self sign-out — never clears it.
+ deviceRemovals.removeWhere((r) => r.pub == pub);
+ notifyListeners();
+ }
+
+ /// Bumped by every read of `pending` and every local dismissal: a read that started before either
+ /// is stale and must not put dismissed devices back on the banner.
+ int _pendingSyncGen = 0;
+
+ /// Rebuild [newDevices] from the log's persisted `pending`, oldest first: what survived a restart,
+ /// and what another path (a `group_sync`, a dismiss) changed.
+ Future<void> _syncPendingDevices() async {
+ final log = _deviceLog;
+ if (log == null) return;
+ final gen = ++_pendingSyncGen;
+ final DeviceLogListing listing;
+ try {
+ listing = await log.list();
+ } catch (_) {
+ return;
+ }
+ if (_disposed || gen != _pendingSyncGen || status != AppStatus.authenticated) return;
+ final pending = listing.pending.toSet();
+ _suspendedNew
+ ..clear()
+ ..addAll([
+ for (final r in listing.members)
+ if (r.suspended) r.member.pub,
+ ]);
+ final next = [
+ for (final r in listing.members)
+ if (pending.contains(r.member.pub) &&
+ !r.self &&
+ !_failedDismissals.contains(r.member.pub))
+ r.member,
+ ]..sort((a, b) => a.seq.compareTo(b.seq));
+ final nextDeparted = [
+ for (final d in listing.departed)
+ if (!_failedDismissals.contains(d.pub)) d,
+ ];
+ final same = listEquals([for (final m in next) m.pub], [for (final m in newDevices) m.pub]);
+ final sameDeparted =
+ listEquals([for (final d in nextDeparted) d.pub], [for (final d in departedDevices) d.pub]);
+ if (same && sameDeparted) return;
+ newDevices
+ ..clear()
+ ..addAll(next);
+ departedDevices
+ ..clear()
+ ..addAll(nextDeparted);
+ notifyListeners();
+ }
+
/// A machine waiting for its password that the device key log now vouches for: dial it again.
Future<void> _redialNewlyTrusted() async {
for (final state in [...machineStates.values]) {