1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 10:22:31 +01:00
lossless-cut/public/menu.js

398 lines
12 KiB
JavaScript
Raw Normal View History

2022-11-23 10:00:00 +01:00
const electron = require('electron');
2023-02-18 16:11:17 +01:00
const { t } = require('i18next');
2016-10-30 11:57:12 +01:00
2023-02-06 07:33:02 +01:00
// menu-safe i18n.t:
// https://github.com/mifi/lossless-cut/issues/1456
2023-02-18 16:11:17 +01:00
const esc = (val) => val.replace(/&/g, '&&');
2023-02-06 07:33:02 +01:00
2018-09-30 22:08:36 +02:00
const { Menu } = electron;
2016-10-30 11:57:12 +01:00
const { homepage, getReleaseUrl, licensesPage } = require('./constants');
2016-10-30 11:57:12 +01:00
module.exports = ({ app, mainWindow, newVersion, isStoreBuild }) => {
const menu = [
...(process.platform === 'darwin' ? [{ role: 'appMenu' }] : []),
2016-10-30 11:57:12 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('File')),
submenu: [
{
2023-02-18 16:11:17 +01:00
label: esc(t('Open')),
accelerator: 'CmdOrCtrl+O',
async click() {
mainWindow.webContents.send('openFilesDialog');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Close')),
accelerator: 'CmdOrCtrl+W',
async click() {
2022-02-23 12:43:19 +01:00
mainWindow.webContents.send('closeCurrentFile');
},
},
2021-08-28 16:47:43 +02:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Close batch')),
2021-08-28 16:47:43 +02:00
async click() {
2022-02-23 12:43:19 +01:00
mainWindow.webContents.send('closeBatchFiles');
2021-08-28 16:47:43 +02:00
},
},
{ type: 'separator' },
{
2023-02-18 16:11:17 +01:00
label: esc(t('Import project (LLC)...')),
click() {
mainWindow.webContents.send('importEdlFile', 'llc');
},
},
2020-12-11 16:15:35 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Export project (LLC)...')),
2020-12-11 16:15:35 +01:00
click() {
mainWindow.webContents.send('exportEdlFile', 'llc');
2020-12-11 16:15:35 +01:00
},
},
2020-11-18 21:24:20 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Import project')),
2020-11-18 21:24:20 +01:00
submenu: [
{
2023-02-18 16:11:17 +01:00
label: esc(t('Times in seconds (CSV)')),
click() {
mainWindow.webContents.send('importEdlFile', 'csv');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Frame numbers (CSV)')),
click() {
mainWindow.webContents.send('importEdlFile', 'csv-frames');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('EDL (MPlayer)')),
click() {
mainWindow.webContents.send('importEdlFile', 'mplayer');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Text chapters / YouTube')),
click() {
mainWindow.webContents.send('importEdlFile', 'youtube');
},
},
2020-11-18 21:24:20 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('DaVinci Resolve / Final Cut Pro XML')),
2020-11-18 21:24:20 +01:00
click() {
mainWindow.webContents.send('importEdlFile', 'xmeml');
},
},
2022-07-17 23:36:57 +02:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Final Cut Pro FCPX / FCPXML')),
2022-07-17 23:36:57 +02:00
click() {
mainWindow.webContents.send('importEdlFile', 'fcpxml');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('CUE sheet file')),
click() {
mainWindow.webContents.send('importEdlFile', 'cue');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('PotPlayer Bookmarks (.pbf)')),
click() {
mainWindow.webContents.send('importEdlFile', 'pbf');
},
},
2020-11-18 21:24:20 +01:00
],
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Export project')),
submenu: [
{
2023-02-18 16:11:17 +01:00
label: esc(t('Times in seconds (CSV)')),
click() {
mainWindow.webContents.send('exportEdlFile', 'csv');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Timestamps (CSV)')),
click() {
2020-12-15 00:49:08 +01:00
mainWindow.webContents.send('exportEdlFile', 'csv-human');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Frame numbers (CSV)')),
click() {
mainWindow.webContents.send('exportEdlFile', 'csv-frames');
},
},
2020-12-15 00:49:08 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Timestamps (TSV/TXT)')),
2020-12-15 00:49:08 +01:00
click() {
mainWindow.webContents.send('exportEdlFile', 'tsv-human');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Start times as YouTube Chapters')),
click() {
mainWindow.webContents.send('exportEdlYouTube');
},
},
],
},
{ type: 'separator' },
{
2023-02-18 16:11:17 +01:00
label: esc(t('Convert to supported format')),
click() {
mainWindow.webContents.send('html5ify');
},
},
2020-11-22 23:53:04 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Fix incorrect duration')),
2020-11-22 23:53:04 +01:00
click() {
mainWindow.webContents.send('fixInvalidDuration');
},
},
{ type: 'separator' },
2020-12-11 16:15:35 +01:00
{ type: 'separator' },
{
2023-02-18 16:11:17 +01:00
label: esc(t('Settings')),
accelerator: 'CmdOrCtrl+,',
click() {
2022-02-23 12:43:19 +01:00
mainWindow.webContents.send('toggleSettings');
},
},
2022-08-12 11:37:39 +02:00
// Due to Apple Review Guidelines, we cannot include an Exit menu item here
// Apple has their own Quit from the app menu
...(process.platform !== 'darwin' ? [
{ type: 'separator' },
{
2023-02-18 16:11:17 +01:00
label: esc(t('Exit')),
2022-08-12 11:37:39 +02:00
click() {
app.quit();
},
},
2022-08-12 11:37:39 +02:00
] : []),
],
2020-02-20 11:41:01 +01:00
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Edit')),
submenu: [
// https://github.com/mifi/lossless-cut/issues/610
// https://github.com/mifi/lossless-cut/issues/1183
2023-02-18 16:11:17 +01:00
{ role: 'undo', label: esc(t('Undo')) },
{ role: 'redo', label: esc(t('Redo')) },
{ type: 'separator' },
2023-02-18 16:11:17 +01:00
{ role: 'cut', label: esc(t('Cut')) },
{ role: 'copy', label: esc(t('Copy')) },
{ role: 'paste', label: esc(t('Paste')) },
{ role: 'selectall', label: esc(t('Select All')) },
{ type: 'separator' },
{
2023-02-18 16:11:17 +01:00
label: esc(t('Segments')),
submenu: [
2020-12-14 12:29:17 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Clear all segments')),
2020-12-14 12:29:17 +01:00
click() {
mainWindow.webContents.send('clearSegments');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Reorder segments by start time')),
click() {
mainWindow.webContents.send('reorderSegsByStartTime');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Create num segments')),
click() {
mainWindow.webContents.send('createNumSegments');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Create fixed duration segments')),
click() {
mainWindow.webContents.send('createFixedDurationSegments');
},
},
2022-05-24 07:31:48 +02:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Create random segments')),
2022-05-24 07:31:48 +02:00
click() {
mainWindow.webContents.send('createRandomSegments');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Invert all segments on timeline')),
click() {
mainWindow.webContents.send('invertAllSegments');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Fill gaps between segments')),
click() {
mainWindow.webContents.send('fillSegmentsGaps');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Combine overlapping segments')),
click() {
mainWindow.webContents.send('combineOverlappingSegments');
},
},
2022-02-18 07:34:20 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Shuffle segments order')),
2022-02-18 07:34:20 +01:00
click() {
mainWindow.webContents.send('shuffleSegments');
},
},
2022-03-01 16:10:25 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Shift all segments on timeline')),
2022-03-01 16:10:25 +01:00
click() {
mainWindow.webContents.send('shiftAllSegmentTimes');
},
},
2023-02-05 12:08:28 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Align segment times to keyframes')),
2023-02-05 12:08:28 +01:00
click() {
mainWindow.webContents.send('alignSegmentTimesToKeyframes');
},
},
],
},
2020-12-11 16:15:35 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Tracks')),
2020-12-11 16:15:35 +01:00
submenu: [
{
2023-02-18 16:11:17 +01:00
label: esc(t('Extract all tracks')),
2020-12-11 16:15:35 +01:00
click() {
2022-02-23 12:43:19 +01:00
mainWindow.webContents.send('extractAllStreams');
2020-12-11 16:15:35 +01:00
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Edit tracks / metadata tags')),
2020-12-11 16:15:35 +01:00
click() {
mainWindow.webContents.send('showStreamsSelector');
},
},
],
},
],
2020-02-20 11:41:01 +01:00
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('View')),
submenu: [
2023-02-18 16:11:17 +01:00
{ role: 'togglefullscreen', label: esc(t('Toggle Full Screen')) },
],
},
2020-02-20 11:41:01 +01:00
2020-03-26 14:31:11 +01:00
// On Windows the windowMenu has a close Ctrl+W which clashes with File->Close shortcut
...(process.platform === 'darwin'
2023-02-18 16:11:17 +01:00
? [{ role: 'windowMenu', label: esc(t('Window')) }]
2020-03-26 14:31:11 +01:00
: [{
2023-02-18 16:11:17 +01:00
label: esc(t('Window')),
submenu: [{ role: 'minimize', label: esc(t('Minimize')) }],
2020-03-26 14:31:11 +01:00
}]
),
2016-10-30 11:57:12 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Tools')),
submenu: [
2022-02-23 14:16:02 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Merge/concatenate files')),
2022-02-23 14:16:02 +01:00
click() {
mainWindow.webContents.send('concatCurrentBatch');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Set custom start offset/timecode')),
click() {
2022-02-23 14:16:02 +01:00
mainWindow.webContents.send('askSetStartTimeOffset');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Detect black scenes')),
click() {
mainWindow.webContents.send('detectBlackScenes');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Detect silent scenes')),
click() {
mainWindow.webContents.send('detectSilentScenes');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Detect scene changes')),
click() {
mainWindow.webContents.send('detectSceneChanges');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Create segments from keyframes')),
click() {
mainWindow.webContents.send('createSegmentsFromKeyframes');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Last ffmpeg commands')),
click() { mainWindow.webContents.send('toggleLastCommands'); },
},
{ type: 'separator' },
2023-02-18 16:11:17 +01:00
{ role: 'toggleDevTools', label: esc(t('Toggle Developer Tools')) },
],
},
{
role: 'help',
2023-02-18 16:11:17 +01:00
label: esc(t('Help')),
submenu: [
{
2023-02-18 16:11:17 +01:00
label: esc(t('How to use')),
click() { electron.shell.openExternal('https://mifi.no/losslesscut/usage'); },
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('FAQ')),
click() { electron.shell.openExternal('https://mifi.no/losslesscut/faq'); },
},
2021-11-15 08:32:27 +01:00
{
2023-02-18 16:11:17 +01:00
label: esc(t('Troubleshooting')),
click() { electron.shell.openExternal('https://mifi.no/losslesscut/troubleshooting'); },
2021-11-15 08:32:27 +01:00
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Learn More')),
click() { electron.shell.openExternal(homepage); },
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Licenses')),
click() { electron.shell.openExternal(licensesPage); },
},
{ type: 'separator' },
{
2023-02-18 16:11:17 +01:00
label: esc(t('Keyboard & mouse shortcuts')),
click() {
mainWindow.webContents.send('toggleKeyboardShortcuts');
},
},
{
2023-02-18 16:11:17 +01:00
label: esc(t('Report an error')),
click() { mainWindow.webContents.send('openSendReportDialog'); },
},
2023-03-11 14:11:54 +01:00
...(process.platform !== 'darwin' ? [{ role: 'about' }] : []),
],
},
];
2016-10-30 11:57:12 +01:00
if (!isStoreBuild && newVersion) {
2018-02-17 15:15:30 +01:00
menu.push({
2023-02-18 16:11:17 +01:00
label: esc(t('New version!')),
2018-02-17 15:15:30 +01:00
submenu: [
{
2023-02-18 16:11:17 +01:00
label: esc(t('Download {{version}}', { version: newVersion })),
click() { electron.shell.openExternal(getReleaseUrl(newVersion)); },
2018-02-17 15:15:30 +01:00
},
],
});
}
2016-10-30 11:57:12 +01:00
Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
};