chore: Custom menu

This commit is contained in:
Felix Rieseberg 2019-02-03 13:44:57 -08:00
parent ac84f4164e
commit ed1bd0a1e0
2 changed files with 152 additions and 67 deletions

View file

@ -28,7 +28,6 @@
]
},
"dependencies": {
"electron-default-menu": "^1.0.1",
"electron-squirrel-startup": "^1.0.0",
"fs-extra": "^7.0.1",
"update-electron-app": "^1.3.0"

View file

@ -1,8 +1,10 @@
const { app, shell, Menu, BrowserWindow } = require('electron')
const defaultMenu = require('electron-default-menu')
const { clearCaches } = require('./cache')
const { IPC_COMMANDS } = require('./constants')
const LINKS = {
homepage: 'https://www.felixrieseberg.com',
homepage: 'https://www.twitter.com/felixrieseberg',
repo: 'https://github.com/felixrieseberg/windows95',
credits: 'https://github.com/felixrieseberg/windows95/blob/master/CREDITS.md',
help: 'https://github.com/felixrieseberg/windows95/blob/master/HELP.md'
@ -17,74 +19,158 @@ function send (cmd) {
}
async function createMenu () {
const menu = defaultMenu(app, shell)
.map((item) => {
if (item.label === 'View') {
item.submenu = item.submenu.filter((subItem) => {
return subItem.label !== 'Reload'
})
}
if (item.label === 'Help') {
item.submenu = [
{
label: 'Author',
click() {
shell.openExternal(LINKS.homepage)
},
},
{
label: 'Learn More',
click() {
shell.openExternal(LINKS.repo)
},
},
{
type: 'separator'
},
{
label: 'Help',
click() {
shell.openExternal(LINKS.help)
}
},
{
label: 'Credits',
click() {
shell.openExternal(LINKS.credits)
}
const template = [
{
label: 'View',
submenu: [
{
label: 'Toggle Full Screen',
accelerator: (function () {
if (process.platform === 'darwin') { return 'Ctrl+Command+F' } else { return 'F11' }
})(),
click: function (_item, focusedWindow) {
if (focusedWindow) { focusedWindow.setFullScreen(!focusedWindow.isFullScreen()) }
}
]
}
},
{
label: 'Toggle Developer Tools',
accelerator: (function () {
if (process.platform === 'darwin') { return 'Alt+Command+I' } else { return 'Ctrl+Shift+I' }
})(),
click: function (_item, focusedWindow) {
if (focusedWindow) { focusedWindow.toggleDevTools() }
}
},
{
type: 'separator'
},
{
label: 'Toggle Emulator Info',
click: () => send(IPC_COMMANDS.TOGGLE_INFO)
}
]
},
{
label: 'Window',
role: 'window',
submenu: [
{
label: 'Minimize',
accelerator: 'CmdOrCtrl+M',
role: 'minimize'
},
{
label: 'Close',
accelerator: 'CmdOrCtrl+W',
role: 'close'
}
]
},
{
label: 'Machine',
submenu: [
{
label: 'Send Ctrl+Alt+Del',
click: () => send('ctrlaltdel')
},
{
label: 'Restart',
click: () => send(IPC_COMMANDS.MACHINE_RESTART)
},
{
type: 'separator'
},
{
label: 'Go to Disk Image',
click: () => send('disk-image')
}
]
},
{
label: 'Help',
role: 'help',
submenu: [
{
label: 'Author',
click: () => shell.openExternal(LINKS.homepage)
},
{
label: 'windows95 on GitHub',
click: () => shell.openExternal(LINKS.repo)
},
{
label: 'Help',
click: () => shell.openExternal(LINKS.help)
},
{
type: 'separator'
},
{
label: 'Troubleshooting',
submenu: [
{
label: 'Clear Cache and Restart',
async click () {
await clearCaches()
return item
})
.filter((item) => {
return item.label !== 'Edit'
app.relaunch()
app.quit()
}
}
]
}
]
}
]
if (process.platform === 'darwin') {
template.unshift({
label: 'windows95',
submenu: [
{
label: 'About windows95',
role: 'about'
},
{
type: 'separator'
},
{
label: 'Services',
role: 'services',
submenu: []
},
{
type: 'separator'
},
{
label: 'Hide windows95',
accelerator: 'Command+H',
role: 'hide'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
role: 'hideothers'
},
{
label: 'Show All',
role: 'unhide'
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Command+Q',
click () {
app.quit()
}
}
]
})
}
menu.splice(1, 0, {
label: 'Machine',
submenu: [
{
label: 'Send Ctrl+Alt+Del',
click: () => send('ctrlaltdel')
},
{
label: 'Restart',
click: () => send('restart')
},
{
type: 'separator'
},
{
label: 'Go to Disk Image',
click: () => send('disk-image')
}
]
})
Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
}
module.exports = {