浏览代码

Added some code to notify 'no ports'

Andrew Chalkley 9 年之前
父节点
当前提交
9ad6a557cb
共有 3 个文件被更改,包括 9 次插入3 次删除
  1. 1 0
      back-end/available_serial_ports.js
  2. 6 3
      front-end/js/app.js
  3. 2 0
      index.js

+ 1 - 0
back-end/available_serial_ports.js

@@ -4,6 +4,7 @@ module.exports = function getAvailablePorts(){
     return new Promise(function(resolve, reject){
         serialport.list(function (err, ports) {
             if(err) reject(err);
+            else if(ports.length === 0) reject(new Error("No serial ports detected."));
             else resolve(ports.map(p => { return p.comName }));
         });
   });

+ 6 - 3
front-end/js/app.js

@@ -5,7 +5,7 @@ function $(id) { return document.getElementById(id) }
 const flashButton = $("flash-button");
 const appStatus = $("status");
 const portsSelect = $("ports");
-
+var last_notification = "";
 
 flashButton.addEventListener("click", event => {
     var notification = new Notification("Flash Finished!");
@@ -13,7 +13,6 @@ flashButton.addEventListener("click", event => {
 
 
 function checkPorts() {
-    appStatus.textContent = "Checking Serial/COM ports";
     availableSerialPorts()
         .then(addPortsToSelect)
         .then(readyToFlash)
@@ -68,7 +67,11 @@ function enableInputs(){
  * @param error
  */
 function onError(error){
-    new Notification(error.message);
+    if(last_notification !== error.message) {
+        last_notification = error.message;
+        new Notification(last_notification);
+    }
+    appStatus.textContent = error.message;
 }
 
 /**

+ 2 - 0
index.js

@@ -27,6 +27,8 @@ app.on('ready', function() {
     height: 200,
     'min-width': 256,
     'min-height': 200,
+    'max-width': 500,
+    'max-height': 550,
     'accept-first-mouse': true,
     'title-bar-style': 'hidden'
   });