Skip to content

Commit

Permalink
notify when has new update
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita committed Jan 1, 2018
1 parent 2dcb069 commit cefc4ee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
29 changes: 29 additions & 0 deletions main/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Packages
const { shell, Notification } = require('electron')
const { resolve } = require('app-root-path')

const icon = resolve('./static/icon.ico')

module.exports = ({ title, body, url, onClick }) => {
const specs = {
title,
body,
icon,
silent: true
}

const notification = new Notification(specs)

if (url || onClick) {
notification.on('click', () => {
if (onClick) {
return onClick()
}

shell.openExternal(url)
})
}

notification.show()
console.log(`[Notification] ${title}: ${body}`)
}
18 changes: 17 additions & 1 deletion main/updater.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
'use strict'

// Packages
const { app, autoUpdater } = require('electron')
const isDev = require('electron-is-dev')

// Utils
const notify = require('./notify')

module.exports = () => {
if (!isDev) {
const server = 'https://taskr.now.sh'
const feed = `${server}/update/${process.platform}/${app.getVersion()}`

autoUpdater.setFeedURL(feed)

return autoUpdater.getFeedURL()
autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall()
app.quit()
})

autoUpdater.on('update-available', () => {
notify({
title: 'New update available',
body: 'Found update for the app! Downloading...'
})
})

return autoUpdater.checkForUpdates()
}
}

0 comments on commit cefc4ee

Please sign in to comment.