fix(update): verify and apply the actual latest version

This commit is contained in:
Sucukdeluxe
2026-08-21 07:39:37 +02:00
parent 4cebc6fefd
commit 6efdca6885
10 changed files with 154 additions and 41 deletions
+7 -11
View File
@@ -895,17 +895,13 @@ export class AppController {
this.lastUpdateCheckAt = Date.now();
}
return result;
}
public async installUpdate(onProgress?: (progress: UpdateInstallProgress) => void): Promise<UpdateInstallResult> {
const cacheAgeMs = Date.now() - this.lastUpdateCheckAt;
const cached = this.lastUpdateCheck && !this.lastUpdateCheck.error && cacheAgeMs <= 10 * 60 * 1000
? this.lastUpdateCheck
: undefined;
const result = await runInstallWithResume(
this.manager,
() => installLatestUpdate(this.settings.updateRepo, cached, onProgress)
);
}
public async installUpdate(onProgress?: (progress: UpdateInstallProgress) => void): Promise<UpdateInstallResult> {
const result = await runInstallWithResume(
this.manager,
() => installLatestUpdate(this.settings.updateRepo, undefined, onProgress)
);
if (result.started) {
this.lastUpdateCheck = null;
this.lastUpdateCheckAt = 0;
+24
View File
@@ -0,0 +1,24 @@
import fs from "node:fs";
import path from "node:path";
function normalizedVersion(value: unknown): string {
const version = String(value || "").trim();
return /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(version) ? version : "";
}
export function resolveRuntimeAppVersion(
fallbackVersion: string,
resourcesPath: string = (process as NodeJS.Process & { resourcesPath?: string }).resourcesPath || ""
): string {
if (resourcesPath) {
for (const relativePath of ["app.asar/package.json", "app/package.json"]) {
try {
const payload = JSON.parse(fs.readFileSync(path.join(resourcesPath, ...relativePath.split("/")), "utf8")) as { version?: unknown };
const version = normalizedVersion(payload.version);
if (version) return version;
} catch {
}
}
}
return normalizedVersion(fallbackVersion) || "0.0.0";
}
+4 -3
View File
@@ -1,11 +1,12 @@
import path from "node:path";
import os from "node:os";
import { AppSettings } from "../shared/types";
import { getProviderUsageDayKey } from "../shared/provider-daily-limits";
import packageJson from "../../package.json";
import { getProviderUsageDayKey } from "../shared/provider-daily-limits";
import packageJson from "../../package.json";
import { resolveRuntimeAppVersion } from "./app-version";
export const APP_NAME = "Multi Debrid Downloader";
export const APP_VERSION: string = packageJson.version;
export const APP_VERSION: string = resolveRuntimeAppVersion(packageJson.version);
export const API_BASE_URL = "https://api.real-debrid.com/rest/1.0";
export const DCRYPT_UPLOAD_URL = "https://dcrypt.it/decrypt/upload";
+22 -11
View File
@@ -1491,6 +1491,14 @@ export function shouldApplyUpdateCheckResult(
return completedGeneration === currentGeneration;
}
export function shouldOpenUpdatePrompt(
source: "manual" | "startup",
latestTag: string,
dismissedTag: string
): boolean {
return source === "manual" || !latestTag || latestTag !== dismissedTag;
}
export async function runLatestUpdateCheck(
generationRef: { current: number },
check: () => Promise<UpdateCheckResult>,
@@ -1523,6 +1531,7 @@ export function App(): ReactElement {
const [scheduleCountdown, setScheduleCountdown] = useState("");
const [runtimeNow, setRuntimeNow] = useState(() => Date.now());
const updateCheckGenerationRef = useRef(0);
const dismissedUpdateTagRef = useRef("");
const settingsDirtyRef = useRef(false);
const writeOnlySettingsDirtyRef = useRef(new Set<"archivePasswordList" | "notifyUrl">());
const archivePasswordLoadGenerationRef = useRef(0);
@@ -2589,7 +2598,15 @@ export function App(): ReactElement {
releaseNotes: changelogText
});
setUpdateInstallProgress(null);
setUpdateDialogOpen(true);
setUpdateDialogOpen(shouldOpenUpdatePrompt(source, result.latestTag, dismissedUpdateTagRef.current));
};
const dismissUpdatePrompt = (): void => {
if (availableUpdate?.latestTag) {
dismissedUpdateTagRef.current = availableUpdate.latestTag;
}
setUpdateDialogOpen(false);
setUpdateInstallProgress(null);
};
const installUpdate = async (): Promise<void> => {
@@ -5737,12 +5754,9 @@ export function App(): ReactElement {
available={Boolean(availableUpdate)}
currentVersion={availableUpdate?.currentVersion ?? appVersion}
latestTag={availableUpdate?.latestTag ?? ""}
onClose={() => {
setUpdateDialogOpen(false);
setUpdateInstallProgress(null);
}}
onClose={dismissUpdatePrompt}
onInstall={() => { void installUpdate(); }}
onLater={() => setUpdateDialogOpen(false)}
onLater={dismissUpdatePrompt}
onOpen={() => setUpdateDialogOpen(true)}
open={updateDialogOpen || updateInstallProgress !== null}
progress={updateInstallProgress ? {
@@ -6708,12 +6722,9 @@ export function App(): ReactElement {
available={Boolean(availableUpdate)}
currentVersion={availableUpdate?.currentVersion ?? appVersion}
latestTag={availableUpdate?.latestTag ?? ""}
onClose={() => {
setUpdateDialogOpen(false);
setUpdateInstallProgress(null);
}}
onClose={dismissUpdatePrompt}
onInstall={() => { void installUpdate(); }}
onLater={() => setUpdateDialogOpen(false)}
onLater={dismissUpdatePrompt}
onOpen={() => setUpdateDialogOpen(true)}
open={updateDialogOpen || updateInstallProgress !== null}
progress={updateInstallProgress ? {
+3 -3
View File
@@ -164,7 +164,7 @@
justify-content: center;
border: 0;
border-radius: 6px;
background: var(--ui-update);
background: var(--ui-success);
color: var(--ui-update-text);
cursor: pointer;
font-size: 14px;
@@ -174,8 +174,8 @@
}
.md-update-trigger:hover {
background: var(--ui-update-hover);
}
background: color-mix(in srgb, var(--ui-success) 82%, #000);
}
.md-update-trigger:focus-visible,
.md-update-dialog button:focus-visible,