summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2023-04-19 08:46:03 +0200
committerOskar Nyberg <oskar@mullvad.net>2023-04-19 13:37:31 +0200
commitec33228db6c8c014a67fccd2cd9f2fae9fc414f6 (patch)
treeca454c39017c2182231f146d93b7f2e79db1aac0 /gui/src/main
parent4626da611b7029aad402b251d18b92389a678c76 (diff)
downloadmullvadvpn-ec33228db6c8c014a67fccd2cd9f2fae9fc414f6.tar.xz
mullvadvpn-ec33228db6c8c014a67fccd2cd9f2fae9fc414f6.zip
Refactor command line option handling
Diffstat (limited to 'gui/src/main')
-rw-r--r--gui/src/main/command-line-options.ts60
-rw-r--r--gui/src/main/index.ts6
-rw-r--r--gui/src/main/user-interface.ts6
3 files changed, 51 insertions, 21 deletions
diff --git a/gui/src/main/command-line-options.ts b/gui/src/main/command-line-options.ts
index 543a384029..a7300d1f83 100644
--- a/gui/src/main/command-line-options.ts
+++ b/gui/src/main/command-line-options.ts
@@ -1,17 +1,47 @@
-enum CommandLineOptions {
- showChanges = '--show-changes',
- disableResetNavigation = '--disable-reset-navigation', // development only
- disableDevtoolsOpen = '--disable-devtools-open', // development only
- forwardRendererLog = '--forward-renderer-log', // development only
+class CommandLineOption {
+ private options: string[];
+
+ public constructor(private description: string, ...options: string[]) {
+ this.options = options;
+ }
+
+ public get match(): boolean {
+ return this.options.some((option) => process.argv.includes(option));
+ }
+
+ public format(): string {
+ return formatOption(this.description, ...this.options);
+ }
+}
+
+class DevelopmentCommandLineOption extends CommandLineOption {
+ public constructor(...options: string[]) {
+ super('', ...options);
+ }
+
+ public get match(): boolean {
+ return process.env.NODE_ENV === 'development' && super.match;
+ }
}
-export const SHOULD_SHOW_CHANGES = process.argv.includes(CommandLineOptions.showChanges);
-export const SHOULD_DISABLE_RESET_NAVIGATION = process.argv.includes(
- CommandLineOptions.disableResetNavigation,
-);
-export const SHOULD_DISABLE_DEVTOOLS_OPEN = process.argv.includes(
- CommandLineOptions.disableDevtoolsOpen,
-);
-export const SHOULD_FORWARD_RENDERER_LOG = process.argv.includes(
- CommandLineOptions.forwardRendererLog,
-);
+export const CommandLineOptions = {
+ showChanges: new CommandLineOption('Show changes dialog', '--show-changes'),
+ disableResetNavigation: new DevelopmentCommandLineOption('--disable-reset-navigation'),
+ disableDevtoolsOpen: new DevelopmentCommandLineOption('--disable-devtools-open'),
+ forwardRendererLog: new DevelopmentCommandLineOption('--forward-renderer-log'),
+} as const;
+
+export function printCommandLineOptions() {
+ Object.values(CommandLineOptions).forEach((option) => {
+ if (!(option instanceof DevelopmentCommandLineOption)) {
+ console.log(option.format());
+ }
+ });
+}
+
+function formatOption(description: string, ...options: string[]) {
+ const joinedOptions = options.join(', ');
+ const padding = ' ';
+ const paddedOptions = (joinedOptions + padding).slice(0, -joinedOptions.length);
+ return ' ' + paddedOptions + description;
+}
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 6492b0865a..f14ed2ee3f 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -27,7 +27,7 @@ import {
import Account, { AccountDelegate, LocaleProvider } from './account';
import { getOpenAtLogin } from './autostart';
import { readChangelog } from './changelog';
-import { SHOULD_DISABLE_RESET_NAVIGATION, SHOULD_SHOW_CHANGES } from './command-line-options';
+import { CommandLineOptions, printCommandLineOptions } from './command-line-options';
import { ConnectionObserver, DaemonRpc, SubscriptionListener } from './daemon-rpc';
import Expectation from './expectation';
import { IpcMainEventChannel } from './ipc-event-channel';
@@ -400,7 +400,7 @@ class ApplicationMain
this,
this.daemonRpc,
SANDBOX_DISABLED,
- SHOULD_DISABLE_RESET_NAVIGATION,
+ CommandLineOptions.disableResetNavigation.match,
);
this.tunnelStateExpectation = new Expectation(async () => {
@@ -720,7 +720,7 @@ class ApplicationMain
windowsSplitTunnelingApplications: this.windowsSplitTunnelingApplications,
macOsScrollbarVisibility: this.macOsScrollbarVisibility,
changelog: this.changelog ?? [],
- forceShowChanges: SHOULD_SHOW_CHANGES,
+ forceShowChanges: CommandLineOptions.showChanges.match,
navigationHistory: this.navigationHistory,
}));
diff --git a/gui/src/main/user-interface.ts b/gui/src/main/user-interface.ts
index aa3e8b07f5..4376043f87 100644
--- a/gui/src/main/user-interface.ts
+++ b/gui/src/main/user-interface.ts
@@ -10,7 +10,7 @@ import { IAccountData, ILocation, TunnelState } from '../shared/daemon-rpc-types
import { messages, relayLocations } from '../shared/gettext';
import log from '../shared/logging';
import { Scheduler } from '../shared/scheduler';
-import { SHOULD_DISABLE_DEVTOOLS_OPEN, SHOULD_FORWARD_RENDERER_LOG } from './command-line-options';
+import { CommandLineOptions } from './command-line-options';
import { DaemonRpc } from './daemon-rpc';
import {
changeIpcWebContents,
@@ -110,12 +110,12 @@ export default class UserInterface implements WindowControllerDelegate {
if (process.env.NODE_ENV === 'development') {
await this.installDevTools();
- if (!SHOULD_DISABLE_DEVTOOLS_OPEN) {
+ if (!CommandLineOptions.disableDevtoolsOpen.match) {
// The devtools doesn't open on Windows if openDevTools is called without a delay here.
window.once('ready-to-show', () => window.webContents.openDevTools({ mode: 'detach' }));
}
- if (SHOULD_FORWARD_RENDERER_LOG) {
+ if (CommandLineOptions.forwardRendererLog.match) {
log.addInput(new WebContentsConsoleInput(window.webContents));
}
}