use proper nativeimage
This commit is contained in:
parent
70606f208b
commit
0fe8782c2d
|
@ -1,5 +1,5 @@
|
||||||
import {
|
import {
|
||||||
NativeImage,
|
nativeImage,
|
||||||
Tray,
|
Tray,
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
@ -10,15 +10,17 @@ import { DesktopConstants } from '../desktopConstants';
|
||||||
|
|
||||||
export class TrayMain {
|
export class TrayMain {
|
||||||
private tray: Tray;
|
private tray: Tray;
|
||||||
private icon: string | NativeImage;
|
private icon: string | Electron.NativeImage;
|
||||||
|
private pressedIcon: Electron.NativeImage;
|
||||||
|
|
||||||
constructor(private windowMain: WindowMain, private appName: string, private minToTray: () => Promise<boolean>) {
|
constructor(private windowMain: WindowMain, private appName: string, private minToTray: () => Promise<boolean>) {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
this.icon = path.join(__dirname, '/images/icon.ico');
|
this.icon = path.join(__dirname, '/images/icon.ico');
|
||||||
} else if (process.platform === 'darwin') {
|
} else if (process.platform === 'darwin') {
|
||||||
const nativeImage = NativeImage.createFromPath(path.join(__dirname, '/images/icon-template.png'));
|
const nImage = nativeImage.createFromPath(path.join(__dirname, '/images/icon-template.png'));
|
||||||
nativeImage.setTemplateImage(true);
|
nImage.setTemplateImage(true);
|
||||||
this.icon = nativeImage;
|
this.icon = nImage;
|
||||||
|
this.pressedIcon = nativeImage.createFromPath(path.join(__dirname, '/images/icon-highlight.png'));
|
||||||
} else {
|
} else {
|
||||||
this.icon = path.join(__dirname, '/images/icon.png');
|
this.icon = path.join(__dirname, '/images/icon.png');
|
||||||
}
|
}
|
||||||
|
@ -47,6 +49,9 @@ export class TrayMain {
|
||||||
private handleHideEvent() {
|
private handleHideEvent() {
|
||||||
this.tray = new Tray(this.icon);
|
this.tray = new Tray(this.icon);
|
||||||
this.tray.setToolTip(this.appName);
|
this.tray.setToolTip(this.appName);
|
||||||
|
if (this.pressedIcon != null) {
|
||||||
|
this.tray.setPressedImage(this.pressedIcon);
|
||||||
|
}
|
||||||
|
|
||||||
this.tray.on('click', () => {
|
this.tray.on('click', () => {
|
||||||
if (this.windowMain.win.isVisible()) {
|
if (this.windowMain.win.isVisible()) {
|
||||||
|
|
Loading…
Reference in New Issue