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');
|
2017-08-15 14:02:26 +02:00
|
|
|
const path = require('path');
|
|
|
|
const url = require('url');
|
2016-10-30 11:57:12 +01:00
|
|
|
|
|
|
|
const menu = require('./menu');
|
|
|
|
|
|
|
|
const app = electron.app;
|
|
|
|
const BrowserWindow = electron.BrowserWindow;
|
|
|
|
|
2016-11-05 21:22:31 +01:00
|
|
|
app.setName('LosslessCut');
|
|
|
|
|
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,
|
|
|
|
});
|
2017-08-15 14:02:26 +02:00
|
|
|
mainWindow.loadURL(url.format({
|
|
|
|
pathname: path.join(__dirname, 'index.html'),
|
|
|
|
protocol: 'file:',
|
|
|
|
slashes: true,
|
|
|
|
}));
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
app.on('ready', () => {
|
|
|
|
createWindow();
|
2016-11-05 21:22:31 +01:00
|
|
|
menu(app, mainWindow);
|
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];
|
|
|
|
if (fileToOpen) mainWindow.webContents.send('file-opened', [fileToOpen]);
|
|
|
|
}
|
|
|
|
});
|