summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-03-30 22:01:43 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-03-30 22:01:43 +0200
commit31f5597f96bb9bf4c37039c696eec590bc168700 (patch)
tree4711fe2f32ca9cd59174bcf7a558b205a9c590c0
parent365ccb65b6b03d3dde3f34f335cdd23e084c3600 (diff)
parent8c35cdb564b9c1bf498947cf9d4464e2e694bf86 (diff)
downloadmullvadvpn-31f5597f96bb9bf4c37039c696eec590bc168700.tar.xz
mullvadvpn-31f5597f96bb9bf4c37039c696eec590bc168700.zip
Merge branch 'start-with-correct-menubar-icon-2'
-rw-r--r--gui/src/main/expectation.ts20
-rw-r--r--gui/src/main/index.ts19
2 files changed, 33 insertions, 6 deletions
diff --git a/gui/src/main/expectation.ts b/gui/src/main/expectation.ts
new file mode 100644
index 0000000000..18fafb2836
--- /dev/null
+++ b/gui/src/main/expectation.ts
@@ -0,0 +1,20 @@
+export default class Expectation {
+ private fulfilled = false;
+ private timeout: NodeJS.Timeout;
+
+ constructor(private handler: () => void, timeout = 2000) {
+ this.timeout = global.setTimeout(() => {
+ this.fulfill();
+ }, timeout);
+ }
+
+ public fulfill() {
+ if (this.fulfilled) {
+ return;
+ }
+
+ this.fulfilled = true;
+ global.clearTimeout(this.timeout);
+ this.handler();
+ }
+}
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 0f1082e0fa..417a6648cb 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -44,6 +44,7 @@ import {
SubscriptionListener,
} from './daemon-rpc';
import { InvalidAccountError } from './errors';
+import Expectation from './expectation';
import GuiSettings from './gui-settings';
import NotificationController from './notification-controller';
import { resolveBin } from './proc';
@@ -127,6 +128,7 @@ class ApplicationMain {
private guiSettings = new GuiSettings();
private location?: ILocation;
private lastDisconnectedLocation?: ILocation;
+ private tunnelStateExpectation?: Expectation;
private relays: IRelayList = { countries: [] };
@@ -323,18 +325,19 @@ class ApplicationMain {
const tray = this.createTray();
const windowController = new WindowController(window, tray);
- const trayIconController = new TrayIconController(
- tray,
- 'unsecured',
- this.guiSettings.monochromaticIcon,
- );
+ this.tunnelStateExpectation = new Expectation(() => {
+ this.trayIconController = new TrayIconController(
+ tray,
+ this.trayIconType(this.tunnelState, this.settings.blockWhenDisconnected),
+ this.guiSettings.monochromaticIcon,
+ );
+ });
this.registerWindowListener(windowController);
this.registerIpcListeners();
this.addContextMenu(window);
this.windowController = windowController;
- this.trayIconController = trayIconController;
this.guiSettings.onChange = (newState, oldState) => {
if (oldState.monochromaticIcon !== newState.monochromaticIcon) {
@@ -426,6 +429,10 @@ class ApplicationMain {
return this.recoverFromBootstrapError(error);
}
+ if (this.tunnelStateExpectation) {
+ this.tunnelStateExpectation.fulfill();
+ }
+
// fetch relays
try {
this.setRelays(