update dependencies
This commit is contained in:
1 parent
3de6903594
commit
d251c7914e
22 files changed
+3722
-395
No files matched your search
+41
-41
@@ -1,76 +1,76 @@
|
||||
import { app, ipcMain } from "electron";
|
||||
import { type ProgressInfo, type UpdateDownloadedEvent, autoUpdater } from "electron-updater";
|
||||
import { app, ipcMain } from 'electron'
|
||||
import { createRequire } from 'node:module'
|
||||
import type {
|
||||
ProgressInfo,
|
||||
UpdateDownloadedEvent,
|
||||
UpdateInfo,
|
||||
} from 'electron-updater'
|
||||
|
||||
const { autoUpdater } = createRequire(import.meta.url)('electron-updater');
|
||||
|
||||
export function update(win: Electron.BrowserWindow) {
|
||||
|
||||
// When set to false, the update download will be triggered through the API
|
||||
autoUpdater.autoDownload = false;
|
||||
autoUpdater.disableWebInstaller = false;
|
||||
autoUpdater.allowDowngrade = false;
|
||||
autoUpdater.autoDownload = false
|
||||
autoUpdater.disableWebInstaller = false
|
||||
autoUpdater.allowDowngrade = false
|
||||
|
||||
// start check
|
||||
autoUpdater.on("checking-for-update", function () {});
|
||||
autoUpdater.on('checking-for-update', function () { })
|
||||
// update available
|
||||
autoUpdater.on("update-available", (arg) => {
|
||||
win.webContents.send("update-can-available", {
|
||||
update: true,
|
||||
version: app.getVersion(),
|
||||
newVersion: arg?.version,
|
||||
});
|
||||
});
|
||||
autoUpdater.on('update-available', (arg: UpdateInfo) => {
|
||||
win.webContents.send('update-can-available', { update: true, version: app.getVersion(), newVersion: arg?.version })
|
||||
})
|
||||
// update not available
|
||||
autoUpdater.on("update-not-available", (arg) => {
|
||||
win.webContents.send("update-can-available", {
|
||||
update: false,
|
||||
version: app.getVersion(),
|
||||
newVersion: arg?.version,
|
||||
});
|
||||
});
|
||||
autoUpdater.on('update-not-available', (arg: UpdateInfo) => {
|
||||
win.webContents.send('update-can-available', { update: false, version: app.getVersion(), newVersion: arg?.version })
|
||||
})
|
||||
|
||||
// Checking for updates
|
||||
ipcMain.handle("check-update", async () => {
|
||||
ipcMain.handle('check-update', async () => {
|
||||
if (!app.isPackaged) {
|
||||
const error = new Error("The update feature is only available after the package.");
|
||||
return { message: error.message, error };
|
||||
const error = new Error('The update feature is only available after the package.')
|
||||
return { message: error.message, error }
|
||||
}
|
||||
|
||||
try {
|
||||
return await autoUpdater.checkForUpdatesAndNotify();
|
||||
return await autoUpdater.checkForUpdatesAndNotify()
|
||||
} catch (error) {
|
||||
return { message: "Network error", error };
|
||||
return { message: 'Network error', error }
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
// Start downloading and feedback on progress
|
||||
ipcMain.handle("start-download", (event) => {
|
||||
ipcMain.handle('start-download', (event: Electron.IpcMainInvokeEvent) => {
|
||||
startDownload(
|
||||
(error, progressInfo) => {
|
||||
if (error) {
|
||||
// feedback download error message
|
||||
event.sender.send("update-error", { message: error.message, error });
|
||||
event.sender.send('update-error', { message: error.message, error })
|
||||
} else {
|
||||
// feedback update progress message
|
||||
event.sender.send("download-progress", progressInfo);
|
||||
event.sender.send('download-progress', progressInfo)
|
||||
}
|
||||
},
|
||||
() => {
|
||||
// feedback update downloaded message
|
||||
event.sender.send("update-downloaded");
|
||||
event.sender.send('update-downloaded')
|
||||
}
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
|
||||
// Install now
|
||||
ipcMain.handle("quit-and-install", () => {
|
||||
autoUpdater.quitAndInstall(false, true);
|
||||
});
|
||||
ipcMain.handle('quit-and-install', () => {
|
||||
autoUpdater.quitAndInstall(false, true)
|
||||
})
|
||||
}
|
||||
|
||||
function startDownload(
|
||||
callback: (error: Error | null, info: ProgressInfo) => void,
|
||||
complete: (event: UpdateDownloadedEvent) => void
|
||||
callback: (error: Error | null, info: ProgressInfo | null) => void,
|
||||
complete: (event: UpdateDownloadedEvent) => void,
|
||||
) {
|
||||
autoUpdater.on("download-progress", (info) => callback(null, info));
|
||||
autoUpdater.on("error", (error) => callback(error, null!));
|
||||
autoUpdater.on("update-downloaded", complete);
|
||||
autoUpdater.downloadUpdate();
|
||||
autoUpdater.on('download-progress', (info: ProgressInfo) => callback(null, info))
|
||||
autoUpdater.on('error', (error: Error) => callback(error, null))
|
||||
autoUpdater.on('update-downloaded', complete)
|
||||
autoUpdater.downloadUpdate()
|
||||
}
|
||||
Reference in new issue
Block a user