lossless-cut/src/menu.js

98 wiersze
2.3 KiB
JavaScript
Czysty Zwykły widok Historia

2016-10-30 10:57:12 +00:00
const electron = require('electron'); // eslint-disable-line
const defaultMenu = require('electron-default-menu');
2018-09-30 20:08:36 +00:00
const { Menu } = electron;
const { dialog } = electron;
2016-10-30 10:57:12 +00:00
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);
2018-09-24 22:19:57 +00:00
const fileMenu = {
2016-10-30 10:57:12 +00:00
label: 'File',
submenu: [
{
label: 'Open',
accelerator: 'CmdOrCtrl+O',
click() {
dialog.showOpenDialog({ properties: ['openFile'] }, (filePaths) => {
mainWindow.webContents.send('file-opened', filePaths);
2016-10-30 10:57:12 +00:00
});
},
},
{
label: 'Convert to friendly format (fast)',
click() {
mainWindow.webContents.send('html5ify', false);
},
},
{
label: 'Convert to friendly codec (slow)',
click() {
mainWindow.webContents.send('html5ify', true);
},
},
2019-01-28 02:23:05 +00:00
{
label: 'Extract all streams',
click() {
mainWindow.webContents.send('extract-all-streams', false);
},
},
2019-01-12 17:43:18 +00:00
{
2019-01-28 11:50:21 +00:00
label: 'Set custom start offset/timecode',
2019-01-12 17:43:18 +00:00
click() {
mainWindow.webContents.send('set-start-offset', true);
},
},
2018-06-24 18:31:10 +00:00
{
label: 'Exit',
click() {
app.quit();
},
},
2016-10-30 10:57:12 +00:00
],
2018-09-24 22:19:57 +00:00
};
menu.splice((process.platform === 'darwin' ? 1 : 0), 0, fileMenu);
2016-10-30 10:57:12 +00:00
const helpIndex = menu.findIndex(item => item.role === 'help');
if (helpIndex >= 0) {
menu.splice(helpIndex, 1, {
label: 'Tools',
submenu: [
{
label: 'Merge files',
click() {
mainWindow.webContents.send('show-merge-dialog', true);
},
},
],
},
{
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));
};