Explorar o código

Fixes #22 amd style improvements

Andrew Chalkley %!s(int64=9) %!d(string=hai) anos
pai
achega
579aab914e
Modificáronse 4 ficheiros con 39 adicións e 7 borrados
  1. 1 0
      back-end/serial_scanner.js
  2. 6 0
      front-end/css/style.css
  3. 28 7
      front-end/js/app.js
  4. 4 0
      front-end/js/port_select.js

+ 1 - 0
back-end/serial_scanner.js

@@ -84,6 +84,7 @@ class SerialScanner extends EventEmitter {
             this._emitError(err);
             this._emitError(err);
         }
         }
         else if(ports.length === 0) {
         else if(ports.length === 0) {
+            this.ports = [];
             this._emitError(new Error("No serial ports detected."));
             this._emitError(new Error("No serial ports detected."));
         }
         }
         else {
         else {

+ 6 - 0
front-end/css/style.css

@@ -36,6 +36,12 @@ button:hover {
 	box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.5);
 	box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.5);
 }
 }
 
 
+button:hover:disabled {
+	background: #eee;
+	color: #aaa;
+}
+
+
 select {
 select {
 	width: 254px;
 	width: 254px;
 	height: 21px;
 	height: 21px;

+ 28 - 7
front-end/js/app.js

@@ -13,6 +13,8 @@ const CONSTANTS = {
     pollTime: 1000
     pollTime: 1000
 };
 };
 
 
+var isFlashing = false;
+
 var last_notification = "";
 var last_notification = "";
 
 
 /************************
 /************************
@@ -69,6 +71,7 @@ function processJSON(response) {
 ************************/
 ************************/
 
 
 flashButton.addEventListener("click", (event) => {
 flashButton.addEventListener("click", (event) => {
+    isFlashing = true;
     disableInputs();
     disableInputs();
     prepareUIForFlashing(()=>{
     prepareUIForFlashing(()=>{
         fetch(manifestsSelect.value)
         fetch(manifestsSelect.value)
@@ -83,21 +86,26 @@ flashButton.addEventListener("click", (event) => {
 
 
  serialScanner.on("ports", (ports) => {
  serialScanner.on("ports", (ports) => {
     portsSelect.addAll(ports);
     portsSelect.addAll(ports);
-    readyToFlash();
 });
 });
 
 
 serialScanner.on("deviceAdded", (port) => {
 serialScanner.on("deviceAdded", (port) => {
     portsSelect.add(port);
     portsSelect.add(port);
-    readyToFlash();
     new Notification(`Added: ${port}!`);
     new Notification(`Added: ${port}!`);
 });
 });
 
 
 serialScanner.on("deviceRemoved", (port) => {
 serialScanner.on("deviceRemoved", (port) => {
-    portsSelect.remove(port);
+    console.log(port);
     new Notification(`Removed: ${port}!`);
     new Notification(`Removed: ${port}!`);
 });
 });
 
 
-serialScanner.on("error", onError);
+serialScanner.on("error", (err) => {
+    if(err.message === "No serial ports detected.") {
+        if(portsSelect.children[0]) {
+            portsSelect.remove(portsSelect.children[0].textContent);
+        }
+    }
+    onError(err);
+});
 
 
 /**
 /**
  * Updates UI to say it's ready
  * Updates UI to say it's ready
@@ -186,13 +194,13 @@ function flashWithManifest(manifest) {
                 .then(() => esp.close())
                 .then(() => esp.close())
                 .then((result) => {
                 .then((result) => {
                     new Notification("Flash Finished!");
                     new Notification("Flash Finished!");
-                    readyToFlash();
+                    isFlashing = false;
                     restoreUI();
                     restoreUI();
                     log.info("Flashed to latest Espruino build!", result);
                     log.info("Flashed to latest Espruino build!", result);
                 });
                 });
         }).catch((error) => {
         }).catch((error) => {
             new Notification("An error occured during flashing.");
             new Notification("An error occured during flashing.");
-            readyToFlash();
+            isFlashing = false;
             log.error("Oh noes!", error);
             log.error("Oh noes!", error);
         });
         });
     }).on("entry", (progress) => {
     }).on("entry", (progress) => {
@@ -277,6 +285,18 @@ function restoreUI(callback) {
     if(callback) callback();
     if(callback) callback();
 }
 }
 
 
+function inputStateManager() {
+    if(!isFlashing) {
+        if( manifestsSelect.children.length > 0 && portsSelect.children.length > 0 ) {
+            readyToFlash();
+        } else {
+            disableInputs();
+        }
+    } else {
+        disableInputs();
+    }
+}
+
 /**
 /**
  * Get's manifest list for possibilities for flashing,
  * Get's manifest list for possibilities for flashing,
  * scans serial ports and sets up timer for checking for changes.
  * scans serial ports and sets up timer for checking for changes.
@@ -284,10 +304,11 @@ function restoreUI(callback) {
 function start() {
 function start() {
     getManifests();
     getManifests();
     serialScanner.scan();
     serialScanner.scan();
+    setInterval(inputStateManager, 10);
     setInterval(serialScanner.checkForChanges.bind(serialScanner), CONSTANTS.pollTime);
     setInterval(serialScanner.checkForChanges.bind(serialScanner), CONSTANTS.pollTime);
 }
 }
 
 
 /**
 /**
  * Start Application
  * Start Application
  */
  */
-start();
+start();

+ 4 - 0
front-end/js/port_select.js

@@ -69,6 +69,10 @@ class PortSelect {
     get value() {
     get value() {
         return this.selectElement.value;
         return this.selectElement.value;
     }
     }
+
+    get children() {
+        return this.selectElement.children;
+    }
 };
 };
 
 
 module.exports = PortSelect;
 module.exports = PortSelect;