Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved update experience #1414

Merged
merged 7 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"openLogsDir": "Open Logs Directory",
"openConfigFile": "Open Configuration File",
"viewOnGitHub": "View on GitHub",
"readReleaseNotes": "Read Release Notes",
"status": "Status",
"files": "Files",
"settings": "Settings",
Expand All @@ -30,13 +31,6 @@
"errorWhileWritingFiles": "An error occurred while writing the files to your file system.",
"hashDownloaded": "Hash downloaded",
"hashDownloadedClickToView": "Hash { hash } content downloaded. Click to view.",
"updateAvailable": "Update available",
"clickToInstall": "Click here to restart and install the newer version of IPFS Desktop.",
"updateNotAvailable": "Update not available",
"runningLatestVersion": "You seem to be running the latest version.",
"updateIsBeingDownloaded": "There is an update available and it is being downloaded.",
"couldNotCheckForUpdates": "Could not check for updates",
"pleaseCheckInternet": "Please check your Internet connection.",
"checkForUpdates": "Check for Updates...",
"yes": "Yes",
"no": "No",
Expand Down Expand Up @@ -116,5 +110,26 @@
"itemsFailedNotification": {
"title": "Failed to add items",
"message": "Could not add your items to your node."
},
"updateAvailableDialog": {
"title": "Update available",
"message": "A new version { version } is available. The download will begin shortly in background."
hacdias marked this conversation as resolved.
Show resolved Hide resolved
},
"updateNotAvailableDialog": {
"title": "Update not available",
"message": "You are on the latest version { version }."
hacdias marked this conversation as resolved.
Show resolved Hide resolved
},
"updateErrorDialog": {
"title": "Could not download update",
"message": "It was not possible to download the update. Please check your Internet connection and try again."
},
"updateDownloadedDialog": {
"title": "Update downloaded",
"message": "Update for version { version } downloaded. Restarting IPFS Desktop is required to install the update.",
hacdias marked this conversation as resolved.
Show resolved Hide resolved
"action": "Restart"
},
"updateDownloadedNotification": {
"title": "Update downloaded",
"message": "Update for version { version } downloaded. Click the notification to install it."
hacdias marked this conversation as resolved.
Show resolved Hide resolved
}
}
125 changes: 84 additions & 41 deletions src/auto-updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,115 @@ const i18n = require('i18next')
const quitAndInstall = require('./quit-and-install')
const logger = require('../common/logger')
const { notify } = require('../common/notify')
const { showDialog } = require('../dialogs')
const { shell } = require('electron')

let userRequested = false

function notifyIfRequested (...opts) {
if (userRequested) {
userRequested = false
notify(...opts)
}
}
let feedback = false

function setup (ctx) {
autoUpdater.autoDownload = false
autoUpdater.autoInstallOnAppQuit = true

autoUpdater.on('error', (err) => {
notifyIfRequested({
title: i18n.t('couldNotCheckForUpdates'),
body: i18n.t('pleaseCheckInternet')
})

autoUpdater.on('error', err => {
logger.error(`[updater] ${err.toString()}`)
})

autoUpdater.on('update-available', async () => {
logger.info('[updater] update available. download started')
if (!feedback) {
return
}

notifyIfRequested({
title: i18n.t('updateAvailable'),
body: i18n.t('updateIsBeingDownloaded')
feedback = false
showDialog({
title: i18n.t('updateErrorDialog.title'),
message: i18n.t('updateErrorDialog.message'),
type: 'error',
buttons: [
i18n.t('close')
]
})
})

autoUpdater.on('update-available', async ({ version, releaseNotes }) => {
logger.info('[updater] update available, download will start')

try {
await autoUpdater.downloadUpdate()
} catch (err) {
logger.error(`[updater] ${err.toString()}`)
}

if (!feedback) {
return
}

// do not toggle feedback off here so we can show a dialog once the download
// is finished.

const opt = showDialog({
title: i18n.t('updateAvailableDialog.title'),
message: i18n.t('updateAvailableDialog.message', { version, releaseNotes }),
type: 'info',
buttons: [
i18n.t('close'),
i18n.t('readReleaseNotes')
]
})

if (opt === 1) {
shell.openExternal(`https://github.com/ipfs-shipyard/ipfs-desktop/releases/v${version}`)
}
})

autoUpdater.on('update-not-available', async () => {
notifyIfRequested({
title: i18n.t('updateNotAvailable'),
body: i18n.t('runningLatestVersion')
autoUpdater.on('update-not-available', ({ version }) => {
logger.info('[updater] update not available')

if (!feedback) {
return
}

feedback = false
const opt = showDialog({
title: i18n.t('updateNotAvailableDialog.title'),
message: i18n.t('updateNotAvailableDialog.message', { version }),
type: 'info',
buttons: [
i18n.t('close'),
i18n.t('readReleaseNotes')
]
})

if (opt === 1) {
shell.openExternal(`https://github.com/ipfs-shipyard/ipfs-desktop/releases/v${version}`)
}
})

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

notify({
title: i18n.t('updateAvailable'),
body: i18n.t('clickToInstall')
}, () => {
const doIt = () => {
setImmediate(() => {
quitAndInstall(ctx)
})
}

if (!feedback) {
notify({
title: i18n.t('updateDownloadedNotification.title'),
body: i18n.t('updateDownloadedNotification.message', { version })
}, doIt)
}

feedback = false

showDialog({
title: i18n.t('updateDownloadedDialog.title'),
message: i18n.t('updateDownloadedDialog.message', { version }),
type: 'info',
buttons: [
i18n.t('updateDownloadedDialog.action')
]
})

doIt()
})
}

Expand All @@ -70,24 +124,13 @@ async function checkForUpdates () {
}

module.exports = async function (ctx) {
if (process.env.NODE_ENV === 'development') {
ctx.checkForUpdates = () => {
notify({
title: 'DEV Check for Updates',
body: 'Yes, you called this function successfully.'
})
}

return
}

setup(ctx)

await checkForUpdates()
setInterval(checkForUpdates, 43200000) // every 12 hours

ctx.checkForUpdates = () => {
userRequested = true
feedback = true
checkForUpdates()
}
}
3 changes: 3 additions & 0 deletions src/dev-app-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
owner: ipfs-shipyard
repo: ipfs-desktop
provider: github