2016-10-30 10:57:12 +00:00
|
|
|
const electron = require('electron'); // eslint-disable-line
|
|
|
|
const defaultMenu = require('electron-default-menu');
|
|
|
|
|
|
|
|
const Menu = electron.Menu;
|
|
|
|
const dialog = electron.dialog;
|
|
|
|
|
|
|
|
const homepage = 'https://github.com/mifi/lossless-cut';
|
2018-02-17 14:15:30 +00:00
|
|
|
const releasesPage = 'https://github.com/mifi/lossless-cut/releases';
|
2016-10-30 10:57:12 +00:00
|
|
|
|
2018-02-17 14:15:30 +00:00
|
|
|
module.exports = (app, mainWindow, newVersion) => {
|
2016-10-30 10:57:12 +00:00
|
|
|
const menu = defaultMenu(app, electron.shell);
|
|
|
|
|
2016-11-05 20:22:31 +00:00
|
|
|
const editMenuIndex = menu.findIndex(item => item.Label === 'Edit');
|
|
|
|
if (editMenuIndex >= 0) menu.splice(editMenuIndex, 1);
|
2016-10-30 10:57:12 +00:00
|
|
|
|
2016-11-05 20:22:31 +00:00
|
|
|
menu.splice((process.platform === 'darwin' ? 1 : 0), 0, {
|
2016-10-30 10:57:12 +00:00
|
|
|
label: 'File',
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: 'Open',
|
|
|
|
accelerator: 'CmdOrCtrl+O',
|
|
|
|
click() {
|
2016-11-08 19:36:44 +00:00
|
|
|
dialog.showOpenDialog({ properties: ['openFile'] }, (filePaths) => {
|
|
|
|
mainWindow.webContents.send('file-opened', filePaths);
|
2016-10-30 10:57:12 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2016-11-05 20:22:31 +00:00
|
|
|
const helpIndex = menu.findIndex(item => item.role === 'help');
|
|
|
|
if (helpIndex >= 0) {
|
|
|
|
menu.splice(helpIndex, 1, {
|
|
|
|
role: 'help',
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: 'Learn More',
|
|
|
|
click() { electron.shell.openExternal(homepage); },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
2016-10-30 10:57:12 +00:00
|
|
|
|
2018-02-17 14:15:30 +00:00
|
|
|
if (newVersion) {
|
|
|
|
menu.push({
|
|
|
|
label: 'New version!',
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: `Download ${newVersion}`,
|
|
|
|
click() { electron.shell.openExternal(releasesPage); },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-30 10:57:12 +00:00
|
|
|
Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
|
|
|
|
};
|