fix menus to work on all platforms

This commit is contained in:
sparks-alec
2022-01-15 16:10:02 -05:00
parent b31e0af2b7
commit 8aa8021272
2 changed files with 115 additions and 117 deletions
+16 -117
View File
@@ -1,116 +1,11 @@
const { app, BrowserWindow, Menu, ipcMain } = require('electron');
const { app, BrowserWindow, Menu, ipcMain, nativeTheme } = require('electron');
const path = require('path');
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
// eslint-disable-next-line global-require
if (require('electron-squirrel-startup')) {
app.quit();
}
const isMac = process.platform === 'darwin';
let menu;
let menuObj;
let mainWindow;
const menuTemplate = [
isMac ? { role: 'appMenu' } : {},
{
label: 'File',
submenu: [
{
label: 'Clear Saved Data',
id: 'resetViews',
click: function (menuItem, window, event) {
mainWindow.webContents.send('resetViews');
},
},
{
label: 'Reload App',
role: 'reload',
},
{
type: 'separator',
},
isMac ? { role: 'close' } : { role: 'quit' },
],
},
{ role: 'editMenu' },
{
label: 'View',
submenu: [
{ role: 'togglefullscreen' },
{ type: 'separator' },
{
label: 'Arrangement 1',
accelerator: 'CommandOrControl+1',
id: 'window1',
enabled: true,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doSlots1');
},
},
{
label: 'Arrangement 2',
accelerator: 'CommandOrControl+2',
id: 'window2',
enabled: true,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doSlots2');
},
},
{
label: 'Arrangement 3',
accelerator: 'CommandOrControl+3',
id: 'window3',
enabled: true,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doSlots3');
},
},
{ type: 'separator' },
{ role: 'toggleDevTools' },
],
},
{
label: 'Device',
submenu: [
{
label: 'Search for Devices',
accelerator: 'CommandOrControl+F',
id: 'deviceSearch',
enabled: true,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doSearch');
},
},
{
type: 'separator',
},
{
label: 'Pinned',
type: 'checkbox',
checked: true,
accelerator: 'CommandOrControl+P',
id: 'devicePin',
enabled: false,
click: function (menuItem, window, event) {
mainWindow.webContents.send(
'setActiveDevicePinned',
menuItem.checked
);
},
},
{
label: 'Delete',
accelerator: 'CommandOrControl+Backspace',
id: 'deviceDelete',
enabled: false,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doDelete');
},
},
],
},
];
const menuTemplate = require('./src/menu');
const windowMac = {
width: 1500,
@@ -141,6 +36,9 @@ const windowWin = {
}
const createWindow = () => {
nativeTheme.themeSource = 'dark';
if(isMac){
mainWindow = new BrowserWindow(windowMac);
}else{
@@ -157,8 +55,9 @@ const createWindow = () => {
mainWindow.webContents.openDevTools();
}
menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
menuObj = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menuObj);
};
app.whenReady().then(() => {
@@ -176,21 +75,21 @@ app.on('window-all-closed', () => {
});
ipcMain.on('enableDeviceDropdown', (event, arg) => {
menu.getMenuItemById('devicePin').enabled = true;
menu.getMenuItemById('deviceDelete').enabled = true;
menuObj.getMenuItemById('devicePin').enabled = true;
menuObj.getMenuItemById('deviceDelete').enabled = true;
});
ipcMain.on('disableDeviceDropdown', (event, arg) => {
menu.getMenuItemById('devicePin').enabled = false;
menu.getMenuItemById('deviceDelete').enabled = false;
menuObj.getMenuItemById('devicePin').enabled = false;
menuObj.getMenuItemById('deviceDelete').enabled = false;
});
ipcMain.on('enableSearchAll', (event, arg) => {
menu.getMenuItemById('deviceSearch').enabled = true;
menuObj.getMenuItemById('deviceSearch').enabled = true;
});
ipcMain.on('disableSearchAll', (event, arg) => {
menu.getMenuItemById('deviceSearch').enabled = false;
menuObj.getMenuItemById('deviceSearch').enabled = false;
});
ipcMain.on('setDevicePin', (event, arg) => {
menu.getMenuItemById('devicePin').checked = arg;
menuObj.getMenuItemById('devicePin').checked = arg;
});
+99
View File
@@ -0,0 +1,99 @@
const isMac = process.platform === 'darwin';
//isMac && { role: 'appMenu' },
//isMac ? { role: 'close' } : { role: 'quit' }
module.exports = [
...(isMac ? [{ role: 'appMenu' }] : []),
{
label: 'File',
submenu: [
{
label: 'Clear Saved Data',
id: 'resetViews',
click: function (menuItem, window, event) {
mainWindow.webContents.send('resetViews');
}
},
{
label: 'Reload App',
role: 'reload'
},
{ type: 'separator' },
...(isMac ? [{ role: 'close' }] : [{ role: 'quit' }])
]
},
{ role: 'editMenu' },
{
label: 'View',
submenu: [
{ role: 'togglefullscreen' },
{ type: 'separator' },
{
label: 'Arrangement 1',
accelerator: 'CommandOrControl+1',
id: 'window1',
enabled: true,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doSlots1');
}
},
{
label: 'Arrangement 2',
accelerator: 'CommandOrControl+2',
id: 'window2',
enabled: true,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doSlots2');
}
},
{
label: 'Arrangement 3',
accelerator: 'CommandOrControl+3',
id: 'window3',
enabled: true,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doSlots3');
}
},
{ type: 'separator' },
{ role: 'toggleDevTools' }
]
},
{
label: 'Device',
submenu: [
{
label: 'Search for Devices',
accelerator: 'CommandOrControl+F',
id: 'deviceSearch',
enabled: true,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doSearch');
}
},
{ type: 'separator' },
{
label: 'Pinned',
type: 'checkbox',
checked: true,
accelerator: 'CommandOrControl+P',
id: 'devicePin',
enabled: false,
click: function (menuItem, window, event) {
mainWindow.webContents.send(
'setActiveDevicePinned',
menuItem.checked
);
}
},
{
label: 'Delete',
accelerator: 'CommandOrControl+Backspace',
id: 'deviceDelete',
enabled: false,
click: function (menuItem, window, event) {
mainWindow.webContents.send('doDelete');
}
}
]
}
];