|
1 | | -import { app, BrowserWindow, ipcMain, shell, dialog, globalShortcut, Menu, session } from 'electron'; |
| 1 | +import { app, BrowserWindow, ipcMain, shell, dialog, globalShortcut, Menu, session, Notification } from 'electron'; |
2 | 2 | import fs from 'fs/promises'; |
3 | 3 | import fsSync from 'fs'; |
4 | 4 | import path from 'path'; |
@@ -903,53 +903,30 @@ ipcMain.handle('get-versions', async () => { |
903 | 903 | return {current: pjson.version, latest: latestVersion}; |
904 | 904 | }); |
905 | 905 |
|
906 | | -app.whenReady().then(() => { |
907 | | - // Check for updates on startup |
908 | | - autoUpdater.checkForUpdatesAndNotify(); |
909 | | - |
910 | | - autoUpdater.on('checking-for-update', () => { |
911 | | - console.log('Checking for update...'); |
912 | | - }); |
913 | | - |
914 | | - autoUpdater.on('update-available', (info) => { |
915 | | - console.log('Update available.', info); |
916 | | - }); |
917 | | - |
918 | | - autoUpdater.on('update-not-available', (info) => { |
919 | | - console.log('Update not available.', info); |
920 | | - }); |
921 | | - |
922 | | - autoUpdater.on('error', (err) => { |
923 | | - console.error('Error in auto-updater.', err); |
924 | | - }); |
925 | | - |
926 | | - autoUpdater.on('download-progress', (progressObj) => { |
927 | | - let log_message = "Download speed: " + progressObj.bytesPerSecond; |
928 | | - log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'; |
929 | | - log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')'; |
930 | | - console.log(log_message); |
931 | | - }); |
932 | | - |
933 | | - autoUpdater.on('update-downloaded', (info) => { |
934 | | - console.log('Update downloaded', info); |
935 | | - }); |
936 | | - |
937 | | - session.defaultSession.webRequest.onHeadersReceived((details, callback) => { |
938 | | - callback({ |
939 | | - responseHeaders: { |
940 | | - ...details.responseHeaders, |
941 | | - "Access-Control-Allow-Origin": ["*"], // Allow all origins |
942 | | - "Access-Control-Allow-Methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"], |
943 | | - "Access-Control-Allow-Headers": ["*"] |
944 | | - } |
945 | | - }); |
946 | | - }); |
| 906 | +// Manual update handlers |
| 907 | +ipcMain.handle('check-for-updates', async () => { |
| 908 | + try { |
| 909 | + await autoUpdater.checkForUpdates(); |
| 910 | + return { success: true }; |
| 911 | + } catch (error) { |
| 912 | + console.error('Manual update check failed:', error); |
| 913 | + return { success: false, error: error.message }; |
| 914 | + } |
| 915 | +}); |
947 | 916 |
|
948 | | - createWindows(); |
| 917 | +ipcMain.handle('download-update', async () => { |
| 918 | + try { |
| 919 | + await autoUpdater.downloadUpdate(); |
| 920 | + return { success: true }; |
| 921 | + } catch (error) { |
| 922 | + console.error('Update download failed:', error); |
| 923 | + return { success: false, error: error.message }; |
| 924 | + } |
| 925 | +}); |
949 | 926 |
|
950 | | - globalShortcut.register('Ctrl+Shift+K', () => { |
951 | | - killChildProcesses(childProcesses); |
952 | | - }); |
| 927 | +ipcMain.handle('quit-and-install', async () => { |
| 928 | + app.relaunch({ args: process.argv.slice(1).concat(['--restarted']) }); |
| 929 | + autoUpdater.quitAndInstall(); |
953 | 930 | }); |
954 | 931 |
|
955 | 932 | ipcMain.handle('install-flatpak', async (event, appId) => { |
@@ -1151,3 +1128,78 @@ ipcMain.handle('get-flatpak-download-size', async (event, appId) => { |
1151 | 1128 | }); |
1152 | 1129 | }); |
1153 | 1130 | }); |
| 1131 | + |
| 1132 | +// Manual update system - no auto-check on startup |
| 1133 | +app.whenReady().then(() => { |
| 1134 | + autoUpdater.on('checking-for-update', () => { |
| 1135 | + mainWindow.webContents.send('update-status', { status: 'checking' }); |
| 1136 | + }); |
| 1137 | + |
| 1138 | + autoUpdater.on('update-available', (info) => { |
| 1139 | + new Notification({ |
| 1140 | + title: 'Update Available', |
| 1141 | + body: `Emulsion ${info.version} is available for download` |
| 1142 | + }).show(); |
| 1143 | + mainWindow.webContents.send('update-status', { |
| 1144 | + status: 'available', |
| 1145 | + info: info, |
| 1146 | + version: info.version |
| 1147 | + }); |
| 1148 | + }); |
| 1149 | + |
| 1150 | + autoUpdater.on('update-not-available', (info) => { |
| 1151 | + new Notification({ |
| 1152 | + title: 'No Updates Available', |
| 1153 | + body: 'You are running the latest version of Emulsion' |
| 1154 | + }).show(); |
| 1155 | + mainWindow.webContents.send('update-status', { status: 'up-to-date' }); |
| 1156 | + }); |
| 1157 | + |
| 1158 | + autoUpdater.on('error', (err) => { |
| 1159 | + new Notification({ |
| 1160 | + title: 'Update Error', |
| 1161 | + body: `Failed to check for updates: ${err.message}` |
| 1162 | + }).show(); |
| 1163 | + mainWindow.webContents.send('update-status', { status: 'error', error: err.message }); |
| 1164 | + }); |
| 1165 | + |
| 1166 | + autoUpdater.on('download-progress', (progressObj) => { |
| 1167 | + const progress = Math.round(progressObj.percent); |
| 1168 | + const speedMBs = (progressObj.bytesPerSecond / 1024 / 1024).toFixed(2); |
| 1169 | + const downloadedMB = (progressObj.transferred / 1024 / 1024).toFixed(2); |
| 1170 | + const totalMB = (progressObj.total / 1024 / 1024).toFixed(2); |
| 1171 | + |
| 1172 | + mainWindow.webContents.send('update-status', { |
| 1173 | + status: 'downloading', |
| 1174 | + progress: progress, |
| 1175 | + speed: speedMBs, |
| 1176 | + downloaded: downloadedMB, |
| 1177 | + total: totalMB |
| 1178 | + }); |
| 1179 | + }); |
| 1180 | + |
| 1181 | + autoUpdater.on('update-downloaded', (info) => { |
| 1182 | + new Notification({ |
| 1183 | + title: 'Update Downloaded', |
| 1184 | + body: 'Restart Emulsion to apply the update' |
| 1185 | + }).show(); |
| 1186 | + mainWindow.webContents.send('update-status', { status: 'downloaded', info: info }); |
| 1187 | + }); |
| 1188 | + |
| 1189 | + session.defaultSession.webRequest.onHeadersReceived((details, callback) => { |
| 1190 | + callback({ |
| 1191 | + responseHeaders: { |
| 1192 | + ...details.responseHeaders, |
| 1193 | + "Access-Control-Allow-Origin": ["*"], // Allow all origins |
| 1194 | + "Access-Control-Allow-Methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"], |
| 1195 | + "Access-Control-Allow-Headers": ["*"] |
| 1196 | + } |
| 1197 | + }); |
| 1198 | + }); |
| 1199 | + |
| 1200 | + createWindows(); |
| 1201 | + |
| 1202 | + globalShortcut.register('Ctrl+Shift+K', () => { |
| 1203 | + killChildProcesses(childProcesses); |
| 1204 | + }); |
| 1205 | +}); |
0 commit comments