diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-02-04 10:11:05 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-02-06 16:58:45 +0100 |
| commit | 662dcd175380e650bf7dfb06adf7f842a0e8cdce (patch) | |
| tree | f389b53c78bc1af0c38cf1678141aac110d9013d /gui | |
| parent | dc1f418c8fdc5a939909079f882d32f7de06f632 (diff) | |
| download | mullvadvpn-662dcd175380e650bf7dfb06adf7f842a0e8cdce.tar.xz mullvadvpn-662dcd175380e650bf7dfb06adf7f842a0e8cdce.zip | |
Add support for .ico files
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/src/main/tray-icon-controller.ts | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/gui/src/main/tray-icon-controller.ts b/gui/src/main/tray-icon-controller.ts index f3333a2636..f4f3925f75 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() }); @@ -61,13 +61,20 @@ export default class TrayIconController { const basePath = path.resolve(path.join(__dirname, '../../assets/images/menubar icons')); const frames = Array.from({ length: 10 }, (_, i) => i + 1); + const suffix = this.imageSuffix(); + const extension = process.platform === 'win32' ? 'ico' : 'png'; + this.iconImages = frames.map((frame) => - nativeImage.createFromPath(path.join(basePath, `lock-${frame}.png`)), + nativeImage.createFromPath(path.join(basePath, `lock-${frame}${suffix}.${extension}`)), ); + } - this.monochromaticIconImages = frames.map((frame) => - nativeImage.createFromPath(path.join(basePath, `lock-${frame}Template.png`)), - ); + private imageSuffix() { + if (this.useMonochromaticIconValue && process.platform === 'darwin') { + return 'Template'; + } else { + return ''; + } } private targetFrame(): number { @@ -80,10 +87,4 @@ export default class TrayIconController { return 8; } } - - private imageForFrame(frame: number): NativeImage { - return this.useMonochromaticIconValue - ? this.monochromaticIconImages[frame] - : this.iconImages[frame]; - } } |
