mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-06 05:32:06 +00:00
feat: Implement update management refactor with new dialog and settings handling
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { BrowserWindow, dialog } from "electron";
|
||||
import type { MessageBoxOptions } from "electron";
|
||||
|
||||
import { ReleaseUpdate } from "./update-utils";
|
||||
|
||||
export type DownloadUpdateChoice = "download" | "open-release" | "dismiss";
|
||||
|
||||
export async function askToDownloadUpdate(
|
||||
update: ReleaseUpdate,
|
||||
releasePageUrl: string | undefined,
|
||||
parentWindow: BrowserWindow | null,
|
||||
): Promise<DownloadUpdateChoice> {
|
||||
const result = await showMessageBox(parentWindow, {
|
||||
type: "info",
|
||||
title: "Actualización disponible",
|
||||
message: `Scoreko ${update.version} está disponible.`,
|
||||
detail: "Puedes descargarla ahora o seguir usando esta versión.",
|
||||
buttons: releasePageUrl ? ["Descargar", "Ver release", "Ahora no"] : ["Descargar", "Ahora no"],
|
||||
defaultId: 0,
|
||||
cancelId: releasePageUrl ? 2 : 1,
|
||||
});
|
||||
|
||||
if (releasePageUrl && result.response === 1) {
|
||||
return "open-release";
|
||||
}
|
||||
|
||||
return result.response === 0 ? "download" : "dismiss";
|
||||
}
|
||||
|
||||
export async function askToInstallUpdate(update: ReleaseUpdate, parentWindow: BrowserWindow | null): Promise<boolean> {
|
||||
const result = await showMessageBox(parentWindow, {
|
||||
type: "question",
|
||||
title: "Actualización descargada",
|
||||
message: `Scoreko ${update.version} se ha descargado.`,
|
||||
detail: "Para instalarla se cerrará Scoreko y se abrirá el instalador.",
|
||||
buttons: ["Instalar y cerrar", "Luego"],
|
||||
defaultId: 0,
|
||||
cancelId: 1,
|
||||
});
|
||||
|
||||
return result.response === 0;
|
||||
}
|
||||
|
||||
function showMessageBox(parentWindow: BrowserWindow | null, options: MessageBoxOptions) {
|
||||
return parentWindow ? dialog.showMessageBox(parentWindow, options) : dialog.showMessageBox(options);
|
||||
}
|
||||
Reference in New Issue
Block a user