Updater: show update dialog instead of forcing updates (#1184)
This commit is contained in:
+1
-5
@@ -4,11 +4,11 @@
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import "./updater";
|
||||
import "./ipc";
|
||||
import "./userAssets";
|
||||
|
||||
import { app, BrowserWindow, nativeTheme } from "electron";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
|
||||
import { checkCommandLineForHelpOrVersion } from "./cli";
|
||||
import { DATA_DIR } from "./constants";
|
||||
@@ -22,10 +22,6 @@ import { isDeckGameMode } from "./utils/steamOS";
|
||||
|
||||
checkCommandLineForHelpOrVersion();
|
||||
|
||||
if (!IS_DEV) {
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
}
|
||||
|
||||
console.log("Vesktop v" + app.getVersion());
|
||||
|
||||
// Make the Vencord files use our DATA_DIR
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
||||
* Copyright (c) 2025 Vendicated and Vesktop contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { app, BrowserWindow, ipcMain } from "electron";
|
||||
import { autoUpdater, UpdateInfo } from "electron-updater";
|
||||
import { join } from "path";
|
||||
import { IpcEvents, UpdaterIpcEvents } from "shared/IpcEvents";
|
||||
import { VIEW_DIR } from "shared/paths";
|
||||
import { Millis } from "shared/utils/millis";
|
||||
|
||||
import { State } from "./settings";
|
||||
import { handle } from "./utils/ipcWrappers";
|
||||
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
||||
|
||||
let updaterWindow: BrowserWindow | null = null;
|
||||
|
||||
autoUpdater.on("update-available", update => {
|
||||
if (State.store.updater?.ignoredVersion === update.version) return;
|
||||
if ((State.store.updater?.snoozeUntil ?? 0) > Date.now()) return;
|
||||
|
||||
openUpdater(update);
|
||||
});
|
||||
|
||||
autoUpdater.on("update-downloaded", () => setTimeout(() => autoUpdater.quitAndInstall(), 100));
|
||||
autoUpdater.on("download-progress", p =>
|
||||
updaterWindow?.webContents.send(UpdaterIpcEvents.DOWNLOAD_PROGRESS, p.percent)
|
||||
);
|
||||
autoUpdater.on("error", err => updaterWindow?.webContents.send(UpdaterIpcEvents.ERROR, err.message));
|
||||
|
||||
autoUpdater.autoDownload = false;
|
||||
autoUpdater.autoInstallOnAppQuit = false;
|
||||
autoUpdater.fullChangelog = true;
|
||||
|
||||
const isOutdated = autoUpdater.checkForUpdates().then(res => Boolean(res?.isUpdateAvailable));
|
||||
|
||||
handle(IpcEvents.UPDATER_IS_OUTDATED, () => isOutdated);
|
||||
handle(IpcEvents.UPDATER_OPEN, async () => {
|
||||
const res = await autoUpdater.checkForUpdates();
|
||||
if (res?.isUpdateAvailable && res.updateInfo) openUpdater(res.updateInfo);
|
||||
});
|
||||
|
||||
function openUpdater(update: UpdateInfo) {
|
||||
updaterWindow = new BrowserWindow({
|
||||
title: "Vesktop Updater",
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, "updaterPreload.js")
|
||||
},
|
||||
minHeight: 400,
|
||||
minWidth: 750
|
||||
});
|
||||
makeLinksOpenExternally(updaterWindow);
|
||||
|
||||
handle(UpdaterIpcEvents.GET_DATA, () => ({ update, version: app.getVersion() }));
|
||||
handle(UpdaterIpcEvents.INSTALL, async () => {
|
||||
await autoUpdater.downloadUpdate();
|
||||
});
|
||||
handle(UpdaterIpcEvents.SNOOZE_UPDATE, () => {
|
||||
State.store.updater ??= {};
|
||||
State.store.updater.snoozeUntil = Date.now() + 1 * Millis.DAY;
|
||||
updaterWindow?.close();
|
||||
});
|
||||
handle(UpdaterIpcEvents.IGNORE_UPDATE, () => {
|
||||
State.store.updater ??= {};
|
||||
State.store.updater.ignoredVersion = update.version;
|
||||
updaterWindow?.close();
|
||||
});
|
||||
|
||||
updaterWindow.on("closed", () => {
|
||||
ipcMain.removeHandler(UpdaterIpcEvents.GET_DATA);
|
||||
ipcMain.removeHandler(UpdaterIpcEvents.INSTALL);
|
||||
ipcMain.removeHandler(UpdaterIpcEvents.SNOOZE_UPDATE);
|
||||
ipcMain.removeHandler(UpdaterIpcEvents.IGNORE_UPDATE);
|
||||
updaterWindow = null;
|
||||
});
|
||||
|
||||
updaterWindow.loadFile(join(VIEW_DIR, "updater.html"));
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import { ipcMain, IpcMainEvent, IpcMainInvokeEvent, WebFrameMain } from "electron";
|
||||
import { DISCORD_HOSTNAMES } from "main/constants";
|
||||
import { IpcEvents } from "shared/IpcEvents";
|
||||
import { IpcEvents, UpdaterIpcEvents } from "shared/IpcEvents";
|
||||
|
||||
export function validateSender(frame: WebFrameMain | null, event: string) {
|
||||
if (!frame) throw new Error(`ipc[${event}]: No sender frame`);
|
||||
@@ -25,14 +25,14 @@ export function validateSender(frame: WebFrameMain | null, event: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export function handleSync(event: IpcEvents, cb: (e: IpcMainEvent, ...args: any[]) => any) {
|
||||
export function handleSync(event: IpcEvents | UpdaterIpcEvents, cb: (e: IpcMainEvent, ...args: any[]) => any) {
|
||||
ipcMain.on(event, (e, ...args) => {
|
||||
validateSender(e.senderFrame, event);
|
||||
e.returnValue = cb(e, ...args);
|
||||
});
|
||||
}
|
||||
|
||||
export function handle(event: IpcEvents, cb: (e: IpcMainInvokeEvent, ...args: any[]) => any) {
|
||||
export function handle(event: IpcEvents | UpdaterIpcEvents, cb: (e: IpcMainInvokeEvent, ...args: any[]) => any) {
|
||||
ipcMain.handle(event, (e, ...args) => {
|
||||
validateSender(e.senderFrame, event);
|
||||
return cb(e, ...args);
|
||||
|
||||
Reference in New Issue
Block a user