@@ -7,8 +7,11 @@ Please see LICENSE files in the repository root for full details.
77
88import { app , autoUpdater , ipcMain } from "electron" ;
99import fs from "node:fs/promises" ;
10+ import os from "node:os" ;
1011
1112import { getSquirrelExecutable } from "./squirrelhooks.js" ;
13+ import { _t } from "./language-helper.js" ;
14+ import { initialisePromise } from "./ipc.js" ;
1215
1316const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000 ;
1417const INITIAL_UPDATE_DELAY_MS = 30 * 1000 ;
@@ -69,7 +72,8 @@ async function pollForUpdates(): Promise<void> {
6972}
7073
7174export async function start ( updateBaseUrl : string ) : Promise < void > {
72- if ( ! ( await available ( updateBaseUrl ) ) ) return ;
75+ if ( ! ( await available ( ) ) ) return ;
76+ console . log ( `Starting auto update with base URL: ${ updateBaseUrl } ` ) ;
7377 if ( ! updateBaseUrl . endsWith ( "/" ) ) {
7478 updateBaseUrl = updateBaseUrl + "/" ;
7579 }
@@ -111,24 +115,58 @@ export async function start(updateBaseUrl: string): Promise<void> {
111115 }
112116}
113117
114- async function available ( updateBaseUrl ?: string ) : Promise < boolean > {
118+ /**
119+ * Check if auto update is available on this platform.
120+ * Has a side effect of firing showToast on EOL platforms so must only be called once!
121+ * @returns True if auto update is available
122+ */
123+ async function available ( ) : Promise < boolean > {
115124 if ( process . platform === "linux" ) {
116125 // Auto update is not supported on Linux
117- console . log ( "Auto update not supported on this platform" ) ;
126+ console . warn ( "Auto update not supported on this platform" ) ;
118127 return false ;
119128 }
120129
121130 if ( process . platform === "win32" ) {
122131 try {
123132 await fs . access ( getSquirrelExecutable ( ) ) ;
124133 } catch {
125- console . log ( "Squirrel not found, auto update not supported" ) ;
134+ console . warn ( "Squirrel not found, auto update not supported" ) ;
126135 return false ;
127136 }
128137 }
129138
130139 // Otherwise we're either on macOS or Windows with Squirrel
131- return ! ! updateBaseUrl ;
140+ if ( process . platform === "darwin" ) {
141+ // OS release returns the Darwin kernel version, not the macOS version, see
142+ // https://en.wikipedia.org/wiki/Darwin_(operating_system)#Release_history to interpret it
143+ const release = os . release ( ) ;
144+ const major = parseInt ( release . split ( "." ) [ 0 ] , 10 ) ;
145+
146+ if ( major < 21 ) {
147+ // If the macOS version is too old for modern Electron support then disable auto update to prevent the app updating and bricking itself.
148+ // The oldest macOS version supported by Chromium/Electron 38 is Monterey (12.x) which started with Darwin 21.0
149+ initialisePromise . then ( ( ) => {
150+ ipcMain . emit ( "showToast" , {
151+ title : _t ( "eol|title" ) ,
152+ description : _t ( "eol|no_more_updates" , { brand : global . trayConfig . brand } ) ,
153+ } ) ;
154+ } ) ;
155+ console . warn ( "Auto update not supported, macOS version too old" ) ;
156+ return false ;
157+ } else if ( major < 22 ) {
158+ // If the macOS version is EOL then show a warning message.
159+ // The oldest macOS version still supported by Apple is Ventura (13.x) which started with Darwin 22.0
160+ initialisePromise . then ( ( ) => {
161+ ipcMain . emit ( "showToast" , {
162+ title : _t ( "eol|title" ) ,
163+ description : _t ( "eol|warning" , { brand : global . trayConfig . brand } ) ,
164+ } ) ;
165+ } ) ;
166+ }
167+ }
168+
169+ return true ;
132170}
133171
134172ipcMain . on ( "install_update" , installUpdate ) ;
0 commit comments