- Extract desktop updater state transitions into `updateMachine` reducers with tests
- Extend update IPC/contracts to return `{accepted, completed, state}` for download/install actions
- Add web sidebar update-button logic for retryable download/install errors and clearer tooltips
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
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;
|
|
}): string | null {
|
|
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;
|
|
}
|