From 0ea9f68c13c849f83d63131567a942b21f39cffb Mon Sep 17 00:00:00 2001 From: openbuilds-engineer Date: Wed, 11 Jul 2018 14:39:24 +0200 Subject: [PATCH] update --- .gitignore | 2 +- dev-app-update.yml | 3 ++ index.js | 79 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 12 ++++--- 4 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 dev-app-update.yml diff --git a/.gitignore b/.gitignore index 6d6441a..ada5c96 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ #electron dist dist upload -ssl +electron-builder.yml # Compiled source # ################### diff --git a/dev-app-update.yml b/dev-app-update.yml new file mode 100644 index 0000000..ecc8c99 --- /dev/null +++ b/dev-app-update.yml @@ -0,0 +1,3 @@ +owner: OpenBuilds +repo: SW-Machine-Drivers +provider: github diff --git a/index.js b/index.js index b82f496..e36e97e 100644 --- a/index.js +++ b/index.js @@ -19,16 +19,18 @@ var io = new ioServer(); // var anotherIo = io.listen(https); var fs = require('fs'); +var path = require("path"); +const join = require('path').join; + var httpsOptions = { - key: fs.readFileSync('ssl/localhost.key'), - cert: fs.readFileSync('ssl/localhost.cer') + key: fs.readFileSync(path.join(__dirname, 'ssl/localhost.key')), + cert: fs.readFileSync(path.join(__dirname, 'ssl/localhost.cer')) }; const httpsserver = https.createServer(httpsOptions, app).listen(3001, function() { console.log('https: listening on:' + ip.address() + ":3001"); }); - const httpserver = http.listen(config.webPort, '0.0.0.0', function() { console.log('http: listening on:' + ip.address() + ":" + config.webPort); // Now refresh library @@ -41,8 +43,6 @@ io.attach(httpsserver); const grblStrings = require("./grblStrings.js"); -var path = require("path"); -const join = require('path').join; const serialport = require('serialport'); var SerialPort = serialport; var md5 = require('md5'); @@ -79,6 +79,71 @@ var appIcon = null, jogWindow = null, mainWindow = null +const { + autoUpdater +} = require("electron-updater"); + +electronApp.on('ready', function() { + autoUpdater.checkForUpdates(); +}); + +autoUpdater.on('checking-for-update', () => { + var string = 'Checking for update...'; + io.sockets.emit('data', string); + appIcon.displayBalloon({ + icon: nativeImage.createFromPath(iconPath), + title: "OpenBuilds Machine Driver", + content: string + }) +}) +autoUpdater.on('update-available', (ev, info) => { + var string = 'Update available.'; + io.sockets.emit('data', string); + appIcon.displayBalloon({ + icon: nativeImage.createFromPath(iconPath), + title: "OpenBuilds Machine Driver", + content: string + }) +}) +autoUpdater.on('update-not-available', (ev, info) => { + var string = 'Update not available.'; + io.sockets.emit('data', string); + appIcon.displayBalloon({ + icon: nativeImage.createFromPath(iconPath), + title: "OpenBuilds Machine Driver", + content: string + }) +}) +autoUpdater.on('error', (ev, err) => { + var string = 'Error in auto-updater.'; + io.sockets.emit('data', string); + appIcon.displayBalloon({ + icon: nativeImage.createFromPath(iconPath), + title: "OpenBuilds Machine Driver", + content: string + }) +}) +autoUpdater.on('download-progress', (ev, progressObj) => { + var string = 'Download progress...'; + io.sockets.emit('data', string); + appIcon.displayBalloon({ + icon: nativeImage.createFromPath(iconPath), + title: "OpenBuilds Machine Driver", + content: string + }) +}) + +autoUpdater.on('update-downloaded', (info) => { + var string = "New update ready"; + io.sockets.emit('data', string); + appIcon.displayBalloon({ + icon: nativeImage.createFromPath(iconPath), + title: "OpenBuilds Machine Driver", + content: string + }) + // autoUpdater.quitAndInstall(); +}); + var uploadsDir = electronApp.getPath('userData') + '/upload/'; fs.existsSync(uploadsDir) || fs.mkdirSync(uploadsDir) @@ -586,6 +651,10 @@ io.on("connection", function(socket) { electronApp.exit(0); }); + socket.on("applyUpdate", function(data) { + autoUpdater.quitAndInstall(); + }) + socket.on("connectTo", function(data) { // If a user picks a port to connect to, open a Node SerialPort Instance to it if (status.comms.connectionStatus < 1) { diff --git a/package.json b/package.json index 0efefa1..c4926f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "OpenBuildsMachineDriver", - "version": "1.0.13", + "version": "1.0.14", "license": "AGPL-3.0", "description": "Machine Interface Driver for OpenBuilds", "author": "github.com/openbuilds", @@ -12,6 +12,7 @@ }, "dependencies": { "directory-tree": "^2.1.0", + "electron-updater": "^2.23.3", "express": "^4.16.2", "formidable": "^1.2.1", "gcodethumbnail": "^1.0.1", @@ -28,14 +29,12 @@ "test": "echo \"Error: no test specified\" && exit 0", "dist": "build", "distmac": "build --mac ", - "distwinx86": "build --win --ia32 ", - "distwinx64": "build --win --x64", - "distlinx86": "build --linux --ia32 ", - "distlinx64": "build --linux --x64" + "ship": "build --win -p always" }, "keywords": [ "usb" ], + "repository": "https://github.com/OpenBuilds/SW-Machine-Drivers", "build": { "appId": "openbuilds.projectmakr", "productName": "OpenBuilds Machine Driver", @@ -51,6 +50,9 @@ "files": [ "**/*" ], + "extraFiles": [ + "ssl" + ], "linux": { "icon": "build/" },