first commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { app } from 'electron'
|
||||
import electronUpdater, { type UpdateInfo, type ProgressInfo } from 'electron-updater'
|
||||
import { emit } from './events'
|
||||
|
||||
/**
|
||||
* Auto-update du launcher via electron-updater (provider "generic" pointant sur
|
||||
* une release Gitea à tag fixe, voir electron-builder.yml).
|
||||
*
|
||||
* UX : check au démarrage -> téléchargement en fond -> on relaie l'état vers le
|
||||
* renderer (bandeau). L'install effective se fait quand l'utilisateur clique
|
||||
* "Redémarrer pour installer" (quitAndInstallUpdate), ou à la fermeture.
|
||||
*/
|
||||
|
||||
// electron-updater est CommonJS : on récupère autoUpdater via le default export.
|
||||
const { autoUpdater } = electronUpdater
|
||||
|
||||
/** Re-check périodique (6 h) tant que le launcher reste ouvert. */
|
||||
const RECHECK_INTERVAL_MS = 6 * 60 * 60 * 1000
|
||||
|
||||
export function initUpdater(): void {
|
||||
// L'updater ne fonctionne que sur une app packagée (sauf dev-app-update.yml).
|
||||
if (!app.isPackaged) {
|
||||
console.info('[updater] dev non packagé : auto-update désactivé.')
|
||||
return
|
||||
}
|
||||
|
||||
// On gère l'install manuellement (bouton "Redémarrer"), mais on installe
|
||||
// quand même à la fermeture si la maj a été téléchargée.
|
||||
autoUpdater.autoDownload = true
|
||||
autoUpdater.autoInstallOnAppQuit = true
|
||||
|
||||
autoUpdater.on('checking-for-update', () => {
|
||||
emit.updateStatus({ state: 'checking' })
|
||||
})
|
||||
autoUpdater.on('update-available', (info: UpdateInfo) => {
|
||||
emit.updateStatus({ state: 'available', version: info.version })
|
||||
})
|
||||
autoUpdater.on('update-not-available', () => {
|
||||
emit.updateStatus({ state: 'none' })
|
||||
})
|
||||
autoUpdater.on('download-progress', (p: ProgressInfo) => {
|
||||
emit.updateStatus({ state: 'downloading', progress: p.percent / 100 })
|
||||
})
|
||||
autoUpdater.on('update-downloaded', (info: UpdateInfo) => {
|
||||
emit.updateStatus({ state: 'downloaded', version: info.version })
|
||||
})
|
||||
autoUpdater.on('error', (err: Error) => {
|
||||
console.error('[updater]', err)
|
||||
emit.updateStatus({ state: 'error', message: err.message })
|
||||
})
|
||||
|
||||
void autoUpdater.checkForUpdates()
|
||||
setInterval(() => void autoUpdater.checkForUpdates(), RECHECK_INTERVAL_MS)
|
||||
}
|
||||
|
||||
/** Quitte et installe la mise à jour téléchargée (appelé par le bouton UI). */
|
||||
export function quitAndInstallUpdate(): void {
|
||||
autoUpdater.quitAndInstall()
|
||||
}
|
||||
Reference in New Issue
Block a user