Skip to content

Commit

Permalink
feat: Add log for electron updater.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu committed Aug 2, 2023
1 parent 9c2e70c commit d0f3890
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/neuron-wallet/src/controllers/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { autoUpdater, UpdateInfo, CancellationToken } from 'electron-updater'
import { autoUpdater, UpdateInfo, CancellationToken, ProgressInfo } from 'electron-updater'
import AppUpdaterSubject, { AppUpdater } from '../models/subjects/app-updater'
import logger from '../utils/logger'

export default class UpdateController {
static isChecking = false // One instance is already running and checking
Expand All @@ -8,8 +9,11 @@ export default class UpdateController {

static lastNotifyInfo: AppUpdater

static updatePackageSize: number = 0

constructor(check: boolean = true) {
autoUpdater.autoDownload = false
autoUpdater.logger = logger

if (check && !UpdateController.isChecking) {
this.bindEvents()
Expand All @@ -36,7 +40,15 @@ export default class UpdateController {
}

public downloadUpdate() {
this.notify({ ...UpdateController.lastNotifyInfo, progressInfo: null, downloadProgress: 0 })
this.notify({
...UpdateController.lastNotifyInfo,
progressInfo: {
total: UpdateController.updatePackageSize,
percent: 0,
transferred: 0,
},
downloadProgress: 0,
})
UpdateController.downCancellationToken = new CancellationToken()
autoUpdater.downloadUpdate(UpdateController.downCancellationToken)
}
Expand All @@ -63,6 +75,7 @@ export default class UpdateController {
autoUpdater.on('update-available', (info: UpdateInfo) => {
if (UpdateController.isChecking) {
UpdateController.isChecking = false
UpdateController.updatePackageSize = info.files[0].size ?? 0
this.notify({
version: info.version,
releaseDate: info.releaseDate,
Expand All @@ -78,8 +91,9 @@ export default class UpdateController {
}
})

autoUpdater.on('download-progress', progressInfo => {
autoUpdater.on('download-progress', (progressInfo: ProgressInfo) => {
const progressPercent = progressInfo.percent / 100
UpdateController.updatePackageSize = progressInfo.total
if (progressPercent !== 1) {
this.notify({ ...UpdateController.lastNotifyInfo, downloadProgress: progressPercent, progressInfo })
}
Expand Down

0 comments on commit d0f3890

Please sign in to comment.