11// @flow
22import { app , BrowserWindow , ipcMain } from 'electron' ;
3+ import log from 'electron-log' ;
4+ import { autoUpdater } from "electron-updater" ;
35import MenuBuilder from './menu' ;
46import configureStore from './store/configureStore' ;
57import appPackage from './package.json' ;
68
9+ autoUpdater . logger = log ;
10+ autoUpdater . logger . transports . file . level = 'info' ;
11+ log . info ( 'App starting...' ) ;
12+
713const store = configureStore ( ) ;
814let mainWindow = null ;
915
1016if ( process . env . NODE_ENV === 'development' ) {
1117 app . setName ( appPackage . name ) ;
1218 app . setVersion ( appPackage . version ) ;
19+ autoUpdater . updateConfigPath = './dev-app-update.yml' ;
1320}
1421
1522if ( process . env . NODE_ENV === 'production' ) {
@@ -18,18 +25,18 @@ if (process.env.NODE_ENV === 'production') {
1825}
1926
2027// if (process.env.NODE_ENV === 'development') {
21- require ( 'electron-debug' ) ( ) ; // eslint-disable-line global-require
22- const path = require ( 'path' ) ; // eslint-disable-line
23- const p = path . join ( __dirname , '..' , 'app' , 'node_modules' ) ; // eslint-disable-line
24- require ( 'module' ) . globalPaths . push ( p ) ; // eslint-disable-line
28+ require ( 'electron-debug' ) ( ) ; // eslint-disable-line global-require
29+ const path = require ( 'path' ) ; // eslint-disable-line
30+ const p = path . join ( __dirname , '..' , 'app' , 'node_modules' ) ; // eslint-disable-line
31+ require ( 'module' ) . globalPaths . push ( p ) ; // eslint-disable-line
2532// }
2633
2734app . on ( 'window-all-closed' , ( ) => {
2835 if ( process . platform !== 'darwin' ) app . quit ( ) ;
2936} ) ;
3037
3138
32- const installExtensions = async ( ) => {
39+ const installExtensions = async ( ) => {
3340 if ( process . env . NODE_ENV === 'development' ) {
3441 const installer = require ( 'electron-devtools-installer' ) ; // eslint-disable-line global-require
3542
@@ -49,10 +56,9 @@ const installExtensions = async() => {
4956 }
5057} ;
5158
52- app . on ( 'ready' , async ( ) => {
59+ app . on ( 'ready' , async ( ) => {
5360 await installExtensions ( ) ;
5461
55-
5662 mainWindow = new BrowserWindow ( {
5763 show : false ,
5864 width : 1450 ,
@@ -72,6 +78,8 @@ app.on('ready', async() => {
7278 mainWindow . show ( ) ;
7379 mainWindow . focus ( ) ;
7480 mainWindow . maximize ( ) ;
81+
82+ autoUpdater . checkForUpdates ( ) ;
7583 } ) ;
7684
7785 mainWindow . on ( 'closed' , ( ) => {
@@ -84,3 +92,16 @@ app.on('ready', async() => {
8492 const menuBuilder = new MenuBuilder ( mainWindow , store ) ;
8593 menuBuilder . buildMenu ( ) ;
8694} ) ;
95+
96+
97+ autoUpdater . on ( 'download-progress' , ( progressObj ) => {
98+ log . info ( 'Downloaded ' + Math . round ( progressObj . percent ) + '% (' + progressObj . transferred + "/" + progressObj . total + ')' ) ;
99+ } ) ;
100+ autoUpdater . on ( 'update-downloaded' , ( update ) => mainWindow . send ( 'dispatchFromMain' , { update} ) ) ;
101+ ipcMain . on ( 'installUpdate' , ( ) => {
102+ if ( process . env . NODE_ENV === 'development' ) {
103+ console . log ( 'autoUpdater.quitAndInstall()' ) ;
104+ } else {
105+ autoUpdater . quitAndInstall ( ) ;
106+ }
107+ } ) ;
0 commit comments