| author | |
| committer | |
| log | 5d9eb183123466fdf4b972fe33a4823d089370d3 |
| tree | a86e7082dd92fa30cf6b93ed6418b24f46d7d8ab |
| parent | abb84c09e3051db4745ba19a65e5d88319d473d2 |
| signature | Signed by PGP key B5690EEEBB952194 |
Co-authored-by: Julius Marminge <julius0216@outlook.com>3 files changed, 50 insertions(+), 11 deletions(-)
apps/desktop/src/main.ts+17-11| ... | ... | @@ -700,12 +700,15 @@ function dispatchMenuAction(action: string): void { |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | function handleCheckForUpdatesMenuClick(): void { |
| 703 | const hasUpdateFeedConfig = | |
| 704 | readAppUpdateYml() !== null || Boolean(process.env.T3CODE_DESKTOP_MOCK_UPDATES); | |
| 703 | 705 | const disabledReason = getAutoUpdateDisabledReason({ |
| 704 | 706 | isDevelopment, |
| 705 | 707 | isPackaged: app.isPackaged, |
| 706 | 708 | platform: process.platform, |
| 707 | 709 | appImage: process.env.APPIMAGE, |
| 708 | 710 | disabledByEnv: process.env.T3CODE_DISABLE_AUTO_UPDATE === "1", |
| 711 | hasUpdateFeedConfig, | |
| 709 | 712 | }); |
| 710 | 713 | if (disabledReason) { |
| 711 | 714 | console.info("[desktop-updater] Manual update check requested, but updates are disabled."); |
| ... | ... | @@ -942,6 +945,8 @@ function setUpdateState(patch: Partial<DesktopUpdateState>): void { |
| 942 | 945 | } |
| 943 | 946 | |
| 944 | 947 | function shouldEnableAutoUpdates(): boolean { |
| 948 | const hasUpdateFeedConfig = | |
| 949 | readAppUpdateYml() !== null || Boolean(process.env.T3CODE_DESKTOP_MOCK_UPDATES); | |
| 945 | 950 | return ( |
| 946 | 951 | getAutoUpdateDisabledReason({ |
| 947 | 952 | isDevelopment, |
| ... | ... | @@ -949,6 +954,7 @@ function shouldEnableAutoUpdates(): boolean { |
| 949 | 954 | platform: process.platform, |
| 950 | 955 | appImage: process.env.APPIMAGE, |
| 951 | 956 | disabledByEnv: process.env.T3CODE_DISABLE_AUTO_UPDATE === "1", |
| 957 | hasUpdateFeedConfig, | |
| 952 | 958 | }) === null |
| 953 | 959 | ); |
| 954 | 960 | } |
| ... | ... | @@ -1032,17 +1038,6 @@ async function installDownloadedUpdate(): Promise<{ accepted: boolean; completed |
| 1032 | 1038 | } |
| 1033 | 1039 | |
| 1034 | 1040 | function configureAutoUpdater(): void { |
| 1035 | const enabled = shouldEnableAutoUpdates(); | |
| 1036 | setUpdateState({ | |
| 1037 | ...createInitialDesktopUpdateState(app.getVersion(), desktopRuntimeInfo), | |
| 1038 | enabled, | |
| 1039 | status: enabled ? "idle" : "disabled", | |
| 1040 | }); | |
| 1041 | if (!enabled) { | |
| 1042 | return; | |
| 1043 | } | |
| 1044 | updaterConfigured = true; | |
| 1045 | ||
| 1046 | 1041 | const githubToken = |
| 1047 | 1042 | process.env.T3CODE_DESKTOP_UPDATE_GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim() || ""; |
| 1048 | 1043 | if (githubToken) { |
| ... | ... | @@ -1067,6 +1062,17 @@ function configureAutoUpdater(): void { |
| 1067 | 1062 | }); |
| 1068 | 1063 | } |
| 1069 | 1064 | |
| 1065 | const enabled = shouldEnableAutoUpdates(); | |
| 1066 | setUpdateState({ | |
| 1067 | ...createInitialDesktopUpdateState(app.getVersion(), desktopRuntimeInfo), | |
| 1068 | enabled, | |
| 1069 | status: enabled ? "idle" : "disabled", | |
| 1070 | }); | |
| 1071 | if (!enabled) { | |
| 1072 | return; | |
| 1073 | } | |
| 1074 | updaterConfigured = true; | |
| 1075 | ||
| 1070 | 1076 | autoUpdater.autoDownload = false; |
| 1071 | 1077 | autoUpdater.autoInstallOnAppQuit = false; |
| 1072 | 1078 | // Keep alpha branding, but force all installs onto the stable update track. |
apps/desktop/src/updateState.test.ts+29| ... | ... | @@ -71,10 +71,37 @@ describe("getAutoUpdateDisabledReason", () => { |
| 71 | 71 | platform: "darwin", |
| 72 | 72 | appImage: undefined, |
| 73 | 73 | disabledByEnv: false, |
| 74 | hasUpdateFeedConfig: true, | |
| 74 | 75 | }), |
| 75 | 76 | ).toContain("packaged production builds"); |
| 76 | 77 | }); |
| 77 | 78 | |
| 79 | it("reports packaged local builds without an update feed as disabled", () => { | |
| 80 | expect( | |
| 81 | getAutoUpdateDisabledReason({ | |
| 82 | isDevelopment: false, | |
| 83 | isPackaged: true, | |
| 84 | platform: "darwin", | |
| 85 | appImage: undefined, | |
| 86 | disabledByEnv: false, | |
| 87 | hasUpdateFeedConfig: false, | |
| 88 | }), | |
| 89 | ).toContain("no update feed"); | |
| 90 | }); | |
| 91 | ||
| 92 | it("allows packaged builds with an update feed", () => { | |
| 93 | expect( | |
| 94 | getAutoUpdateDisabledReason({ | |
| 95 | isDevelopment: false, | |
| 96 | isPackaged: true, | |
| 97 | platform: "darwin", | |
| 98 | appImage: undefined, | |
| 99 | disabledByEnv: false, | |
| 100 | hasUpdateFeedConfig: true, | |
| 101 | }), | |
| 102 | ).toBeNull(); | |
| 103 | }); | |
| 104 | ||
| 78 | 105 | it("reports env-disabled auto updates", () => { |
| 79 | 106 | expect( |
| 80 | 107 | getAutoUpdateDisabledReason({ |
| ... | ... | @@ -83,6 +110,7 @@ describe("getAutoUpdateDisabledReason", () => { |
| 83 | 110 | platform: "darwin", |
| 84 | 111 | appImage: undefined, |
| 85 | 112 | disabledByEnv: true, |
| 113 | hasUpdateFeedConfig: true, | |
| 86 | 114 | }), |
| 87 | 115 | ).toContain("T3CODE_DISABLE_AUTO_UPDATE"); |
| 88 | 116 | }); |
| ... | ... | @@ -95,6 +123,7 @@ describe("getAutoUpdateDisabledReason", () => { |
| 95 | 123 | platform: "linux", |
| 96 | 124 | appImage: undefined, |
| 97 | 125 | disabledByEnv: false, |
| 126 | hasUpdateFeedConfig: true, | |
| 98 | 127 | }), |
| 99 | 128 | ).toContain("AppImage"); |
| 100 | 129 | }); |
apps/desktop/src/updateState.ts+4| ... | ... | @@ -34,7 +34,11 @@ export function getAutoUpdateDisabledReason(args: { |
| 34 | 34 | platform: NodeJS.Platform; |
| 35 | 35 | appImage?: string | undefined; |
| 36 | 36 | disabledByEnv: boolean; |
| 37 | hasUpdateFeedConfig: boolean; | |
| 37 | 38 | }): string | null { |
| 39 | if (!args.hasUpdateFeedConfig) { | |
| 40 | return "Automatic updates are not available because no update feed is configured."; | |
| 41 | } | |
| 38 | 42 | if (args.isDevelopment || !args.isPackaged) { |
| 39 | 43 | return "Automatic updates are only available in packaged production builds."; |
| 40 | 44 | } |