fix menubar icon size in macOS (#360)

add support for MacOS theme (light/dark)
This commit is contained in:
Mario Dian 2023-06-20 14:23:24 +08:00 committed by GitHub
parent 6db0decdb9
commit c7a355b407
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 12 deletions

View file

@ -5,24 +5,21 @@ const isDev = require('electron-is-dev');
const { autoUpdater } = require('electron-updater');
let win = null;
const instanceLock = app.requestSingleInstanceLock();
const isMacOS = process.platform === 'darwin';
if (require('electron-squirrel-startup')) app.quit();
const PORT = isDev ? '5173' : '51735';
const ICON = 'icon-rounded.png';
const ICON_TEMPLATE = 'iconTemplate.png';
function createWindow() {
let iconPath = '';
if (isDev) {
iconPath = path.join(__dirname, '../public/icon-rounded.png');
} else {
iconPath = path.join(__dirname, '../dist/icon-rounded.png');
}
autoUpdater.checkForUpdatesAndNotify();
win = new BrowserWindow({
autoHideMenuBar: true,
show: false,
icon: iconPath,
icon: assetPath(ICON),
});
createTray(win);
@ -41,12 +38,16 @@ function createWindow() {
return win;
}
const assetPath = (asset) => {
return path.join(
__dirname,
isDev ? `../public/${asset}` : `../dist/${asset}`
)
}
const createTray = (window) => {
const tray = new Tray(
path.join(
__dirname,
isDev ? '../public/icon-rounded.png' : '../dist/icon-rounded.png'
)
assetPath(!isMacOS ? ICON : ICON_TEMPLATE)
);
const contextMenu = Menu.buildFromTemplate([
{
@ -76,7 +77,7 @@ const createTray = (window) => {
};
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
if (!isMacOS) {
app.quit();
}
});

BIN
public/iconTemplate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
public/iconTemplate@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
public/iconTemplate@3x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB