2016-10-30 11:57:12 +01:00
|
|
|
const electron = require('electron'); // eslint-disable-line
|
2016-11-21 19:05:19 +01:00
|
|
|
const isDev = require('electron-is-dev');
|
2016-10-30 11:57:12 +01:00
|
|
|
|
|
|
|
const menu = require('./menu');
|
|
|
|
|
2018-02-17 15:15:30 +01:00
|
|
|
const { checkNewVersion } = require('./update-checker');
|
|
|
|
|
2018-09-30 22:08:36 +02:00
|
|
|
const { app } = electron;
|
|
|
|
const { BrowserWindow } = electron;
|
2016-10-30 11:57:12 +01:00
|
|
|
|
2020-02-11 15:16:03 +01:00
|
|
|
app.name = 'LosslessCut';
|
2016-11-05 21:22:31 +01:00
|
|
|
|
2016-11-21 19:05:19 +01:00
|
|
|
if (!isDev) process.env.NODE_ENV = 'production';
|
2016-11-03 22:31:13 +01:00
|
|
|
|
2016-10-30 11:57:12 +01:00
|
|
|
// Keep a global reference of the window object, if you don't, the window will
|
|
|
|
// be closed automatically when the JavaScript object is garbage collected.
|
|
|
|
let mainWindow;
|
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
mainWindow = new BrowserWindow({
|
|
|
|
darkTheme: true,
|
2019-11-04 04:32:03 +01:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
|
|
|
},
|
2016-10-30 11:57:12 +01:00
|
|
|
});
|
2019-11-04 04:32:03 +01:00
|
|
|
mainWindow.loadFile(isDev ? 'index.html' : 'build/index.html');
|
2016-10-30 11:57:12 +01:00
|
|
|
|
|
|
|
mainWindow.on('closed', () => {
|
|
|
|
// Dereference the window object, usually you would store windows
|
|
|
|
// in an array if your app supports multi windows, this is the time
|
|
|
|
// when you should delete the corresponding element.
|
|
|
|
mainWindow = null;
|
|
|
|
});
|
2020-02-18 10:06:57 +01:00
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/39574636/prompt-to-save-quit-before-closing-window/47434365
|
|
|
|
mainWindow.on('close', (e) => {
|
|
|
|
const choice = electron.dialog.showMessageBoxSync(mainWindow, {
|
|
|
|
type: 'question',
|
|
|
|
buttons: ['Yes', 'No'],
|
|
|
|
title: 'Confirm quit',
|
|
|
|
message: 'Are you sure you want to quit? You will lose all unsaved work',
|
|
|
|
});
|
|
|
|
if (choice === 1) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2016-10-30 11:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method will be called when Electron has finished
|
|
|
|
// initialization and is ready to create browser windows.
|
|
|
|
// Some APIs can only be used after this event occurs.
|
2018-02-17 15:15:30 +01:00
|
|
|
app.on('ready', async () => {
|
2016-10-30 11:57:12 +01:00
|
|
|
createWindow();
|
2016-11-05 21:22:31 +01:00
|
|
|
menu(app, mainWindow);
|
2018-02-17 15:15:30 +01:00
|
|
|
|
|
|
|
const newVersion = await checkNewVersion();
|
|
|
|
if (newVersion) {
|
|
|
|
menu(app, mainWindow, newVersion);
|
|
|
|
}
|
2016-10-30 11:57:12 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Quit when all windows are closed.
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
app.quit();
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2016-11-21 19:05:48 +01:00
|
|
|
|
|
|
|
electron.ipcMain.on('renderer-ready', () => {
|
|
|
|
if (!isDev) {
|
|
|
|
const fileToOpen = process.argv[1];
|
2020-02-11 15:16:19 +01:00
|
|
|
// https://github.com/electron/electron/issues/3657
|
|
|
|
if (fileToOpen && !fileToOpen.startsWith('-psn_')) mainWindow.webContents.send('file-opened', [fileToOpen]);
|
2016-11-21 19:05:48 +01:00
|
|
|
}
|
|
|
|
});
|