diff --git a/packages/neon_framework/lib/src/blocs/accounts.dart b/packages/neon_framework/lib/src/blocs/accounts.dart index ba71bae42d3..426b7f26188 100644 --- a/packages/neon_framework/lib/src/blocs/accounts.dart +++ b/packages/neon_framework/lib/src/blocs/accounts.dart @@ -111,6 +111,7 @@ class _AccountsBloc extends Bloc implements AccountsBloc { for (final app in allAppImplementations) { app.blocsCache.pruneAgainst(accounts); } + unawaited(checkRemoteWipe(accounts)); }); } @@ -129,6 +130,7 @@ class _AccountsBloc extends Bloc implements AccountsBloc { final weatherStatusBlocs = AccountCache(); final maintenanceModeBlocs = AccountCache(); final referencesBlocs = AccountCache(); + final remoteWipeChecks = {}; @override void dispose() { @@ -228,4 +230,45 @@ class _AccountsBloc extends Bloc implements AccountsBloc { account: account, capabilities: getCapabilitiesBlocFor(account).capabilities, ); + + Future checkRemoteWipe(BuiltList 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); + } + } + } }