Skip to content

Commit

Permalink
feat: Add additional menu items
Browse files Browse the repository at this point in the history
This adds in the edit/view/window/help menus as well
as adds in additional menu items for the main application.
This allows shortcuts like cmd+q to quit the application on mac.

ref: https://github.com/electron/electron/blob/main/docs/api/menu.md#examples

Signed-off-by: Brad Beam <[email protected]>
  • Loading branch information
bradbeam committed Oct 27, 2024
1 parent 208d62c commit e8e47ed
Showing 1 changed file with 98 additions and 19 deletions.
117 changes: 98 additions & 19 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,27 +405,106 @@ app.on('ready', async () => {
app.setAppUserModelId(process.execPath);
createWindow();

if (process.platform === 'darwin') {
// Create our menu entries so that we can use MAC shortcuts like copy & paste
Menu.setApplicationMenu(
Menu.buildFromTemplate([
{
label: 'Edit',
const isMac = process.platform === 'darwin'

Check failure on line 408 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

const template = [
// { role: 'appMenu' }
...(isMac
? [{

Check failure on line 413 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎··········`
label: app.name,

Check failure on line 414 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
submenu: [

Check failure on line 415 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Replace `··········` with `············`
{ role: 'undo' },
{ role: 'redo' },
{ role: 'about' },

Check failure on line 416 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
{ type: 'separator' },

Check failure on line 417 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Replace `············` with `··············`
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'delete' },
{ role: 'selectall' },
],
},
])
);
}
{ role: 'services' },

Check failure on line 418 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
{ type: 'separator' },

Check failure on line 419 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
{ role: 'hide' },

Check failure on line 420 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
{ role: 'hideOthers' },

Check failure on line 421 in app/main.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
]
}]
: []),
// { role: 'editMenu' }
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac
? [
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Speech',
submenu: [
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
]
: [
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
])
]
},
// { role: 'viewMenu' }
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
// { role: 'windowMenu' }
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
...(isMac
? [
{ type: 'separator' },
{ role: 'front' },
{ type: 'separator' },
{ role: 'window' }
]
: [
{ role: 'close' }
])
]
},
{
role: 'help',
submenu: [
{
label: 'Learn More',
click: async () => {
const { shell } = require('electron')
await shell.openExternal('https://github.com/Xzandro/sw-exporter')
}
}
]
}
]

const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

storage.getAll(async (error, data) => {
if (error) throw error;
Expand Down

0 comments on commit e8e47ed

Please sign in to comment.