Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

add back auto updater. closes #476 #490

Merged
merged 4 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { app, BrowserWindow, shell, Menu } = require('electron')
const { neutral } = require('dat-colors')
const autoUpdater = require('./lib/auto-updater')
const defaultMenu = require('electron-default-menu')
const doctor = require('dat-doctor')
const { Writable } = require('stream')
Expand Down Expand Up @@ -35,6 +36,11 @@ app.on('ready', () => {
win.loadURL(`file://${__dirname}/index.html`)
win.webContents.openDevTools()
Menu.setApplicationMenu(Menu.buildFromTemplate(menu))

if (process.env.NODE_ENV === 'production') {
const log = str => win && win.webContents.send('log', str)
autoUpdater({ log })
}
})

app.on('window-all-closed', () => app.quit())
Expand Down
36 changes: 36 additions & 0 deletions lib/auto-updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const os = require('os')
const { app, dialog, autoUpdater } = require('electron')
const ms = require('ms')

module.exports = ({ log }) => {
const onerror = err => err && log(err.stack)

const platform = `${os.platform()}_${os.arch()}`
const version = app.getVersion()

autoUpdater.setFeedURL(`http://dat.land:6000/update/${platform}/${version}`)
autoUpdater.on('error', onerror)
autoUpdater.on('checking-for-update', () => log('checking for update'))
autoUpdater.on('update-available', () => log('update available, downloading…'))
autoUpdater.on('update-not-available', () => log('update not available'))
autoUpdater.on('download-progress', p => log('download progress ' + p.percent))
autoUpdater.once('update-downloaded', (ev, notes, version) => {
log('update downloaded')

dialog.showMessageBox({
type: 'question',
buttons: ['Install and Relaunch', 'Dismiss'],
defaultId: 0,
title: 'A new version of Dat Desktop is ready to install!',
message: `Dat Desktop ${version} has been downloaded and is ready to use! Would you like to install it and relaunch Dat Desktop now?`
}, res => {
const update = res === 0
if (!update) return log('dismiss')
log('updating…')
autoUpdater.quitAndInstall()
})
})

setTimeout(() => autoUpdater.checkForUpdates(), ms('10s'))
setInterval(() => autoUpdater.checkForUpdates(), ms('30m'))
}
Loading