Selaa lähdekoodia

Created helper for linux users who launch app for first time without correct user permissions. Fixes #19

Andrew Chalkley 9 vuotta sitten
vanhempi
commit
eb6d9d4d93
7 muutettua tiedostoa jossa 125 lisäystä ja 24 poistoa
  1. 29 0
      back-end/checkDialout.js
  2. 2 2
      back-end/prepare_binaries.js
  3. 17 0
      front-end/css/style.css
  4. 1 1
      front-end/index.html
  5. 52 0
      front-end/linux-help.html
  6. 24 4
      index.js
  7. 0 17
      linux-config.json

+ 29 - 0
back-end/checkDialout.js

@@ -0,0 +1,29 @@
+"use strict";
+
+const childProcess = require("child_process");
+const ERROR_MESSAGES = {
+    USER_NOT_IN_DIALOUT: "User not part of dialout group"
+}
+/**
+* Checks for the if the current Linux user is part of the dialout group
+* @param success callback if they are part of the dialout group
+* @param failure callback if they are not part of the dialout group
+*/
+function checkDialout(success, failure) {
+    childProcess.exec("id -Gn", (err, stdout, sterr) => {
+        if(err) {
+            failure(err);
+        } else {
+            const groups = stdout.split(" ");
+            if(groups.indexOf("dialout") != -1) {
+                success();
+            } else {
+                const dialoutMissingError = new Error(ERROR_MESSAGES.USER_NOT_IN_DIALOUT);
+                failure(dialoutMissingError);
+            }
+        }        
+    });
+}
+
+module.exports = checkDialout;
+module.exports.ERROR_MESSAGES = ERROR_MESSAGES;

+ 2 - 2
back-end/prepare_binaries.js

@@ -3,7 +3,7 @@
 const request = require("request");
 const decompress = require("decompress");
 const fs = require("fs");
-const EventEmitter = require("events");
+const EventEmitter = require("events").EventEmitter;
 
 function isBinaryFileRequired(flashSpecification, fileName) {
     return flashSpecification.map(binary => binary.path).indexOf(fileName) !== -1;
@@ -22,7 +22,7 @@ function prepareBinaries(manifest) {
     const flashContents = manifest.flash;
     let body;
     let contentLength;
-    const downloadRequest = request(manifest.download)
+    request(manifest.download)
         .on("response", response => {
             contentLength = Number(response.headers["content-length"]);
         })

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

@@ -113,3 +113,20 @@ footer {
 	display: inline-block;
 }
 
+#warning p {
+    line-height: 1.5;
+    margin-top:5px;
+}
+
+.code {
+    background: #ccc;
+    border: 1px solid #999;
+    font-family: monospace;
+    padding: 2px 4px;
+    border-radius: 4px;
+}
+
+#warning p.code {
+    padding:1px 10px;
+    display: inline-block;
+}

+ 1 - 1
front-end/index.html

@@ -17,7 +17,7 @@
             .bg{fill:none;stroke:#EEEEEE;stroke-width:3;stroke-miterlimit:10;}
         </style>
         <g>
-            <title>Flasherjs</title>
+            <title>Flasher.js</title>
 
         <linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="49" y1="145" x2="128" y2="145" gradientTransform="matrix(1 0 0 1 0 -55)">
             <stop  offset="0" style="stop-color:#FFAB91"/>

+ 52 - 0
front-end/linux-help.html

@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>Flasher.js</title>
+    <!-- Stylesheets -->
+    <link rel="stylesheet" href="css/style.css">
+</head>
+<body>
+    <div id="app">
+        <div id="logo">
+            <svg version="1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+     viewBox="0 0 180 180" style="enable-background:new 0 0 180 180;" xml:space="preserve">
+        <style type="text/css">
+            .st0{fill:none;stroke:url(#SVGID_1_);stroke-width:3;stroke-miterlimit:10;}
+            .st1{fill:none;stroke:#FFAB91;stroke-width:3;stroke-miterlimit:10;}
+            .st2{fill:none;stroke:#FFD600;stroke-width:3;stroke-miterlimit:10;}
+            .bg{fill:none;stroke:#EEEEEE;stroke-width:3;stroke-miterlimit:10;}
+        </style>
+        <g>
+            <title>Flasher.js - Linux Help</title>
+
+        <linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="49" y1="145" x2="128" y2="145" gradientTransform="matrix(1 0 0 1 0 -55)">
+            <stop  offset="0" style="stop-color:#FFAB91"/>
+            <stop  offset="1" style="stop-color:#FFD600"/>
+        </linearGradient>
+
+        <polyline class="st0" points="52,28 63,28 51,93 57,93 72,4 78,4 62,93 68,93 78,38 84,38
+        73,93 79,93 86,55 91,55 69,176 75,176 91,88 97,88 85,154 90,154 102,88 108,88
+        100,136 105,136 114,88 119,88 117,99 128,99"/>
+        <circle class="st1" cx="49" cy="28" r="3"/>
+        <circle class="st2" cx="131" cy="100" r="3"/>
+        </g>
+        </svg>
+        </div>
+        <div id="warning">
+            <p>
+                Your user account is not part of the <span class="code">dialout</span> group. 
+                The <span class="code">dialout</span> group allows users of that group to write to serial ports. 
+            </p>
+            <p>
+                 To add your user account to the group run the following command in your terminal:
+            </p>
+            <p class="code">
+                sudo usermod -a -G dialout $USER
+            </p>
+            <p>
+                Then log out or reboot your machine.
+            </p>
+        </div>
+    </div>
+</body>
+</html>

+ 24 - 4
index.js

@@ -10,7 +10,7 @@ if (handleSquirrelEvent()) {
 const electron = require('electron');
 const app = electron.app;  // Module to control application life.
 const BrowserWindow = electron.BrowserWindow;  // Module to create native browser window.
-
+const checkDialout = require("./back-end/checkDialout");
 // Keep a global reference of the window object, if you don't, the window will
 // be closed automatically when the JavaScript object is garbage collected.
 var mainWindow = null;
@@ -25,6 +25,17 @@ app.on('window-all-closed', function() {
   }
 });
 
+var  launchApp = function() {
+  // load the index.html of the app.
+  mainWindow.loadURL('file://' + __dirname + '/front-end/index.html');
+
+}
+
+function launchLinuxHelper() {
+  // load the linux-help.html of the app.
+  mainWindow.loadURL('file://' + __dirname + '/front-end/linux-help.html');
+}
+
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
 app.on('ready', function() {
@@ -37,9 +48,18 @@ app.on('ready', function() {
     'accept-first-mouse': true
   });
 
-  // and load the index.html of the app.
-  mainWindow.loadURL('file://' + __dirname + '/front-end/index.html');
-
+  if(process.platform === "linux") {
+      checkDialout(launchApp, (err) => {
+          if(err.message === checkDialout.ERROR_MESSAGES.USER_NOT_IN_DIALOUT) {
+              launchLinuxHelper();
+          } else {
+              //TODO: When another error occurs propogate the error somehow.
+              launchApp();
+          }
+      });
+  } else {
+      launchApp();
+  }
   // Open the DevTools.
   // mainWindow.webContents.openDevTools();
 

+ 0 - 17
linux-config.json

@@ -15,23 +15,6 @@
   "categories": [
     "Development Tools"
   ],
-  "depends": [
-    "git",
-    "gconf2",
-    "gconf-service",
-    "gvfs-bin",
-    "libc6",
-    "libcap2",
-    "libgtk2.0-0",
-    "libudev0 | libudev1",
-    "libgcrypt11 | libgcrypt20",
-    "libappindicator1",
-    "libnotify4",
-    "libnss3",
-    "libxtst6",
-    "python",
-    "xdg-utils"
-  ],
   "lintianOverrides": [
     "changelog-file-missing-in-native-package"
   ]