From 2d1a84ec50e05ee1afd28f9a3298e718a5d5bd6b Mon Sep 17 00:00:00 2001 From: "i.mirdzhamolov" Date: Sun, 26 Apr 2020 17:20:21 +0300 Subject: [PATCH] feat: change for AppController * set `isActive` to true by default * create `updateState()` * use `nativeImage.createFromPath()` for resolve icons path --- server/AppController.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/server/AppController.js b/server/AppController.js index 27bc62c..dcfe2f0 100644 --- a/server/AppController.js +++ b/server/AppController.js @@ -1,4 +1,4 @@ -const { Tray, Menu, nativeImage, NativeImage, MenuItem, nativeTheme } = require('electron'); +const { Tray, Menu, nativeImage, nativeTheme } = require('electron'); const path = require('path'); /** @@ -26,13 +26,10 @@ class AppController { /** @param {(BrowserWindowController)} browserWindowController */ constructor(browserWindowController) { - this.isActive = false; + this.isActive = true; this.theme = AppController.getCurrentThemeName(); this.tray = new Tray(nativeImage.createEmpty()); - this.setTrayImage(); - this.setTrayTooltip(); - this.handleActivateMenuItemClick = this.handleActivateMenuItemClick.bind(this); this.handleQuitClick = this.handleQuitClick.bind(this); this.handleThemeChange = this.handleThemeChange.bind(this); @@ -51,6 +48,8 @@ class AppController { ])); this.browserWindowController = browserWindowController; + + this.updateState(); } start() { @@ -137,17 +136,10 @@ class AppController { */ getImagePath(theme) { const pathToImage = this.isActive ? `assets/${theme}/icon-active.png` : `assets/${theme}/icon.png`; - - return path.join(process.cwd(), pathToImage); + return nativeImage.createFromPath(path.join(__dirname, `../${pathToImage}`)); } - /** - * @param {Electron.MenuItem} menuItem - * @private - */ - handleActivateMenuItemClick(menuItem) { - this.isActive = menuItem.checked; - + updateState() { this.setTrayImage(); this.setTrayTooltip(); @@ -158,6 +150,15 @@ class AppController { } } + /** + * @param {Electron.MenuItem} menuItem + * @private + */ + handleActivateMenuItemClick(menuItem) { + this.isActive = menuItem.checked; + this.updateState(); + } + /** @private */ handleQuitClick() { this.quitHandler();