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