@@ -210,15 +210,19 @@ function parseAppUpdateYml(raw: string): Effect.Effect<Option.Option<AppUpdateYm
210210 ) ;
211211}
212212
213+ /** Idle state when updates run, or a disabled state that carries the reason
214+ in `message` so clients can show it instead of "up to date". */
213215function createBaseUpdateState (
214216 channel : DesktopUpdateChannel ,
215- enabled : boolean ,
217+ disabledReason : Option . Option < string > ,
216218 environment : DesktopEnvironment . DesktopEnvironment [ "Service" ] ,
217219) : DesktopUpdateState {
220+ const enabled = Option . isNone ( disabledReason ) ;
218221 return {
219222 ...createInitialDesktopUpdateState ( environment . appVersion , environment . runtimeInfo , channel ) ,
220223 enabled,
221224 status : enabled ? "idle" : "disabled" ,
225+ message : Option . getOrNull ( disabledReason ) ,
222226 } ;
223227}
224228
@@ -244,11 +248,36 @@ function shouldBroadcastDownloadProgress(
244248 return nextStep !== previousStep || nextPercent === 100 ;
245249}
246250
247- function getAutoUpdateDisabledReason ( args : {
251+ /**
252+ * How a Linux install that is not running as an AppImage gets updates. The
253+ * marker is the electron-builder `package-type` file next to the app
254+ * resources; the deb and rpm builds write it, and the AUR PKGBUILDs write
255+ * `pacman`. No marker means an extracted AppImage or an unknown layout.
256+ */
257+ function getLinuxPackageUpdateReason ( packageType : string | null ) : string {
258+ switch ( packageType ) {
259+ case null :
260+ return "Automatic updates on Linux require running the AppImage build." ;
261+ case "deb" :
262+ return "T3 Code was installed with apt. Update it with: sudo apt update && sudo apt upgrade" ;
263+ case "rpm" :
264+ return "T3 Code was installed with dnf. Update it with: sudo dnf upgrade" ;
265+ case "pacman" :
266+ return "T3 Code was installed from the AUR. Update it with your AUR helper, for example: yay -Syu" ;
267+ default :
268+ return "T3 Code was installed by your system package manager. Update it with that package manager." ;
269+ }
270+ }
271+
272+ /** Why automatic updates are off, or null when they can run. Reasons are
273+ checked in priority order; `linuxPackageType` only matters on Linux
274+ without `APPIMAGE`. Exported for tests. */
275+ export function getAutoUpdateDisabledReason ( args : {
248276 isDevelopment : boolean ;
249277 isPackaged : boolean ;
250278 platform : NodeJS . Platform ;
251279 appImage ?: string | undefined ;
280+ linuxPackageType : string | null ;
252281 disabledByEnv : boolean ;
253282 hasUpdateFeedConfig : boolean ;
254283} ) : string | null {
@@ -262,7 +291,7 @@ function getAutoUpdateDisabledReason(args: {
262291 return "Automatic updates are disabled by the T3CODE_DISABLE_AUTO_UPDATE setting." ;
263292 }
264293 if ( args . platform === "linux" && ! args . appImage ) {
265- return "Automatic updates on Linux require running the AppImage build." ;
294+ return getLinuxPackageUpdateReason ( args . linuxPackageType ) ;
266295 }
267296 return null ;
268297}
@@ -335,14 +364,29 @@ export const make = Effect.gen(function* () {
335364 Effect . map ( ( appUpdateYmlConfig ) => Option . isSome ( appUpdateYmlConfig ) || config . mockUpdates ) ,
336365 ) ;
337366
367+ // Only Linux package installs carry the marker. A missing, unreadable, or
368+ // blank file means no marker.
369+ const readLinuxPackageType : Effect . Effect < Option . Option < string > > =
370+ environment . platform === "linux" && environment . isPackaged
371+ ? fileSystem
372+ . readFileString ( environment . path . join ( environment . resourcesPath , "package-type" ) )
373+ . pipe (
374+ Effect . map ( ( raw ) => raw . trim ( ) ) ,
375+ Effect . option ,
376+ Effect . map ( Option . filter ( ( packageType ) => packageType . length > 0 ) ) ,
377+ )
378+ : Effect . succeedNone ;
379+
338380 const resolveDisabledReason = Effect . gen ( function * ( ) {
339381 const hasFeedConfig = yield * hasUpdateFeedConfig ;
382+ const linuxPackageType = yield * readLinuxPackageType ;
340383 return Option . fromNullishOr (
341384 getAutoUpdateDisabledReason ( {
342385 isDevelopment : environment . isDevelopment ,
343386 isPackaged : environment . isPackaged ,
344387 platform : environment . platform ,
345388 appImage : Option . getOrUndefined ( config . appImagePath ) ,
389+ linuxPackageType : Option . getOrNull ( linuxPackageType ) ,
346390 disabledByEnv : config . disableAutoUpdate ,
347391 hasUpdateFeedConfig : hasFeedConfig ,
348392 } ) ,
@@ -389,8 +433,6 @@ export const make = Effect.gen(function* () {
389433 } ) ;
390434 } ) ;
391435
392- const shouldEnableAutoUpdates = resolveDisabledReason . pipe ( Effect . map ( Option . isNone ) ) ;
393-
394436 const checkForUpdates = Effect . fn ( "desktop.updates.checkForUpdates" ) ( function * (
395437 reason : string ,
396438 actionReservation : "acquire" | "held" = "acquire" ,
@@ -878,9 +920,9 @@ export const make = Effect.gen(function* () {
878920 }
879921
880922 const settings = yield * desktopSettings . get ;
881- const enabled = yield * shouldEnableAutoUpdates ;
882- yield * setState ( createBaseUpdateState ( settings . updateChannel , enabled , environment ) ) ;
883- if ( ! enabled ) {
923+ const disabledReason = yield * resolveDisabledReason ;
924+ yield * setState ( createBaseUpdateState ( settings . updateChannel , disabledReason , environment ) ) ;
925+ if ( Option . isSome ( disabledReason ) ) {
884926 return ;
885927 }
886928 yield * Ref . set ( updaterConfiguredRef , true ) ;
@@ -949,10 +991,10 @@ export const make = Effect.gen(function* () {
949991 ) ,
950992 ) ;
951993
952- const enabled = yield * shouldEnableAutoUpdates ;
953- yield * setState ( createBaseUpdateState ( nextChannel , enabled , environment ) ) ;
994+ const disabledReason = yield * resolveDisabledReason ;
995+ yield * setState ( createBaseUpdateState ( nextChannel , disabledReason , environment ) ) ;
954996
955- if ( ! enabled || ! ( yield * Ref . get ( updaterConfiguredRef ) ) ) {
997+ if ( Option . isSome ( disabledReason ) || ! ( yield * Ref . get ( updaterConfiguredRef ) ) ) {
956998 return yield * Ref . get ( updateStateRef ) ;
957999 }
9581000
0 commit comments