Просмотр исходного кода

WIP: Run updates.thingssdk.com locally

craigsdennis 9 лет назад
Родитель
Сommit
334dd32d8b
2 измененных файлов с 15 добавлено и 0 удалено
  1. 1 0
      .jshintrc
  2. 14 0
      front-end/js/app.js

+ 1 - 0
.jshintrc

@@ -1,5 +1,6 @@
 {
     "esversion": 6,
     "node": true,
+    "electron": true,
     "strict": true
 }

+ 14 - 0
front-end/js/app.js

@@ -1,8 +1,11 @@
 "use strict";
 
+const autoUpdater = require('auto-updater');
+const os = require('os').platform();
 //Relative to index.html not app.js
 const SerialScanner = require("../back-end/serial_scanner");
 const PortSelect = require("./js/port_select");
+const packageInfo = require('./package.json');
 
 function $(id) { return document.getElementById(id); }
 
@@ -35,6 +38,10 @@ serialScanner.on("deviceRemoved", (port ) => {
 
 serialScanner.on("error", onError);
 
+autoUpdater.on("checking-for-update", () => {
+    new Notification("Checking for updates");
+});
+
 /**
  * Updates UI to say it's ready
  */
@@ -63,12 +70,19 @@ function onError(error){
     appStatus.textContent = error.message;
 }
 
+function initUpdater() {
+    let updateFeed = `http://localhost:3000/updates/${packageInfo.name}/latest`;
+    autoUpdater.setFeedURL(updateFeed + '?v=' + packageInfo.version);
+    autoUpdater.checkForUpdates();
+}
+
 /**
  * Sets up UI
  */
 function init() {
     serialScanner.scan();
     setInterval(serialScanner.checkForChanges.bind(serialScanner), pollTime);
+    initUpdater();
 }
 
 init();