mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix menu bar for macOS
This commit is contained in:
+42
-35
@@ -175,36 +175,39 @@ const createMainWindow = () => {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
})
|
})
|
||||||
|
|
||||||
// tray
|
if (process.platform !== 'darwin') {
|
||||||
const trayIconPath = path.join(
|
// tray
|
||||||
__dirname,
|
const trayIconPath = path.join(
|
||||||
'..',
|
__dirname,
|
||||||
isDev ? 'public' : 'build',
|
'..',
|
||||||
'electron-tray-icon.png'
|
isDev ? 'public' : 'build',
|
||||||
);
|
'electron-tray-icon.png'
|
||||||
const tray = new Tray(trayIconPath);
|
);
|
||||||
tray.setToolTip('plebchan');
|
const tray = new Tray(trayIconPath);
|
||||||
const trayMenu = Menu.buildFromTemplate([
|
tray.setToolTip('plebchan');
|
||||||
{
|
const trayMenu = Menu.buildFromTemplate([
|
||||||
label: 'Open plebchan',
|
{
|
||||||
click: () => {
|
label: 'Open plebchan',
|
||||||
mainWindow.show();
|
click: () => {
|
||||||
|
mainWindow.show();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
label: 'Quit plebchan',
|
||||||
label: 'Quit plebchan',
|
click: () => {
|
||||||
click: () => {
|
mainWindow.destroy();
|
||||||
mainWindow.destroy();
|
app.quit();
|
||||||
app.quit();
|
},
|
||||||
},
|
},
|
||||||
},
|
]);
|
||||||
]);
|
tray.setContextMenu(trayMenu);
|
||||||
tray.setContextMenu(trayMenu);
|
|
||||||
|
// show/hide on tray right click
|
||||||
|
tray.on('right-click', () => {
|
||||||
|
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// show/hide on tray right click
|
|
||||||
tray.on('right-click', () => {
|
|
||||||
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
// close to tray
|
// close to tray
|
||||||
if (!isDev) {
|
if (!isDev) {
|
||||||
@@ -226,24 +229,28 @@ const createMainWindow = () => {
|
|||||||
const originalAppMenuWithoutHelp = Menu.getApplicationMenu()?.items.filter(
|
const originalAppMenuWithoutHelp = Menu.getApplicationMenu()?.items.filter(
|
||||||
(item) => item.role !== 'help'
|
(item) => item.role !== 'help'
|
||||||
);
|
);
|
||||||
const appMenuBack = new MenuItem({
|
const appMenu = new Menu();
|
||||||
|
appMenu.append(new MenuItem({role: 'appMenu'}));
|
||||||
|
appMenu.append(new MenuItem({
|
||||||
label: '←',
|
label: '←',
|
||||||
enabled: mainWindow?.webContents?.canGoBack(),
|
enabled: mainWindow?.webContents?.canGoBack(),
|
||||||
click: () => mainWindow?.webContents?.goBack(),
|
click: () => mainWindow?.webContents?.goBack(),
|
||||||
});
|
}));
|
||||||
const appMenuForward = new MenuItem({
|
appMenu.append(new MenuItem({
|
||||||
label: '→',
|
label: '→',
|
||||||
enabled: mainWindow?.webContents?.canGoForward(),
|
enabled: mainWindow?.webContents?.canGoForward(),
|
||||||
click: () => mainWindow?.webContents?.goForward(),
|
click: () => mainWindow?.webContents?.goForward(),
|
||||||
});
|
}));
|
||||||
const appMenuReload = new MenuItem({
|
appMenu.append(new MenuItem({
|
||||||
label: '⟳',
|
label: '⟳',
|
||||||
role: 'reload',
|
role: 'reload',
|
||||||
click: () => mainWindow?.webContents?.reload(),
|
click: () => mainWindow?.webContents?.reload(),
|
||||||
|
}));
|
||||||
|
originalAppMenuWithoutHelp.forEach(item => {
|
||||||
|
appMenu.append(item);
|
||||||
});
|
});
|
||||||
const appMenu = [appMenuBack, appMenuForward, appMenuReload, ...originalAppMenuWithoutHelp];
|
Menu.setApplicationMenu(appMenu);
|
||||||
Menu.setApplicationMenu(Menu.buildFromTemplate(appMenu));
|
|
||||||
};
|
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
createMainWindow();
|
createMainWindow();
|
||||||
|
|||||||
Reference in New Issue
Block a user