Skip to content

Commit

Permalink
fix(windowManager): fixed dark/light mode icon swap bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamuAbba committed Mar 12, 2024
1 parent f6b4a57 commit 172a0ba
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion electron/windowManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, BrowserWindow, ipcMain, Menu } from 'electron';
import { app, BrowserWindow, ipcMain, Menu, nativeImage, Tray } from 'electron';
import { warn } from 'electron-log';
import windowState from 'electron-window-state';
import { join } from 'path';
Expand All @@ -10,6 +10,7 @@ import { initTapdProxy } from './tapd/tapdProxyServer';

class WindowManager {
mainWindow: BrowserWindow | null = null;
tray: Tray | null = null;

start() {
app.on('ready', async () => {
Expand Down Expand Up @@ -45,6 +46,12 @@ class WindowManager {
enableRemoteModule: true,
},
});

// create App system tray icon with context menus
if (!this.tray) {
this.createAppTray();
}

this.mainWindow.setMenuBarVisibility(false);

if (IS_DEV) {
Expand Down Expand Up @@ -92,6 +99,64 @@ class WindowManager {
this.createMainWindow();
}
}

/**
* Creates App tray icon with a menu of options
* to `Hide/Show` the app window
* and also `quite` the running app instance
* @returns void
*/
createAppTray() {
const trayIcon = join(APP_ROOT, 'assets', 'icon.png');
this.tray = new Tray(nativeImage.createFromPath(trayIcon));
this.tray.setIgnoreDoubleClickEvents(true);

/**
* `hides` polar windows
*/
const handleOnHideClick = () => {
if (process.platform !== 'darwin') {
app.dock?.hide();
}
this.mainWindow?.setSkipTaskbar(true);
this.mainWindow?.hide();
};

/**
* `shows` polar window
*/
const handleOnShowClick = () => {
if (process.platform !== 'darwin') {
app.dock?.show();
}
this.mainWindow?.setSkipTaskbar(false);
this.mainWindow?.show();
};

/**
* closes all windows and quits the app
*/
const handleQuitClick = () => {
app.quit();
};

const contextMenu: Menu = Menu.buildFromTemplate([
{
label: 'Minimize to tray',
click: handleOnHideClick,
},
{
label: 'Show window',
click: handleOnShowClick,
},
{
label: 'Quit Polar',
click: handleQuitClick,
},
]);
this.tray.setToolTip('Polar');
this.tray.setContextMenu(contextMenu);
}
}

export default WindowManager;

0 comments on commit 172a0ba

Please sign in to comment.