()
| 162 | } |
| 163 | |
| 164 | export function initAppUpdater(): void { |
| 165 | if (initialized) return |
| 166 | initialized = true |
| 167 | |
| 168 | if (!app.isPackaged) { |
| 169 | setUpdateState( |
| 170 | makeState({ |
| 171 | phase: 'unsupported', |
| 172 | message: 'Update checks only work in packaged ZenNotes builds.' |
| 173 | }) |
| 174 | ) |
| 175 | return |
| 176 | } |
| 177 | |
| 178 | updater = autoUpdater |
| 179 | updater.autoDownload = false |
| 180 | updater.autoInstallOnAppQuit = true |
| 181 | |
| 182 | updater.on('checking-for-update', () => { |
| 183 | setUpdateState( |
| 184 | nextStateFromInfo('checking', lastInfo, 'Checking GitHub releases for updates…') |
| 185 | ) |
| 186 | }) |
| 187 | updater.on('update-available', (info) => { |
| 188 | lastInfo = info |
| 189 | setUpdateState( |
| 190 | nextStateFromInfo( |
| 191 | 'available', |
| 192 | info, |
| 193 | `ZenNotes ${info.version} is available. Download it from inside the app.` |
| 194 | ) |
| 195 | ) |
| 196 | if (notifiedAvailableVersion !== info.version) { |
| 197 | notifiedAvailableVersion = info.version |
| 198 | showNativeUpdateNotification( |
| 199 | 'ZenNotes Update Available', |
| 200 | `ZenNotes ${info.version} is available. Click to open Settings and download it.` |
| 201 | ) |
| 202 | } |
| 203 | }) |
| 204 | updater.on('update-not-available', (info) => { |
| 205 | lastInfo = info |
| 206 | setUpdateState( |
| 207 | nextStateFromInfo( |
| 208 | 'not-available', |
| 209 | info, |
| 210 | `You're already on ZenNotes ${app.getVersion()}.` |
| 211 | ) |
| 212 | ) |
| 213 | }) |
| 214 | updater.on('download-progress', handleDownloadProgress) |
| 215 | updater.on('update-downloaded', (info) => { |
| 216 | lastInfo = info |
| 217 | downloadedFilePath = info.downloadedFile ?? null |
| 218 | // deb/rpm/pacman installs need root. electron-updater's on-quit auto-install |
| 219 | // shells out to a non-interactive `sudo`, which fails in a GUI session with |
| 220 | // no graphical askpass (issue #60). We install those formats ourselves from |
| 221 | // installAppUpdate(), so suppress the broken on-quit path for them. |
no test coverage detected