fix: update encryption status after a passcode operation completes

This commit is contained in:
Baptiste Grob
2020-08-26 18:34:15 +02:00
parent 6483ad3fe7
commit 3ac863098f

View File

@@ -109,7 +109,7 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
this.setState(this.refreshedCredentialState()); this.setState(this.refreshedCredentialState());
this.loadHost(); this.loadHost();
this.reloadAutoLockInterval(); this.reloadAutoLockInterval();
this.loadBackupsAvailability(); this.refreshEncryptionStatus();
} }
refreshedCredentialState() { refreshedCredentialState() {
@@ -148,27 +148,21 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
this.application!.setHost(url); this.application!.setHost(url);
} }
async loadBackupsAvailability() { refreshEncryptionStatus() {
const hasUser = !isNullOrUndefined(this.application!.getUser()); const hasUser = this.application!.hasAccount();
const hasPasscode = this.application!.hasPasscode(); const hasPasscode = this.application!.hasPasscode();
const encryptedAvailable = hasUser || hasPasscode; const encryptionEnabled = hasUser || hasPasscode;
function encryptionStatusString() {
if (hasUser) {
return STRING_E2E_ENABLED;
} else if (hasPasscode) {
return STRING_LOCAL_ENC_ENABLED;
} else {
return STRING_ENC_NOT_ENABLED;
}
}
this.setState({ this.setState({
encryptionStatusString: encryptionStatusString(), encryptionStatusString: hasUser
encryptionEnabled: encryptedAvailable, ? STRING_E2E_ENABLED
: hasPasscode
? STRING_LOCAL_ENC_ENABLED
: STRING_ENC_NOT_ENABLED,
encryptionEnabled,
mutable: { mutable: {
...this.getState().mutable, ...this.getState().mutable,
backupEncrypted: encryptedAvailable backupEncrypted: encryptionEnabled
} }
}); });
} }
@@ -515,18 +509,19 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
return; return;
} }
preventRefreshing(STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE, async () => { await preventRefreshing(STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE, async () => {
if (this.application!.hasPasscode()) { if (this.application!.hasPasscode()) {
await this.application!.changePasscode(passcode); await this.application!.changePasscode(passcode);
} else { } else {
await this.application!.setPasscode(passcode); await this.application!.setPasscode(passcode);
} }
this.setFormDataState({
passcode: undefined,
confirmPasscode: undefined,
showPasscodeForm: false
});
}); });
this.setFormDataState({
passcode: undefined,
confirmPasscode: undefined,
showPasscodeForm: false
});
this.refreshEncryptionStatus();
} }
async changePasscodePressed() { async changePasscodePressed() {
@@ -558,9 +553,10 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
text: message, text: message,
confirmButtonStyle: 'danger' confirmButtonStyle: 'danger'
})) { })) {
preventRefreshing(STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_REMOVAL, async () => { await preventRefreshing(STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_REMOVAL, async () => {
await this.application!.removePasscode(); await this.application!.removePasscode();
}); });
this.refreshEncryptionStatus();
} }
}; };
const needsPrivilege = await this.application!.privilegesService!.actionRequiresPrivilege( const needsPrivilege = await this.application!.privilegesService!.actionRequiresPrivilege(