summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2022-12-02 09:04:01 +0100
committerOskar Nyberg <oskar@mullvad.net>2023-02-09 10:39:26 +0100
commit5793182b65dd1c67cedd82a4cb6b7c5aa742cf86 (patch)
tree8edbc85ac8bad3414753395b00eadfe9149d962e /gui/src
parent15656b4d8adf9785101e873ffa41470efd9094fb (diff)
downloadmullvadvpn-5793182b65dd1c67cedd82a4cb6b7c5aa742cf86.tar.xz
mullvadvpn-5793182b65dd1c67cedd82a4cb6b7c5aa742cf86.zip
Load icons when theme change instead of all at launch
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main/tray-icon-controller.ts58
1 files changed, 18 insertions, 40 deletions
diff --git a/gui/src/main/tray-icon-controller.ts b/gui/src/main/tray-icon-controller.ts
index cee57c0161..2fd2449f9f 100644
--- a/gui/src/main/tray-icon-controller.ts
+++ b/gui/src/main/tray-icon-controller.ts
@@ -10,16 +10,8 @@ const exec = promisify(execAsync);
export type TrayIconType = 'unsecured' | 'securing' | 'secured';
-type IconSets = {
- regular: NativeImage[];
- template: NativeImage[];
- white: NativeImage[];
- black: NativeImage[];
-};
-
export default class TrayIconController {
private animation?: KeyframeAnimation;
- private iconSets: IconSets = { regular: [], template: [], white: [], black: [] };
private iconSet: NativeImage[] = [];
constructor(
@@ -27,7 +19,11 @@ export default class TrayIconController {
private iconTypeValue: TrayIconType,
private useMonochromaticIconValue: boolean,
) {
- this.loadImages();
+ void this.init();
+ }
+
+ public async init() {
+ this.iconSet = await this.loadImages();
}
public dispose() {
@@ -42,27 +38,7 @@ export default class TrayIconController {
}
public async updateTheme() {
- if (this.useMonochromaticIconValue) {
- switch (process.platform) {
- case 'darwin':
- this.iconSet = this.iconSets.template;
- break;
- case 'win32': {
- if (await this.getSystemUsesLightTheme()) {
- this.iconSet = this.iconSets.black;
- } else {
- this.iconSet = this.iconSets.white;
- }
- break;
- }
- case 'linux':
- default:
- this.iconSet = this.iconSets.white;
- break;
- }
- } else {
- this.iconSet = this.iconSets.regular;
- }
+ this.iconSet = await this.loadImages();
if (this.animation === undefined) {
this.initAnimation();
@@ -108,21 +84,23 @@ export default class TrayIconController {
}
};
- private loadImages() {
- this.iconSets.regular = this.loadImageSet('');
-
+ private async loadImages(): Promise<NativeImage[]> {
switch (process.platform) {
case 'darwin':
- this.iconSets.template = this.loadImageSet('Template');
- break;
+ return this.useMonochromaticIconValue
+ ? this.loadImageSet('Template')
+ : this.loadImageSet('');
case 'win32':
- this.iconSets.white = this.loadImageSet('_white');
- this.iconSets.black = this.loadImageSet('_black');
- break;
+ if (this.useMonochromaticIconValue) {
+ return (await this.getSystemUsesLightTheme())
+ ? this.loadImageSet('_black')
+ : this.loadImageSet('_white');
+ } else {
+ return this.loadImageSet('');
+ }
case 'linux':
default:
- this.iconSets.white = this.loadImageSet('_white');
- break;
+ return this.useMonochromaticIconValue ? this.loadImageSet('_white') : this.loadImageSet('');
}
}