summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-07-15 11:17:32 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-07-16 13:02:14 +0200
commit051edd1fe2eacf809c02ceb4b7c6667af8317608 (patch)
tree5f8c85018c9d7f11824cef938fd0bc1b7a2f1f62
parent91bcb610346e9b73bb4bbd5dff848992c6bebf9c (diff)
downloadmullvadvpn-051edd1fe2eacf809c02ceb4b7c6667af8317608.tar.xz
mullvadvpn-051edd1fe2eacf809c02ceb4b7c6667af8317608.zip
Prevent initial route transition when launching app
-rw-r--r--gui/src/renderer/app.tsx64
1 files changed, 43 insertions, 21 deletions
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 '/';
}
}