Skip to content

Commit

Permalink
fix: add logger to electron-updater (#2552)
Browse files Browse the repository at this point in the history
* tmp: debugging autoupdater

* tmp: debugging auto-update

* tmp: random dir in tmp dir

* tmp: more debugging and tweaks

* chore: cleanup

* chore: cleanup
  • Loading branch information
SgtPooki committed Jul 12, 2023
1 parent 7193abb commit 316ec42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/auto-updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function setup (ctx) {
// we download manually in 'update-available'
autoUpdater.autoDownload = false
autoUpdater.autoInstallOnAppQuit = true
autoUpdater.logger = logger

autoUpdater.on('error', err => {
logger.error(`[updater] ${err.toString()}`)
Expand Down Expand Up @@ -88,6 +89,21 @@ function setup (ctx) {
})
})

let progressPercentTimeout = null
autoUpdater.on('download-progress', ({ percent, bytesPerSecond }) => {
const logDownloadProgress = () => {
logger.info(`[updater] download progress is ${percent.toFixed(2)}% at ${bytesPerSecond} bps.`)
}
// log the percent, but not too often to avoid spamming the logs, but we should
// be sure we're logging at what percent any hiccup is occurring.
clearTimeout(progressPercentTimeout)
if (percent === 100) {
logDownloadProgress()
return
}
progressPercentTimeout = setTimeout(logDownloadProgress, 2000)
})

autoUpdater.on('update-downloaded', ({ version }) => {
logger.info(`[updater] update to ${version} downloaded`)

Expand Down Expand Up @@ -151,7 +167,7 @@ async function checkForUpdates () {
}

module.exports = async function (ctx) {
if (['test', 'development'].includes(process.env.NODE_ENV)) {
if (['test', 'development'].includes(process.env.NODE_ENV ?? '')) {
ctx.manualCheckForUpdates = () => {
showDialog({
title: 'Not available in development',
Expand Down
4 changes: 4 additions & 0 deletions src/common/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ module.exports = Object.freeze({
logger.error(err)
},

warn: (msg, meta) => {
logger.warn(msg, meta)
},

logsPath,
addAnalyticsEvent
})

0 comments on commit 316ec42

Please sign in to comment.