diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-07-16 13:21:26 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-07-16 13:21:26 +0200 |
| commit | 19d3618e8f88bf6d9a392df3a39a33be889d169e (patch) | |
| tree | 9210ae31100d1c3963bca8d5dd6e6c66ae7a30d9 | |
| parent | 91bcb610346e9b73bb4bbd5dff848992c6bebf9c (diff) | |
| parent | 35309868a2c88228e891516e4d7cfc77a9bd8df0 (diff) | |
| download | mullvadvpn-19d3618e8f88bf6d9a392df3a39a33be889d169e.tar.xz mullvadvpn-19d3618e8f88bf6d9a392df3a39a33be889d169e.zip | |
Merge branch 'fix-history-init'
| -rw-r--r-- | gui/src/main/window-controller.ts | 12 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 64 |
2 files changed, 45 insertions, 31 deletions
diff --git a/gui/src/main/window-controller.ts b/gui/src/main/window-controller.ts index 450123d035..50ceab01e4 100644 --- a/gui/src/main/window-controller.ts +++ b/gui/src/main/window-controller.ts @@ -133,7 +133,6 @@ export default class WindowController { private windowValue: BrowserWindow; private webContentsValue: WebContents; private windowPositioning: IWindowPositioning; - private isWindowReady = false; get window(): BrowserWindow | undefined { return this.windowValue.isDestroyed() ? undefined : this.windowValue; @@ -154,7 +153,6 @@ export default class WindowController { : new AttachedToTrayWindowPositioning(tray); this.installDisplayMetricsHandler(); - this.installWindowReadyHandlers(); } public replaceWindow(window: BrowserWindow, unpinnedWindow: boolean) { @@ -269,17 +267,11 @@ export default class WindowController { this.window?.setSize(this.width, this.height); } - private installWindowReadyHandlers() { - this.window?.once('ready-to-show', () => { - this.isWindowReady = true; - }); - } - private executeWhenWindowIsReady(closure: () => void) { - if (this.isWindowReady) { + if (this.webContents?.isLoading() === false && this.webContents?.getURL() !== '') { closure(); } else { - this.window?.once('ready-to-show', () => { + this.webContents?.once('did-stop-loading', () => { closure(); }); } diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 5d4d957da4..eb68ed963b 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -23,7 +23,7 @@ import log, { ConsoleOutput } from '../shared/logging'; import { IRelayListPair, LaunchApplicationResult } from '../shared/ipc-schema'; import consumePromise from '../shared/promise'; import { Scheduler } from '../shared/scheduler'; -import History, { transitions } from './lib/history'; +import History, { ITransitionSpecification, transitions } from './lib/history'; import { loadTranslations } from './lib/load-translations'; import { @@ -105,7 +105,7 @@ const SUPPORTED_LOCALE_LIST = [ ]; export default class AppRenderer { - private history = new History('/'); + private history: History; private reduxStore = configureStore(); private reduxActions = { account: bindActionCreators(accountActions, this.reduxStore.dispatch), @@ -224,9 +224,9 @@ export default class AppRenderer { initialState.accountData?.expiry, initialState.accountData?.previousExpiry, ); + this.setSettings(initialState.settings); this.handleAccountChange(undefined, initialState.settings.accountToken); this.setAccountHistory(initialState.accountHistory); - this.setSettings(initialState.settings); this.setTunnelState(initialState.tunnelState); this.updateBlockedState(initialState.tunnelState, initialState.settings.blockWhenDisconnected); @@ -252,6 +252,12 @@ export default class AppRenderer { initialState.windowsSplitTunnelingApplications, ); } + + const navigationBase = this.getNavigationBase( + initialState.isConnected, + initialState.settings.accountToken, + ); + this.history = new History(navigationBase); } public renderView() { @@ -648,27 +654,43 @@ export default class AppRenderer { } private resetNavigation() { - const pathname = this.history.location.pathname; + if (this.history) { + const pathname = this.history.location.pathname; + const nextPath = this.getNavigationBase(this.connectedToDaemon, this.settings.accountToken); - if (this.connectedToDaemon) { - if (this.settings.accountToken) { - const transition = - pathname === '/login' || pathname === '/' ? transitions.push : transitions.dismiss; - this.history.reset('/main', transition); - } else { - const transition = - pathname === '/main' - ? transitions.pop - : pathname === '/' - ? transitions.push - : transitions.none; + // First level contains the possible next locations and the second level contains the possible + // current locations. + const navigationTransitions: { + [from: string]: { [to: string]: ITransitionSpecification }; + } = { + '/': { + '/login': transitions.pop, + '/main': transitions.pop, + '*': transitions.dismiss, + }, + '/login': { + '/': transitions.push, + '/main': transitions.pop, + '*': transitions.none, + }, + '/main': { + '/': transitions.push, + '/login': transitions.push, + '*': transitions.dismiss, + }, + }; - this.history.reset('/login', transition); - } - } else { const transition = - pathname === '/login' || pathname === '/main' ? transitions.pop : transitions.dismiss; - this.history.reset('/', transition); + navigationTransitions[nextPath][pathname] ?? navigationTransitions[nextPath]['*']; + this.history.reset(nextPath, transition); + } + } + + private getNavigationBase(connectedToDaemon: boolean, accountToken?: string): string { + if (connectedToDaemon) { + return accountToken ? '/main' : '/login'; + } else { + return '/'; } } |
