52 lines · 1.6 KB · TypeScript
RawDownload
import type { DesktopUpdateState } from "@t3tools/contracts"; export function shouldBroadcastDownloadProgress(  currentState: DesktopUpdateState,  nextPercent: number,): boolean {  if (currentState.status !== "downloading") {    return true;  }   const currentPercent = currentState.downloadPercent;  if (currentPercent === null) {    return true;  }   const previousStep = Math.floor(currentPercent / 10);  const nextStep = Math.floor(nextPercent / 10);  return nextStep !== previousStep || nextPercent === 100;} export function nextStatusAfterDownloadFailure(  currentState: DesktopUpdateState,): DesktopUpdateState["status"] {  return currentState.availableVersion ? "available" : "error";} export function getCanRetryAfterDownloadFailure(currentState: DesktopUpdateState): boolean {  return currentState.availableVersion !== null;} export function getAutoUpdateDisabledReason(args: {  isDevelopment: boolean;  isPackaged: boolean;  platform: NodeJS.Platform;  appImage?: string | undefined;  disabledByEnv: boolean;  hasUpdateFeedConfig: boolean;}): string | null {  if (!args.hasUpdateFeedConfig) {    return "Automatic updates are not available because no update feed is configured.";  }  if (args.isDevelopment || !args.isPackaged) {    return "Automatic updates are only available in packaged production builds.";  }  if (args.disabledByEnv) {    return "Automatic updates are disabled by the T3CODE_DISABLE_AUTO_UPDATE setting.";  }  if (args.platform === "linux" && !args.appImage) {    return "Automatic updates on Linux require running the AppImage build.";  }  return null;}