add logout button to session load error screen

This commit is contained in:
Bruno Windels 2021-10-28 11:47:31 +02:00
parent cbccca20d0
commit 68a6113c26
5 changed files with 27 additions and 11 deletions

View File

@ -153,6 +153,11 @@ export class SessionLoadViewModel extends ViewModel {
this.platform.saveFileAs(logExport.asBlob(), `hydrogen-logs-${this.platform.clock.now()}.json`); this.platform.saveFileAs(logExport.asBlob(), `hydrogen-logs-${this.platform.clock.now()}.json`);
} }
async logout() {
await this._sessionContainer.logout();
this.navigation.push("session", true);
}
get accountSetupViewModel() { get accountSetupViewModel() {
return this._accountSetupViewModel; return this._accountSetupViewModel;
} }

View File

@ -57,16 +57,11 @@ export class SettingsViewModel extends ViewModel {
return this._sessionContainer.session; return this._sessionContainer.session;
} }
logout() { async logout() {
return this.logger.run("logout", async log => { this._isLoggingOut = true;
this._isLoggingOut = true; await this._sessionContainer.logout();
this.emitChange("isLoggingOut"); this.emitChange("isLoggingOut");
try { this.navigation.push("session", true);
await this._session.logout(log);
} catch (err) {}
await this._sessionContainer.deleteSession(log);
this.navigation.push("session", true);
});
} }
setupDehydratedDevice(key) { setupDehydratedDevice(key) {

View File

@ -107,6 +107,7 @@ export class Session {
return this._sessionInfo.userId; return this._sessionInfo.userId;
} }
/** @internal call SessionContainer.logout instead */
async logout(log = undefined) { async logout(log = undefined) {
await this._hsApi.logout({log}).response(); await this._hsApi.logout({log}).response();
} }

View File

@ -367,6 +367,15 @@ export class SessionContainer {
return !this._reconnector; return !this._reconnector;
} }
logout() {
return this._platform.logger.run("logout", async log => {
try {
await this._session?.logout(log);
} catch (err) {}
await this.deleteSession(log);
});
}
dispose() { dispose() {
if (this._reconnectSubscription) { if (this._reconnectSubscription) {
this._reconnectSubscription(); this._reconnectSubscription();

View File

@ -28,11 +28,17 @@ export class SessionLoadStatusView extends TemplateView {
onClick: () => vm.exportLogs() onClick: () => vm.exportLogs()
}, vm.i18n`Export logs`); }, vm.i18n`Export logs`);
}); });
const logoutButtonIfFailed = t.if(vm => vm.hasError, (t, vm) => {
return t.button({
onClick: () => vm.logout()
}, vm.i18n`Log out`);
});
return t.div({className: "SessionLoadStatusView"}, [ return t.div({className: "SessionLoadStatusView"}, [
t.p({className: "status"}, [ t.p({className: "status"}, [
spinner(t, {hidden: vm => !vm.loading}), spinner(t, {hidden: vm => !vm.loading}),
t.p(vm => vm.loadLabel), t.p(vm => vm.loadLabel),
exportLogsButtonIfFailed exportLogsButtonIfFailed,
logoutButtonIfFailed
]), ]),
t.ifView(vm => vm.accountSetupViewModel, vm => new AccountSetupView(vm.accountSetupViewModel)), t.ifView(vm => vm.accountSetupViewModel, vm => new AccountSetupView(vm.accountSetupViewModel)),
]); ]);