mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
[EC-844] Improve Apple Watch states (#2246)
* EC-844 improve need login / need setup states on the watch * EC-844 Fix naming of things and moved constant to the proper place to maintain format. Also removed UpdateLastUserShouldConnectToWatchAsync from the interface of the StateService given that it's not used outside the service and made it private
This commit is contained in:
parent
a19b5c4e05
commit
728182de6c
5 changed files with 31 additions and 11 deletions
|
@ -91,16 +91,19 @@ namespace Bit.App.Services
|
|||
|
||||
private async Task<WatchState> GetStateAsync(string userId, bool shouldConnectToWatch)
|
||||
{
|
||||
if (await _stateService.GetLastUserShouldConnectToWatchAsync()
|
||||
&&
|
||||
(userId is null || !await _stateService.IsAuthenticatedAsync()))
|
||||
{
|
||||
// if the last user had "Connect to Watch" enabled and there's no user authenticated
|
||||
return WatchState.NeedLogin;
|
||||
}
|
||||
|
||||
if (!shouldConnectToWatch)
|
||||
{
|
||||
return WatchState.NeedSetup;
|
||||
}
|
||||
|
||||
if (!await _stateService.IsAuthenticatedAsync() || userId is null)
|
||||
{
|
||||
return WatchState.NeedLogin;
|
||||
}
|
||||
|
||||
//if (await _vaultTimeoutService.IsLockedAsync() ||
|
||||
// await _vaultTimeoutService.ShouldLockAsync())
|
||||
//{
|
||||
|
|
|
@ -162,5 +162,6 @@ namespace Bit.Core.Abstractions
|
|||
Task SetUsernameGenerationOptionsAsync(UsernameGenerationOptions value, string userId = null);
|
||||
Task<bool> GetShouldConnectToWatchAsync(string userId = null);
|
||||
Task SetShouldConnectToWatchAsync(bool shouldConnect, string userId = null);
|
||||
Task<bool> GetLastUserShouldConnectToWatchAsync();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,11 @@
|
|||
public const string NotificationData = "notificationData";
|
||||
public const string NotificationDataType = "Type";
|
||||
public const string PasswordlessLoginRequestKey = "passwordlessLoginRequest";
|
||||
/// <summary>
|
||||
/// This key is used to store the value of "ShouldConnectToWatch" of the last user that had logged in
|
||||
/// which is used to handle Apple Watch state logic
|
||||
/// </summary>
|
||||
public const string LastUserShouldConnectToWatchKey = "lastUserShouldConnectToWatch";
|
||||
public const int SelectFileRequestCode = 42;
|
||||
public const int SelectFilePermissionRequestCode = 43;
|
||||
public const int SaveFileRequestCode = 44;
|
||||
|
|
|
@ -84,6 +84,8 @@ namespace Bit.Core.Services
|
|||
// Update pre-auth settings based on now-active user
|
||||
await SetRememberedOrgIdentifierAsync(await GetRememberedOrgIdentifierAsync());
|
||||
await SetPreAuthEnvironmentUrlsAsync(await GetEnvironmentUrlsAsync());
|
||||
|
||||
await SetLastUserShouldConnectToWatchAsync();
|
||||
}
|
||||
|
||||
public async Task CheckExtensionActiveUserAndSwitchIfNeededAsync()
|
||||
|
@ -1708,6 +1710,21 @@ namespace Bit.Core.Services
|
|||
ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync());
|
||||
var key = Constants.ShouldConnectToWatchKey(reconciledOptions.UserId);
|
||||
await SetValueAsync(key, shouldConnect, reconciledOptions);
|
||||
await SetLastUserShouldConnectToWatchAsync(shouldConnect);
|
||||
}
|
||||
|
||||
public async Task<bool> GetLastUserShouldConnectToWatchAsync()
|
||||
{
|
||||
var options = await GetDefaultStorageOptionsAsync();
|
||||
var key = Constants.LastUserShouldConnectToWatchKey;
|
||||
return await GetValueAsync<bool?>(key, options) ?? false;
|
||||
}
|
||||
|
||||
private async Task SetLastUserShouldConnectToWatchAsync(bool? shouldConnect = null)
|
||||
{
|
||||
var options = await GetDefaultStorageOptionsAsync();
|
||||
var key = Constants.LastUserShouldConnectToWatchKey;
|
||||
await SetValueAsync(key, shouldConnect ?? await GetShouldConnectToWatchAsync(), options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,12 +51,6 @@ class CipherListViewModel : ObservableObject {
|
|||
|
||||
user = StateService.shared.getUser()
|
||||
|
||||
if user == nil && !watchConnectivityManager.isSessionActivated {
|
||||
currentState = .needSetup
|
||||
showingSheet = true
|
||||
return
|
||||
}
|
||||
|
||||
currentState = state ?? StateService.shared.currentState
|
||||
showingSheet = currentState != .valid
|
||||
|
||||
|
|
Loading…
Reference in a new issue