By default, only a single running instance of LosslessCut is allowed. If you start a new LosslessCut instance from the command line, it will instead pass the list of files onto the already running instance. You can override this behavior by passing `--allow-multiple-instances` via the command line. Running multiple instances is experimental.
// On macOS, the system enforces single instance automatically when users try to open a second instance of your app in Finder, and the open-file and open-url events will be emitted for that.
// However when users start your app in command line, the system's single instance mechanism will be bypassed, and you have to use this method to ensure single instance.
// This can be tested with one terminal: npx electron .
// and another terminal: npx electron . path/to/file.mp4
app.on('second-instance',(event,commandLine)=>{
// Someone tried to run a second instance, we should focus our window.
if(mainWindow){
if(mainWindow.isMinimized())mainWindow.restore();
mainWindow.focus();
}
constargv=parseCliArgs();
logger.info('CLI arguments',argv);
// Only if no files to open already (open-file might have already added some files)
.catch(err=>logger.error('Failed to add extension',err));
}
app.on('activate',()=>{
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if(mainWindow===null){
createWindow();
}
});
updateMenu();
ipcMain.on('renderer-ready',()=>{
rendererReady=true;
if(filesToOpen.length>0)openFiles(filesToOpen);
});
if(!process.windowsStore&&!process.mas){
newVersion=awaitcheckNewVersion();
// newVersion = '1.2.3';
if(newVersion)updateMenu();
}
});
// Mac OS open with LosslessCut
// Emitted when the user wants to open a file with the application. The open-file event is usually emitted when the application is already open and the OS wants to reuse the application to open the file.
app.on('open-file',(event,path)=>{
if(rendererReady)openFiles([path]);
elsefilesToOpen=[path];
event.preventDefault();// recommended in docs https://www.electronjs.org/docs/latest/api/app#event-open-file-macos
});
// Quit when all windows are closed.
app.on('window-all-closed',()=>{
app.quit();
});
ipcMain.on('setAskBeforeClose',(e,val)=>{
askBeforeClose=val;
});
app.on('activate',()=>{
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if(mainWindow===null){
createWindow();
}
});
ipcMain.on('setLanguage',(e,language)=>{
i18n.changeLanguage(language).then(()=>updateMenu()).catch((err)=>logger.error('Failed to set language',err));
});
ipcMain.on('renderer-ready',()=>{
rendererReady=true;
if(filesToOpen.length>0)openFiles(filesToOpen);
});
// Mac OS open with LosslessCut
// Emitted when the user wants to open a file with the application. The open-file event is usually emitted when the application is already open and the OS wants to reuse the application to open the file.
app.on('open-file',(event,path)=>{
openFilesEventually([path]);
event.preventDefault();// recommended in docs https://www.electronjs.org/docs/latest/api/app#event-open-file-macos
});
ipcMain.on('setAskBeforeClose',(e,val)=>{
askBeforeClose=val;
});
ipcMain.on('setLanguage',(e,language)=>{
i18n.changeLanguage(language).then(()=>updateMenu()).catch((err)=>logger.error('Failed to set language',err));