Skip to content

Commit

Permalink
Adds autoUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
James Kerr committed Aug 10, 2018
1 parent 0d7483c commit 95150ae
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
45 changes: 43 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const {app, BrowserWindow} = require("electron")
const {app, BrowserWindow, dialog, autoUpdater} = require("electron")

const server = "http://desktop-release.looky.cloud"
const feed = `${server}/update/${process.platform}/${app.getVersion()}`
console.log(feed)
autoUpdater.setFeedURL(feed)
let win

const createWindow = () => {
Expand All @@ -15,7 +19,13 @@ const createWindow = () => {
})
}

app.on("ready", createWindow)
app.on("ready", () => {
createWindow()
autoUpdater.checkForUpdates()
setInterval(() => {
autoUpdater.checkForUpdates()
}, 15 * 1000)
})

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
Expand All @@ -28,3 +38,34 @@ app.on("activate", () => {
createWindow()
}
})

autoUpdater.on("update-downloaded", (event, releaseNotes, releaseName) => {
const dialogOpts = {
type: "info",
buttons: ["Restart", "Later"],
title: "Application Update",
message: process.platform === "win32" ? releaseNotes : releaseName,
detail:
"A new version has been downloaded. Restart the application to apply the updates."
}

dialog.showMessageBox(dialogOpts, response => {
if (response === 0) autoUpdater.quitAndInstall()
})
})

autoUpdater.on("error", message => {
console.error("Pblem updating the app:", message)
})

autoUpdater.on("update-available", () => {
console.log("update available")
})

autoUpdater.on("update-not-available", () => {
console.log("Up to date!")
})

autoUpdater.on("checking-for-update", () => {
console.log("checking for update")
})
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"description": "Looky Desktop App",
"repository": "https://github.com/looky/looky-desktop",
"license": "None",
"version": "1.0.0",
"version": "0.1.1",
"main": "main.js",
"author": "Looky Labs, Inc.",
"scripts": {
"start": "npm-run-all -p electron watch:*",
"test": "jest --roots src/js",
"pretest": "npm run lint",
"electron": "electron .",
"release": "electron-packager . Looky --out releases --overwrite --icon dist/static/looky.smaller.icns",
"release": "electron-packager . Looky --out=releases --overwrite --icon=dist/static/looky.smaller.icns",
"prerelease": "npm run build",
"build": "npm-run-all -p build:*",
"watch": "npm-run-all -p watch:*",
Expand Down

0 comments on commit 95150ae

Please sign in to comment.