Open History to see the last commit
1import type { DesktopUpdateState } from "@t3tools/contracts";
2
3export function shouldBroadcastDownloadProgress(
4 currentState: DesktopUpdateState,
5 nextPercent: number,
6): boolean {
7 if (currentState.status !== "downloading") {
8 return true;
9 }
10
11 const currentPercent = currentState.downloadPercent;
12 if (currentPercent === null) {
13 return true;
14 }
15
16 const previousStep = Math.floor(currentPercent / 10);
17 const nextStep = Math.floor(nextPercent / 10);
18 return nextStep !== previousStep || nextPercent === 100;
19}
20
21export function nextStatusAfterDownloadFailure(
22 currentState: DesktopUpdateState,
23): DesktopUpdateState["status"] {
24 return currentState.availableVersion ? "available" : "error";
25}
26
27export function getCanRetryAfterDownloadFailure(currentState: DesktopUpdateState): boolean {
28 return currentState.availableVersion !== null;
29}
30
31export function getAutoUpdateDisabledReason(args: {
32 isDevelopment: boolean;
33 isPackaged: boolean;
34 platform: NodeJS.Platform;
35 appImage?: string | undefined;
36 disabledByEnv: boolean;
37}): string | null {
38 if (args.isDevelopment || !args.isPackaged) {
39 return "Automatic updates are only available in packaged production builds.";
40 }
41 if (args.disabledByEnv) {
42 return "Automatic updates are disabled by the T3CODE_DISABLE_AUTO_UPDATE setting.";
43 }
44 if (args.platform === "linux" && !args.appImage) {
45 return "Automatic updates on Linux require running the AppImage build.";
46 }
47 return null;
48}