1- import { is } from '@electron-toolkit/utils'
21import { BrowserWindow , ipcMain } from 'electron'
32import electronUpdater from 'electron-updater'
43import { IpcChannels } from '../../preload/types'
54
65const { autoUpdater } = electronUpdater
76
8- export function setupUpdater ( window : BrowserWindow | null ) {
9- if ( ! window ) return
7+ let updateWindow : BrowserWindow | null = null
108
9+ export function setUpdaterWindow ( window : BrowserWindow | null ) {
10+ updateWindow = window
11+ }
12+
13+ export function initAutoUpdater ( ) {
1114 autoUpdater . autoDownload = false
1215 autoUpdater . autoInstallOnAppQuit = true
16+ autoUpdater . forceDevUpdateConfig = false
1317
1418 // IPC Handlers
1519 ipcMain . handle ( IpcChannels . CheckForUpdates , async ( ) => {
16- if ( is . dev ) {
17- // add mock up response
18- return {
19- files : [
20- {
21- url : 'https://github.com/victoralvesf/aonsoku/releases/download/v0.11.0/Aonsoku-v0.11.0-linux-x86_64.AppImage' ,
22- sha512 :
23- 'QRsm6JGcGxiFzngU5VK9LhN7AJlO1mTjXpZBpUFIb7CmmNyWtH7nmT+YjaaeHVdBLCQJRGZna6U9ZCVfag8CiA==' ,
24- size : 126846979 ,
25- blockMapSize : 133143 ,
26- } ,
27- ] ,
28- version : '9.99.9' ,
29- updateUrl : 'https://github.com/victoralvesf/aonsoku/releases' ,
30- releaseDate : '2025-11-30T02:45:24.024Z' ,
31- releaseNotes :
32- '## New version available\n\n- New feature 1\n- New feature 2\n\n### Fixes\n\n- Fix 1\n- Fix 2' ,
33- }
34- }
35-
3620 try {
3721 return await autoUpdater . checkForUpdates ( )
3822 } catch ( e ) {
@@ -55,22 +39,22 @@ export function setupUpdater(window: BrowserWindow | null) {
5539 } )
5640
5741 autoUpdater . on ( 'update-available' , ( info ) => {
58- window . webContents . send ( IpcChannels . UpdateAvailable , info )
42+ updateWindow ? .webContents . send ( IpcChannels . UpdateAvailable , info )
5943 } )
6044
6145 autoUpdater . on ( 'update-not-available' , ( ) => {
62- window . webContents . send ( IpcChannels . UpdateNotAvailable )
46+ updateWindow ? .webContents . send ( IpcChannels . UpdateNotAvailable )
6347 } )
6448
6549 autoUpdater . on ( 'error' , ( err ) => {
66- window . webContents . send ( IpcChannels . UpdateError , err . message )
50+ updateWindow ? .webContents . send ( IpcChannels . UpdateError , err . message )
6751 } )
6852
6953 autoUpdater . on ( 'download-progress' , ( progressObj ) => {
70- window . webContents . send ( IpcChannels . DownloadProgress , progressObj )
54+ updateWindow ? .webContents . send ( IpcChannels . DownloadProgress , progressObj )
7155 } )
7256
7357 autoUpdater . on ( 'update-downloaded' , ( info ) => {
74- window . webContents . send ( IpcChannels . UpdateDownloaded , info )
58+ updateWindow ? .webContents . send ( IpcChannels . UpdateDownloaded , info )
7559 } )
7660}
0 commit comments