diff --git a/main.js b/main.js index 2bf9b15634..4a0f866b74 100644 --- a/main.js +++ b/main.js @@ -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 = () => { @@ -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") { @@ -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") +}) diff --git a/package.json b/package.json index c5856471c8..8c63029c15 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "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": { @@ -11,7 +11,7 @@ "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:*",