Skip to content

Commit

Permalink
feat(neon_framework): Implement remote wipe
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Nov 19, 2024
1 parent 783daa2 commit 9cdbda3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/neon_framework/lib/src/blocs/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class _AccountsBloc extends Bloc implements AccountsBloc {
for (final app in allAppImplementations) {
app.blocsCache.pruneAgainst(accounts);
}
unawaited(checkRemoteWipe(accounts));
});
}

Expand All @@ -129,6 +130,7 @@ class _AccountsBloc extends Bloc implements AccountsBloc {
final weatherStatusBlocs = AccountCache<WeatherStatusBloc>();
final maintenanceModeBlocs = AccountCache<MaintenanceModeBloc>();
final referencesBlocs = AccountCache<ReferencesBloc>();
final remoteWipeChecks = <Account>{};

@override
void dispose() {
Expand Down Expand Up @@ -228,4 +230,45 @@ class _AccountsBloc extends Bloc implements AccountsBloc {
account: account,
capabilities: getCapabilitiesBlocFor(account).capabilities,
);

Future<void> checkRemoteWipe(BuiltList<Account> accounts) async {
for (final account in accounts) {
// Only check each account once per app start
if (remoteWipeChecks.contains(account)) {
return;
}
remoteWipeChecks.add(account);

log.finer('Checking remote wipe status for account ${account.id}.');

var wipe = false;
try {
wipe = await _accountRepository.getRemoteWipeStatus(account);
} on GetRemoteWipeStatusFailure catch (error, stackTrace) {
log.finer(
'Failed to get remote wipe status for account ${account.id}.',
error,
stackTrace,
);
}

if (wipe) {
log.finer('Wiping account ${account.id}.');

try {
await _accountRepository.postRemoteWipeSuccess(account);

log.finer('Wiped account ${account.id}.');
} on PostRemoteWipeSuccessFailure catch (error, stackTrace) {
log.finer(
'Failed to post remote wipe success for account ${account.id}.',
error,
stackTrace,
);
}

await removeAccount(account);
}
}
}
}

0 comments on commit 9cdbda3

Please sign in to comment.