1- const { app, Tray, Menu, nativeImage } = require ( "electron" ) ;
1+ const {
2+ app,
3+ Tray,
4+ Menu,
5+ nativeImage,
6+ autoUpdater,
7+ dialog
8+ } = require ( "electron" ) ;
29const sqlite3 = require ( "sqlite3" ) ;
310const fs = require ( "fs" ) ;
4- const { startExpressServer } = require ( "./expressServer" ) ;
5- const { startWebsocketServer } = require ( "./websocketServer" ) ;
11+ const { startExpressServer, stopExpressServer } = require ( "./expressServer" ) ;
12+ const {
13+ startWebsocketServer,
14+ stopWebsocketServer
15+ } = require ( "./websocketServer" ) ;
616const path = require ( "path" ) ;
717const { openUrl } = require ( "./Controllers/system-controller" ) ;
818const log = require ( "electron-log" ) ;
9- const {
10- checkForUpdate,
11- downloadLatestRelease
12- } = require ( "./Utils/autoUpdater" ) ;
1319
1420if ( require ( "electron-squirrel-startup" ) ) app . quit ( ) ;
1521
@@ -41,13 +47,48 @@ const handleDatabase = () => {
4147} ;
4248
4349app . whenReady ( ) . then ( async ( ) => {
50+ log . info ( process . argv ) ;
4451 // Check for update
45- const updateInfo = await checkForUpdate (
46- "https://api.github.com/repos/hysasuke/project-hub/releases"
47- ) ;
48- console . log ( updateInfo ) ;
49- if ( updateInfo . updateAvailable ) {
50- downloadLatestRelease ( updateInfo . downloadUrls ) ;
52+ autoUpdater . setFeedURL ( {
53+ url : "https://github.com/hysasuke/Project-Hub/releases/latest/download/"
54+ } ) ;
55+
56+ autoUpdater . on ( "checking-for-update" , ( ) => {
57+ log . info ( "Checking for update..." ) ;
58+ } ) ;
59+ autoUpdater . on ( "update-available" , ( info ) => {
60+ log . info ( "Update available." ) ;
61+ } ) ;
62+
63+ autoUpdater . on ( "update-downloaded" , ( info ) => {
64+ log . info ( "Update downloaded" ) ;
65+ autoUpdater . quitAndInstall ( ) ;
66+ } ) ;
67+
68+ autoUpdater . on ( "update-not-available" , ( info ) => {
69+ log . info ( "Update not available." ) ;
70+ } ) ;
71+
72+ autoUpdater . on ( "error" , ( err ) => {
73+ log . info ( "Error in auto-updater. " + err ) ;
74+ } ) ;
75+
76+ autoUpdater . on ( "before-quit-for-update" , ( ) => {
77+ log . info ( "Update downloaded; will install on quit" ) ;
78+ stopExpressServer ( ) ;
79+ stopWebsocketServer ( ) ;
80+ } ) ;
81+
82+ // Listen to before-quit event
83+ app . on ( "before-quit" , ( ) => {
84+ log . info ( "App is quitting..." ) ;
85+ stopExpressServer ( ) ;
86+ stopWebsocketServer ( ) ;
87+ } ) ;
88+
89+ // set auto update if in production
90+ if ( app . isPackaged ) {
91+ autoUpdater . checkForUpdates ( ) ;
5192 }
5293 // Make appData directory
5394 const appDataPath = path . join ( app . getPath ( "appData" ) , "ProjectHub" ) ;
@@ -67,6 +108,7 @@ app.whenReady().then(async () => {
67108 const exeName = path . basename ( process . execPath ) ;
68109 // note: your contextMenu, Tooltip and Title code will go here!
69110 const contextMenu = Menu . buildFromTemplate ( [
111+ { label : "Current Version: " + app . getVersion ( ) , enabled : false } ,
70112 {
71113 label : "Auto Start" ,
72114 type : "checkbox" ,
@@ -99,6 +141,8 @@ app.whenReady().then(async () => {
99141 tray . setToolTip ( "Project Hub" ) ;
100142 tray . setTitle ( "Project Hub" ) ;
101143
144+ log . info ( "Starting express server..." ) ;
102145 startExpressServer ( ) ;
146+ log . info ( "Starting websocket server..." ) ;
103147 startWebsocketServer ( ) ;
104148} ) ;
0 commit comments