windows95/src/menu.js

93 lines
2 KiB
JavaScript
Raw Normal View History

2018-08-25 08:01:33 +02:00
const { app, shell, Menu, BrowserWindow } = require('electron')
2018-08-23 07:03:28 +02:00
const defaultMenu = require('electron-default-menu')
2018-08-27 17:20:51 +02:00
const LINKS = {
homepage: 'https://www.felixrieseberg.com',
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'
}
2018-08-25 08:01:33 +02:00
function send (cmd) {
const windows = BrowserWindow.getAllWindows()
if (windows[0]) {
windows[0].webContents.send(cmd)
}
}
2018-08-23 07:25:17 +02:00
async function createMenu () {
const menu = defaultMenu(app, shell)
2018-08-25 08:01:33 +02:00
.map((item) => {
if (item.label === 'View') {
item.submenu = item.submenu.filter((subItem) => {
return subItem.label !== 'Reload'
})
}
2018-08-27 17:20:51 +02:00
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)
}
}
]
}
2018-08-25 08:01:33 +02:00
return item
})
.filter((item) => {
return item.label !== 'Edit'
})
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')
}
]
})
2018-08-23 07:03:28 +02:00
2018-08-23 07:25:17 +02:00
Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
2018-08-23 07:03:28 +02:00
}
module.exports = {
createMenu
}