EC-830 Fix state checking when watch app had already been installed before, so reset it if first run. (#2232)
This commit is contained in:
parent
28d204f2b1
commit
b30fc12135
|
@ -70,6 +70,10 @@ public class CryptoService{
|
|||
}
|
||||
return data
|
||||
}
|
||||
|
||||
static func clearKey() {
|
||||
KeychainHelper.standard.delete(CryptoService.ENCRYPTION_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Data {
|
||||
|
|
|
@ -42,4 +42,9 @@ class EnvironmentService{
|
|||
}
|
||||
KeychainHelper.standard.save(url.data(using: .utf8)!, ICONS_URL_KEY)
|
||||
}
|
||||
|
||||
func clear() {
|
||||
baseUrl = nil
|
||||
setIconsUrl(url: nil)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,14 @@ import Foundation
|
|||
class StateService {
|
||||
static let shared: StateService = StateService()
|
||||
|
||||
let HAS_RUN_BEFORE_KEY = "has_run_before_key"
|
||||
let CURRENT_STATE_KEY = "current_state_key"
|
||||
let CURRENT_USER_KEY = "current_user_key"
|
||||
// let TIMEOUT_MINUTES_KEY = "timeout_minutes_key"
|
||||
// let TIMEOUT_ACTION_KEY = "timeout_action_key"
|
||||
|
||||
var hasRunBefore = false
|
||||
|
||||
private init(){}
|
||||
|
||||
var currentState:BWState {
|
||||
|
@ -40,6 +43,29 @@ class StateService {
|
|||
KeychainHelper.standard.save(user, key: CURRENT_USER_KEY)
|
||||
}
|
||||
|
||||
/// Checks the state integrity of the app. If the app has been reinstalled then there are some keychain things that need to be reset.
|
||||
func checkIntegrity() {
|
||||
if hasRunBefore {
|
||||
return
|
||||
}
|
||||
|
||||
let userDefaults = UserDefaults.standard
|
||||
hasRunBefore = userDefaults.bool(forKey: HAS_RUN_BEFORE_KEY)
|
||||
|
||||
if !hasRunBefore {
|
||||
clear()
|
||||
EnvironmentService.shared.clear()
|
||||
CryptoService.clearKey()
|
||||
|
||||
userDefaults.set(true, forKey: HAS_RUN_BEFORE_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
func clear() {
|
||||
currentState = .needSetup
|
||||
setUser(user: nil)
|
||||
}
|
||||
|
||||
// var vaultTimeoutInMinutes: Int? {
|
||||
// guard let timeoutData = KeychainHelper.standard.read(TIMEOUT_MINUTES_KEY),
|
||||
// let strData = String(data: timeoutData, encoding: .utf8),
|
||||
|
|
|
@ -47,6 +47,8 @@ class CipherListViewModel : ObservableObject {
|
|||
}
|
||||
|
||||
func checkStateAndFetch(_ state: BWState? = nil) {
|
||||
StateService.shared.checkIntegrity()
|
||||
|
||||
user = StateService.shared.getUser()
|
||||
|
||||
if user == nil && !watchConnectivityManager.isSessionActivated {
|
||||
|
|
Loading…
Reference in New Issue