Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

updateState.ts

52 lines1.6 KB

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;
20​
21export function nextStatusAfterDownloadFailure(
22 currentState: DesktopUpdateState,
23): DesktopUpdateState["status"] {
24 return currentState.availableVersion ? "available" : "error";
26​
27export function getCanRetryAfterDownloadFailure(currentState: DesktopUpdateState): boolean {
28 return currentState.availableVersion !== null;
30​
31export function getAutoUpdateDisabledReason(args: {
32 isDevelopment: boolean;
33 isPackaged: boolean;
34 platform: NodeJS.Platform;
35 appImage?: string | undefined;
36 disabledByEnv: boolean;
37 hasUpdateFeedConfig: boolean;
38}): string | null {
39 if (!args.hasUpdateFeedConfig) {
40 return "Automatic updates are not available because no update feed is configured.";
41 }
42 if (args.isDevelopment || !args.isPackaged) {
43 return "Automatic updates are only available in packaged production builds.";
44 }
45 if (args.disabledByEnv) {
46 return "Automatic updates are disabled by the T3CODE_DISABLE_AUTO_UPDATE setting.";
47 }
48 if (args.platform === "linux" && !args.appImage) {
49 return "Automatic updates on Linux require running the AppImage build.";
50 }
51 return null;