@@ -2,6 +2,8 @@ const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron');
22const path = require ( 'path' ) ;
33const { exec } = require ( 'child_process' ) ;
44const fs = require ( 'fs' ) ;
5+
6+ // Import autoUpdater from electron-updater
57const { autoUpdater } = require ( 'electron-updater' ) ;
68
79let mainWindow ;
@@ -33,30 +35,10 @@ function createWindow() {
3335 // Check if JAMS is installed
3436 checkJAMSInstallation ( ) ;
3537
36- // Check for updates (only in prod mode)
37- if ( ! isDev ) {
38- autoUpdater . checkForUpdatesAndNotify ( ) ;
39- }
38+ // Check for updates after creating the window
39+ autoUpdater . checkForUpdatesAndNotify ( ) ;
4040}
4141
42- autoUpdater . on ( 'update-available' , ( ) => {
43- mainWindow . webContents . send ( 'update-available' ) ;
44- } ) ;
45-
46- autoUpdater . on ( 'update-downloaded' , ( ) => {
47- mainWindow . webContents . send ( 'update-downloaded' ) ;
48- } ) ;
49-
50- // IPC handler for installing the update
51- ipcMain . on ( 'install-update' , ( ) => {
52- autoUpdater . quitAndInstall ( ) ;
53- } ) ;
54-
55- ipcMain . handle ( 'get-app-version' , ( ) => {
56- return app . getVersion ( ) ;
57- } ) ;
58-
59-
6042app . on ( 'ready' , createWindow ) ;
6143
6244app . on ( 'window-all-closed' , ( ) => {
@@ -71,6 +53,25 @@ app.on('activate', () => {
7153 }
7254} ) ;
7355
56+ // Listen for update events
57+ autoUpdater . on ( 'update-available' , ( ) => {
58+ dialog . showMessageBox ( {
59+ type : 'info' ,
60+ title : 'Update available' ,
61+ message : 'A new version of the application is available. It will be downloaded now.' ,
62+ } ) ;
63+ } ) ;
64+
65+ autoUpdater . on ( 'update-downloaded' , ( ) => {
66+ dialog . showMessageBox ( {
67+ type : 'info' ,
68+ title : 'Update ready' ,
69+ message : 'A new version of the application has been downloaded. The application will now restart to apply the update.' ,
70+ } ) . then ( ( ) => {
71+ autoUpdater . quitAndInstall ( ) ;
72+ } ) ;
73+ } ) ;
74+
7475function checkJAMSInstallation ( ) {
7576 const homeDir = process . env . HOME || process . env . HOMEPATH || process . env . USERPROFILE ;
7677 const binDir = path . join ( homeDir , 'bin' ) ;
0 commit comments