Skip to content

Commit

Permalink
feat: change for AppController
Browse files Browse the repository at this point in the history
* set `isActive` to true by default
* create `updateState()`
* use `nativeImage.createFromPath()` for resolve icons path
  • Loading branch information
imirdzhamolov committed Apr 26, 2020
1 parent 51a1767 commit 2d1a84e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions server/AppController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Tray, Menu, nativeImage, NativeImage, MenuItem, nativeTheme } = require('electron');
const { Tray, Menu, nativeImage, nativeTheme } = require('electron');
const path = require('path');

/**
Expand Down Expand Up @@ -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);
Expand All @@ -51,6 +48,8 @@ class AppController {
]));

this.browserWindowController = browserWindowController;

this.updateState();
}

start() {
Expand Down Expand Up @@ -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();

Expand All @@ -158,6 +150,15 @@ class AppController {
}
}

/**
* @param {Electron.MenuItem} menuItem
* @private
*/
handleActivateMenuItemClick(menuItem) {
this.isActive = menuItem.checked;
this.updateState();
}

/** @private */
handleQuitClick() {
this.quitHandler();
Expand Down

0 comments on commit 2d1a84e

Please sign in to comment.