mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-25 19:15:18 +02:00
refactor(desktop): extract auto-updater into modules/auto-updater.ts
This commit is contained in:
parent
35da1cf1b4
commit
d868464de7
2 changed files with 35 additions and 35 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import { app, BrowserWindow, shell, ipcMain, dialog, Menu } from 'electron';
|
import { app, BrowserWindow, shell, ipcMain, Menu } from 'electron';
|
||||||
import { autoUpdater } from 'electron-updater';
|
|
||||||
import { registerGlobalErrorHandlers, showErrorDialog } from './modules/errors';
|
import { registerGlobalErrorHandlers, showErrorDialog } from './modules/errors';
|
||||||
import { startNextServer } from './modules/server';
|
import { startNextServer } from './modules/server';
|
||||||
import { createMainWindow } from './modules/window';
|
import { createMainWindow } from './modules/window';
|
||||||
import { setupDeepLinks, handlePendingDeepLink } from './modules/deep-links';
|
import { setupDeepLinks, handlePendingDeepLink } from './modules/deep-links';
|
||||||
|
import { setupAutoUpdater } from './modules/auto-updater';
|
||||||
|
|
||||||
registerGlobalErrorHandlers();
|
registerGlobalErrorHandlers();
|
||||||
|
|
||||||
|
|
@ -11,8 +11,6 @@ if (!setupDeepLinks()) {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDev = !app.isPackaged;
|
|
||||||
|
|
||||||
// IPC handlers
|
// IPC handlers
|
||||||
ipcMain.on('open-external', (_event, url: string) => {
|
ipcMain.on('open-external', (_event, url: string) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -29,37 +27,6 @@ ipcMain.handle('get-app-version', () => {
|
||||||
return app.getVersion();
|
return app.getVersion();
|
||||||
});
|
});
|
||||||
|
|
||||||
function setupAutoUpdater() {
|
|
||||||
if (isDev) return;
|
|
||||||
|
|
||||||
autoUpdater.autoDownload = true;
|
|
||||||
|
|
||||||
autoUpdater.on('update-available', (info) => {
|
|
||||||
console.log(`Update available: ${info.version}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
autoUpdater.on('update-downloaded', (info) => {
|
|
||||||
console.log(`Update downloaded: ${info.version}`);
|
|
||||||
dialog.showMessageBox({
|
|
||||||
type: 'info',
|
|
||||||
buttons: ['Restart', 'Later'],
|
|
||||||
defaultId: 0,
|
|
||||||
title: 'Update Ready',
|
|
||||||
message: `Version ${info.version} has been downloaded. Restart to apply the update.`,
|
|
||||||
}).then(({ response }) => {
|
|
||||||
if (response === 0) {
|
|
||||||
autoUpdater.quitAndInstall();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
autoUpdater.on('error', (err) => {
|
|
||||||
console.error('Auto-updater error:', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
autoUpdater.checkForUpdates();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupMenu() {
|
function setupMenu() {
|
||||||
const isMac = process.platform === 'darwin';
|
const isMac = process.platform === 'darwin';
|
||||||
const template: Electron.MenuItemConstructorOptions[] = [
|
const template: Electron.MenuItemConstructorOptions[] = [
|
||||||
|
|
|
||||||
33
surfsense_desktop/src/modules/auto-updater.ts
Normal file
33
surfsense_desktop/src/modules/auto-updater.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
import { app, dialog } from 'electron';
|
||||||
|
import { autoUpdater } from 'electron-updater';
|
||||||
|
|
||||||
|
export function setupAutoUpdater(): void {
|
||||||
|
if (!app.isPackaged) return;
|
||||||
|
|
||||||
|
autoUpdater.autoDownload = true;
|
||||||
|
|
||||||
|
autoUpdater.on('update-available', (info) => {
|
||||||
|
console.log(`Update available: ${info.version}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('update-downloaded', (info) => {
|
||||||
|
console.log(`Update downloaded: ${info.version}`);
|
||||||
|
dialog.showMessageBox({
|
||||||
|
type: 'info',
|
||||||
|
buttons: ['Restart', 'Later'],
|
||||||
|
defaultId: 0,
|
||||||
|
title: 'Update Ready',
|
||||||
|
message: `Version ${info.version} has been downloaded. Restart to apply the update.`,
|
||||||
|
}).then(({ response }) => {
|
||||||
|
if (response === 0) {
|
||||||
|
autoUpdater.quitAndInstall();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('error', (err) => {
|
||||||
|
console.error('Auto-updater error:', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.checkForUpdates();
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue