|
| 1 | +import express from "express"; |
| 2 | +import { autoUpdater } from "electron-updater"; |
| 3 | +import type { ProgressInfo, UpdateDownloadedEvent } from "electron-updater"; |
| 4 | +import { notifyLaravel } from "../utils.js"; |
| 5 | + |
| 6 | +const router = express.Router(); |
| 7 | + |
| 8 | +router.post("/check-for-updates", (req, res) => { |
| 9 | + autoUpdater.checkForUpdates(); |
| 10 | + res.sendStatus(200); |
| 11 | +}); |
| 12 | + |
| 13 | +router.post("/quit-and-install", (req, res) => { |
| 14 | + autoUpdater.quitAndInstall(); |
| 15 | + res.sendStatus(200); |
| 16 | +}); |
| 17 | + |
| 18 | +autoUpdater.addListener("checking-for-update", () => { |
| 19 | + notifyLaravel("events", { |
| 20 | + event: `\\Native\\Laravel\\Events\\AutoUpdater\\CheckingForUpdate`, |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +autoUpdater.addListener("update-available", () => { |
| 25 | + notifyLaravel("events", { |
| 26 | + event: `\\Native\\Laravel\\Events\\AutoUpdater\\UpdateAvailable`, |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +autoUpdater.addListener("update-not-available", () => { |
| 31 | + notifyLaravel("events", { |
| 32 | + event: `\\Native\\Laravel\\Events\\AutoUpdater\\UpdateNotAvailable`, |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +autoUpdater.addListener("error", (error) => { |
| 37 | + notifyLaravel("events", { |
| 38 | + event: `\\Native\\Laravel\\Events\\AutoUpdater\\Error`, |
| 39 | + payload: { |
| 40 | + error: error, |
| 41 | + }, |
| 42 | + }); |
| 43 | +}); |
| 44 | + |
| 45 | +autoUpdater.addListener("download-progress", (progressInfo: ProgressInfo) => { |
| 46 | + notifyLaravel("events", { |
| 47 | + event: `\\Native\\Laravel\\Events\\AutoUpdater\\DownloadProgress`, |
| 48 | + payload: { |
| 49 | + total: progressInfo.total, |
| 50 | + delta: progressInfo.delta, |
| 51 | + transferred: progressInfo.transferred, |
| 52 | + percent: progressInfo.percent, |
| 53 | + bytesPerSecond: progressInfo.bytesPerSecond, |
| 54 | + }, |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +autoUpdater.addListener("update-downloaded", (event: UpdateDownloadedEvent) => { |
| 59 | + notifyLaravel("events", { |
| 60 | + event: `\\Native\\Laravel\\Events\\AutoUpdater\\UpdateDownloaded`, |
| 61 | + payload: { |
| 62 | + version: event.version, |
| 63 | + downloadedFile: event.downloadedFile, |
| 64 | + releaseDate: event.releaseDate, |
| 65 | + releaseNotes: event.releaseNotes, |
| 66 | + releaseName: event.releaseName, |
| 67 | + }, |
| 68 | + }); |
| 69 | +}); |
| 70 | + |
| 71 | +export default router; |
0 commit comments