1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- const { app, BrowserWindow } = require('electron');
- const window = require('./helper/window');
- const path = require('path');
- const { program } = require('commander');
- // Handle creating/removing shortcuts on Windows when installing/uninstalling.
- if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
- app.quit();
- }
- /* --- Initialisation --- */
- // Global var
- let mainWindow;
- let indexFile = 'src/index.html';
- // Add version and option
- program.version('0.0.1');
- program
- .option('-s, --src', 'Load the file from src folder instead of the app folder');
- program.parse(process.argv);
- // Check Option
- const folder = program.src ? './' : './app/';
- /* --- Functions --- */
- // Main function
- async function main() {
- createMainWindow(program.src);
- }
- // Create main window function
- async function createMainWindow(simple = false) {
- if (simple) {
- mainWindow = window.simple(folder + indexFile);
- } else {
- mainWindow = window.new(folder + indexFile);
- }
- mainWindow.on('close', () => {
- mainWindow = null;
- });
- }
- /* --- Electron app actions --- */
- // This method will be called when Electron is ready
- app.on('ready', main);
- // Quit when all windows are closed.
- app.on('window-all-closed', () => {
- // On OS X it is common for applications and their menu bar
- // to stay active until the user quits explicitly with Cmd + Q
- if (process.platform !== 'darwin') {
- app.quit();
- }
- });
- // Re-open
- 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 (BrowserWindow.getAllWindows().length === 0) {
- createMainWindow(program.src);
- }
- });
-
|