-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: checking for updates after the client is reopened shows an `obje…
…ct destroy` error Signed-off-by: The1111mp <[email protected]>
- Loading branch information
Showing
5 changed files
with
61 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,68 @@ | ||
import { ipcMain } from 'electron' | ||
import updater from 'electron-updater' | ||
import log from 'electron-log' | ||
import { ipcMain } from "electron"; | ||
import updater from "electron-updater"; | ||
import log from "electron-log"; | ||
|
||
const { autoUpdater } = updater | ||
const { autoUpdater } = updater; | ||
|
||
import type { BrowserWindow } from 'electron' | ||
import type { BrowserWindow } from "electron"; | ||
|
||
export class AppUpdater { | ||
constructor(private readonly mainWindow: BrowserWindow) { | ||
log.transports.file.level = 'info' | ||
autoUpdater.logger = log | ||
autoUpdater.autoDownload = false | ||
log.transports.file.level = "info"; | ||
autoUpdater.logger = log; | ||
autoUpdater.autoDownload = false; | ||
|
||
autoUpdater.on('update-available', (info) => { | ||
autoUpdater.on("update-available", (info) => { | ||
// had updates | ||
this.mainWindow?.webContents.send('update-available', info) | ||
}) | ||
this.mainWindow?.webContents.send("update-available", info); | ||
}); | ||
|
||
autoUpdater.on('update-not-available', () => { | ||
autoUpdater.on("update-not-available", () => { | ||
// there are no updates | ||
this.mainWindow?.webContents.send('update-not-available', 'update-not-available') | ||
}) | ||
this.mainWindow?.webContents.send("update-not-available", "update-not-available"); | ||
}); | ||
|
||
autoUpdater.on('download-progress', (progress) => { | ||
autoUpdater.on("download-progress", (progress) => { | ||
// download progress | ||
mainWindow?.webContents.send('download-progress', progress) | ||
}) | ||
mainWindow?.webContents.send("download-progress", progress); | ||
}); | ||
|
||
autoUpdater.on('update-downloaded', (_evt) => { | ||
autoUpdater.on("update-downloaded", (_evt) => { | ||
// update downloaded | ||
ipcMain.once('make-update-now', () => { | ||
autoUpdater.quitAndInstall() | ||
}) | ||
}) | ||
ipcMain.once("make-update-now", () => { | ||
autoUpdater.quitAndInstall(); | ||
}); | ||
}); | ||
|
||
autoUpdater.on('error', (error) => { | ||
autoUpdater.on("error", (error) => { | ||
// update error | ||
mainWindow?.webContents.send('update-error', error) | ||
}) | ||
mainWindow?.webContents.send("update-error", error); | ||
}); | ||
|
||
// initial | ||
this.checkForUpdates() | ||
this.comfirmUpdate() | ||
this.checkForUpdates(); | ||
this.comfirmUpdate(); | ||
} | ||
|
||
checkForUpdates() { | ||
ipcMain.handle('check-for-updates', async () => { | ||
ipcMain.handle("check-for-updates", async () => { | ||
try { | ||
const result = await autoUpdater.checkForUpdates() | ||
const result = await autoUpdater.checkForUpdates(); | ||
|
||
return result && result.updateInfo ? result?.updateInfo : result | ||
return result && result.updateInfo ? result?.updateInfo : result; | ||
} catch (err) { | ||
return Promise.reject(err) | ||
return Promise.reject(err); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
comfirmUpdate() { | ||
ipcMain.handle('confirm-update', () => { | ||
return autoUpdater.downloadUpdate() | ||
}) | ||
ipcMain.handle("confirm-update", () => { | ||
return autoUpdater.downloadUpdate(); | ||
}); | ||
} | ||
|
||
clearMainBindings() { | ||
autoUpdater.removeAllListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters