22const electron = require ( 'electron' ) ;
33const app = electron . app ;
44const BrowserWindow = electron . BrowserWindow ;
5- const localShortcut = require ( 'electron-localshortcut' ) ;
65
76const APP_URL = 'app://birdex/index.html' ; // birdex.asar
87// const APP_URL = 'http://new.001.birdex.org/';
98// const APP_URL = 'http://oleg.dev:8000/index-dev.html';
109// const APP_URL = 'http://oleg.dev:8000/index.html';
1110
12- const handleSetupEvent = function ( ) {
11+ const handleStartupEvent = function ( ) {
1312 if ( process . argv . length === 1 ) {
1413 return false ;
1514 }
@@ -49,7 +48,6 @@ const handleSetupEvent = function() {
4948
5049 spawnUpdate ( [ '--createShortcut' , exeName ] ) ;
5150
52- setTimeout ( app . quit , 1000 ) ;
5351 return true ;
5452
5553 case '--squirrel-uninstall' :
@@ -58,74 +56,52 @@ const handleSetupEvent = function() {
5856
5957 spawnUpdate ( [ '--removeShortcut' , exeName ] ) ;
6058
61- setTimeout ( app . quit , 1000 ) ;
6259 return true ;
6360
6461 case '--squirrel-obsolete' :
6562 // This is called on the outgoing version of your app before
6663 // we update to the new version - it's the opposite of
6764 // --squirrel-updated
6865
69- app . quit ( ) ;
7066 return true ;
7167 }
7268} ;
73- if ( handleSetupEvent ( ) ) {
74- return ;
69+ if ( handleStartupEvent ( ) ) {
70+ return setTimeout ( app . quit , 1000 ) ;
7571}
7672
77- function devTools ( ) {
78- const win = BrowserWindow . getFocusedWindow ( ) ;
79-
80- if ( win ) {
81- win . toggleDevTools ( ) ;
73+ app . on ( 'ready' , ( ) => {
74+ const localShortcut = require ( 'electron-localshortcut' ) ;
75+ const openDevTools = function ( ) {
76+ const win = BrowserWindow . getFocusedWindow ( ) ;
77+ if ( win ) {
78+ win . toggleDevTools ( ) ;
79+ }
8280 }
83- }
84-
85- function refresh ( ) {
86- const win = BrowserWindow . getFocusedWindow ( ) ;
8781
88- // return console.log(APP_URL.substr(3));
89- if ( win ) {
90- if ( APP_URL . substr ( 0 , 3 ) === 'app' ) {
91- win . loadURL ( APP_URL ) ;
92- } else {
93- win . webContents . reloadIgnoringCache ( ) ;
82+ const refresh = function ( ) {
83+ const win = BrowserWindow . getFocusedWindow ( ) ;
84+ if ( win ) {
85+ if ( APP_URL . substr ( 0 , 3 ) === 'app' ) {
86+ win . loadURL ( APP_URL ) ;
87+ } else {
88+ win . webContents . reloadIgnoringCache ( ) ;
89+ }
9490 }
9591 }
96- }
9792
98- app . on ( 'ready' , ( ) => {
99- localShortcut . register ( 'Ctrl+Shift+I' , devTools ) ;
100- localShortcut . register ( 'F12' , devTools ) ;
93+ localShortcut . register ( 'Ctrl+Shift+I' , openDevTools ) ;
94+ localShortcut . register ( 'F12' , openDevTools ) ;
10195
10296 localShortcut . register ( 'CmdOrCtrl+R' , refresh ) ;
10397 localShortcut . register ( 'F5' , refresh ) ;
10498} ) ;
10599
106- let downloadedUpdate = false ;
107-
108- const GhReleases = require ( 'electron-gh-releases' )
109- let options = {
110- repo : 'AlgorithmLLC/chat-client-electron' ,
111- currentVersion : app . getVersion ( )
112- } ;
113- const updater = new GhReleases ( options ) ;
114- // Check for updates
115- // `status` returns true if there is a new update available
116- updater . check ( ( err , status ) => {
117- if ( ! err && status ) {
118- // Download the update
119- updater . download ( ) ;
120- }
121- } ) ;
122-
123100// Quit when all windows are closed.
124101app . on ( 'window-all-closed' , function ( ) {
125102 app . quit ( ) ;
126103} ) ;
127104
128-
129105let mainWindow ;
130106// This method will be called when Electron has finished
131107// initialization and is ready to create browser windows.
@@ -135,21 +111,23 @@ app.on('ready', function() {
135111 let url = request . url . substr ( 12 ) ;
136112 callback ( { path : require ( 'path' ) . normalize ( __dirname + '/birdex.asar/' + url ) } ) ;
137113 } , function ( error ) {
138- if ( error )
139- console . error ( 'Failed to register protocol' )
114+ if ( error ) {
115+ console . error ( 'Failed to register protocol' ) ;
116+ }
140117 } ) ;
141118
142119 // bugfix for <img ng-src> requesting unsafe:app://birdex/path
143120 protocol . registerFileProtocol ( 'unsafe' , function ( request , callback ) {
144121 let url = request . url . substr ( 19 ) ;
145122 callback ( { path : require ( 'path' ) . normalize ( __dirname + '/birdex.asar/' + url ) } ) ;
146123 } , function ( error ) {
147- if ( error )
148- console . error ( 'Failed to register protocol' )
124+ if ( error ) {
125+ console . error ( 'Failed to register protocol' ) ;
126+ }
149127 } ) ;
150128
151129 // Create the browser window.
152- mainWindow = new electron . BrowserWindow ( {
130+ mainWindow = new BrowserWindow ( {
153131 width : 1280
154132 , height : 720
155133 , minHeight : 720
@@ -161,12 +139,26 @@ app.on('ready', function() {
161139
162140 // and load the index.html of the app.
163141 mainWindow . loadURL ( APP_URL ) ;
164-
165142 // Emitted when the window is closed.
166143 mainWindow . on ( 'closed' , function ( ) {
167144 // Dereference the window object, usually you would store windows
168145 // in an array if your app supports multi windows, this is the time
169146 // when you should delete the corresponding element.
170147 mainWindow = null ;
171148 } ) ;
149+
150+ const GhReleases = require ( 'electron-gh-releases' ) ;
151+ let options = {
152+ repo : 'AlgorithmLLC/chat-client-electron' ,
153+ currentVersion : app . getVersion ( )
154+ } ;
155+ const updater = new GhReleases ( options ) ;
156+ // Check for updates
157+ // `status` returns true if there is a new update available
158+ updater . check ( ( err , status ) => {
159+ if ( ! err && status ) {
160+ // Download the update
161+ updater . download ( ) ;
162+ }
163+ } ) ;
172164} ) ;
0 commit comments