diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-02-06 16:59:12 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-02-06 16:59:12 +0100 |
| commit | e498f07e2322d581e1e0a5b5fc0243fa919eedb3 (patch) | |
| tree | edf2a7ade62568166f14cd07ef850a5d792a1f5d /gui/src/main | |
| parent | dc1f418c8fdc5a939909079f882d32f7de06f632 (diff) | |
| parent | 8daeac54caec833675cf65b0fac551b78e5944dc (diff) | |
| download | mullvadvpn-e498f07e2322d581e1e0a5b5fc0243fa919eedb3.tar.xz mullvadvpn-e498f07e2322d581e1e0a5b5fc0243fa919eedb3.zip | |
Merge branch 'monochrome-icons-on-windows-linux'
Diffstat (limited to 'gui/src/main')
| -rw-r--r-- | gui/src/main/index.ts | 7 | ||||
| -rw-r--r-- | gui/src/main/tray-icon-controller.ts | 27 |
2 files changed, 14 insertions, 20 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 6663a5574e..4df3b4c7a2 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -319,7 +319,7 @@ class ApplicationMain { const trayIconController = new TrayIconController( tray, 'unsecured', - process.platform === 'darwin' && this.guiSettings.monochromaticIcon, + this.guiSettings.monochromaticIcon, ); this.registerWindowListener(windowController); @@ -330,10 +330,7 @@ class ApplicationMain { this.trayIconController = trayIconController; this.guiSettings.onChange = (newState, oldState) => { - if ( - process.platform === 'darwin' && - oldState.monochromaticIcon !== newState.monochromaticIcon - ) { + if (oldState.monochromaticIcon !== newState.monochromaticIcon) { if (this.trayIconController) { this.trayIconController.useMonochromaticIcon = newState.monochromaticIcon; } diff --git a/gui/src/main/tray-icon-controller.ts b/gui/src/main/tray-icon-controller.ts index f3333a2636..bb1d4f5868 100644 --- a/gui/src/main/tray-icon-controller.ts +++ b/gui/src/main/tray-icon-controller.ts @@ -7,7 +7,6 @@ export type TrayIconType = 'unsecured' | 'securing' | 'secured'; export default class TrayIconController { private animation?: KeyframeAnimation; private iconImages: NativeImage[] = []; - private monochromaticIconImages: NativeImage[] = []; constructor( tray: Tray, @@ -19,7 +18,7 @@ export default class TrayIconController { const initialFrame = this.targetFrame(); const animation = new KeyframeAnimation(); animation.speed = 100; - animation.onFrame = (frameNumber) => tray.setImage(this.imageForFrame(frameNumber)); + animation.onFrame = (frameNumber) => tray.setImage(this.iconImages[frameNumber]); animation.play({ start: initialFrame, end: initialFrame }); this.animation = animation; @@ -38,6 +37,7 @@ export default class TrayIconController { set useMonochromaticIcon(useMonochromaticIcon: boolean) { this.useMonochromaticIconValue = useMonochromaticIcon; + this.loadImages(); if (this.animation && !this.animation.isRunning) { this.animation.play({ end: this.targetFrame() }); @@ -58,16 +58,19 @@ export default class TrayIconController { } private loadImages() { - const basePath = path.resolve(path.join(__dirname, '../../assets/images/menubar icons')); const frames = Array.from({ length: 10 }, (_, i) => i + 1); + this.iconImages = frames.map((frame) => nativeImage.createFromPath(this.getImagePath(frame))); + } - this.iconImages = frames.map((frame) => - nativeImage.createFromPath(path.join(basePath, `lock-${frame}.png`)), - ); + private getImagePath(frame: number) { + const basePath = path.resolve(path.join(__dirname, '../../assets/images/menubar icons')); + const extension = process.platform === 'win32' ? 'ico' : 'png'; + let suffix = ''; + if (this.useMonochromaticIconValue) { + suffix = process.platform === 'darwin' ? 'Template' : '_white'; + } - this.monochromaticIconImages = frames.map((frame) => - nativeImage.createFromPath(path.join(basePath, `lock-${frame}Template.png`)), - ); + return path.join(basePath, process.platform, `lock-${frame}${suffix}.${extension}`); } private targetFrame(): number { @@ -80,10 +83,4 @@ export default class TrayIconController { return 8; } } - - private imageForFrame(frame: number): NativeImage { - return this.useMonochromaticIconValue - ? this.monochromaticIconImages[frame] - : this.iconImages[frame]; - } } |
