|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -const electron = require('electron'); |
4 |
| -// Module to control application life. |
5 |
| -const { app } = electron; |
6 |
| -// Module to create native browser window. |
7 |
| -const { BrowserWindow } = electron; |
8 |
| - |
9 |
| -let win, serve; |
10 |
| -const args = process.argv.slice(1); |
11 |
| -serve = args.some(val => val === "--serve"); |
12 |
| - |
13 |
| -if (serve) { |
14 |
| - require('electron-reload')(__dirname + '/dist'); |
15 |
| -} |
| 3 | +try { |
| 4 | + const electron = require('electron'); |
| 5 | + // Module to control application life. |
| 6 | + const { app } = electron; |
| 7 | + // Module to create native browser window. |
| 8 | + const { BrowserWindow } = electron; |
16 | 9 |
|
17 |
| -function createWindow() { |
| 10 | + let win, serve; |
| 11 | + const args = process.argv.slice(1); |
| 12 | + serve = args.some(val => val === "--serve"); |
18 | 13 |
|
19 |
| - let electronScreen = electron.screen; |
20 |
| - let size = electronScreen.getPrimaryDisplay().workAreaSize; |
| 14 | + if (serve) { |
| 15 | + require('electron-reload')(__dirname + '/dist'); |
| 16 | + } |
21 | 17 |
|
22 |
| - // Create the browser window. |
23 |
| - win = new BrowserWindow({ |
24 |
| - x: 0, |
25 |
| - y: 0, |
26 |
| - width: size.width, |
27 |
| - height: size.height |
28 |
| - }); |
| 18 | + function createWindow() { |
29 | 19 |
|
30 |
| - let url = serve ? |
31 |
| - 'file://' + __dirname + '/dist/index.html' : |
32 |
| - 'file://' + __dirname + '/index.html'; |
| 20 | + let electronScreen = electron.screen; |
| 21 | + let size = electronScreen.getPrimaryDisplay().workAreaSize; |
33 | 22 |
|
34 |
| - // and load the index.html of the app. |
35 |
| - win.loadURL(url); |
| 23 | + // Create the browser window. |
| 24 | + win = new BrowserWindow({ |
| 25 | + x: 0, |
| 26 | + y: 0, |
| 27 | + width: size.width, |
| 28 | + height: size.height |
| 29 | + }); |
36 | 30 |
|
37 |
| - // Open the DevTools. |
38 |
| - if (serve) { |
39 |
| - win.webContents.openDevTools(); |
| 31 | + let url = serve ? |
| 32 | + 'file://' + __dirname + '/dist/index.html' : |
| 33 | + 'file://' + __dirname + '/index.html'; |
| 34 | + |
| 35 | + // and load the index.html of the app. |
| 36 | + win.loadURL(url); |
| 37 | + |
| 38 | + // Open the DevTools. |
| 39 | + if (serve) { |
| 40 | + win.webContents.openDevTools(); |
| 41 | + } |
| 42 | + |
| 43 | + // Emitted when the window is closed. |
| 44 | + win.on('closed', () => { |
| 45 | + // Dereference the window object, usually you would store window |
| 46 | + // in an array if your app supports multi windows, this is the time |
| 47 | + // when you should delete the corresponding element. |
| 48 | + win = null; |
| 49 | + }); |
40 | 50 | }
|
41 | 51 |
|
42 |
| - // Emitted when the window is closed. |
43 |
| - win.on('closed', () => { |
44 |
| - // Dereference the window object, usually you would store window |
45 |
| - // in an array if your app supports multi windows, this is the time |
46 |
| - // when you should delete the corresponding element. |
47 |
| - win = null; |
48 |
| - }); |
49 |
| -} |
50 | 52 |
|
| 53 | + // This method will be called when Electron has finished |
| 54 | + // initialization and is ready to create browser windows. |
| 55 | + // Some APIs can only be used after this event occurs. |
| 56 | + app.on('ready', createWindow); |
51 | 57 |
|
52 |
| -// This method will be called when Electron has finished |
53 |
| -// initialization and is ready to create browser windows. |
54 |
| -// Some APIs can only be used after this event occurs. |
55 |
| -app.on('ready', createWindow); |
| 58 | + // Quit when all windows are closed. |
| 59 | + app.on('window-all-closed', () => { |
| 60 | + // On OS X it is common for applications and their menu bar |
| 61 | + // to stay active until the user quits explicitly with Cmd + Q |
| 62 | + if (process.platform !== 'darwin') { |
| 63 | + app.quit(); |
| 64 | + } |
| 65 | + }); |
56 | 66 |
|
57 |
| -// Quit when all windows are closed. |
58 |
| -app.on('window-all-closed', () => { |
59 |
| - // On OS X it is common for applications and their menu bar |
60 |
| - // to stay active until the user quits explicitly with Cmd + Q |
61 |
| - if (process.platform !== 'darwin') { |
62 |
| - app.quit(); |
63 |
| - } |
64 |
| -}); |
| 67 | + app.on('activate', () => { |
| 68 | + // On OS X it's common to re-create a window in the app when the |
| 69 | + // dock icon is clicked and there are no other windows open. |
| 70 | + if (win === null) { |
| 71 | + createWindow(); |
| 72 | + } |
| 73 | + }); |
65 | 74 |
|
66 |
| -app.on('activate', () => { |
67 |
| - // On OS X it's common to re-create a window in the app when the |
68 |
| - // dock icon is clicked and there are no other windows open. |
69 |
| - if (win === null) { |
70 |
| - createWindow(); |
71 |
| - } |
72 |
| -}); |
73 | 75 |
|
| 76 | +} catch (e) { |
| 77 | + // Catch Error |
| 78 | +} |
0 commit comments