فهرست منبع

Initial electron

Andrew Chalkley 9 سال پیش
والد
کامیت
7204416a06
3فایلهای تغییر یافته به همراه59 افزوده شده و 5 حذف شده
  1. 16 0
      index.html
  2. 39 4
      index.js
  3. 4 1
      package.json

+ 16 - 0
index.html

@@ -0,0 +1,16 @@
+<html>
+  <head>
+    <meta charset="UTF-8">
+    <title>Hello World!</title>
+  </head>
+  <body>
+    <h1>Hello World!</h1>
+    <script>
+    var getAvailablePorts = require("./spike/available_serial_ports");
+
+    getAvailablePorts().then((ports) => {
+        ports.forEach(p=>{document.write(p)});
+    }).catch(e=>{alert(e)});
+    </script>
+  </body>
+</html>

+ 39 - 4
index.js

@@ -1,5 +1,40 @@
-var getAvailablePorts = require("./spike/available_serial_ports");
+'use strict';
 
-getAvailablePorts().then((ports) => {
-    console.dir(ports);
-}).catch(console.error);
+const electron = require('electron');
+const app = electron.app;  // Module to control application life.
+const BrowserWindow = electron.BrowserWindow;  // Module to create native browser window.
+
+// 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;
+
+
+// Quit when all windows are closed.
+app.on('window-all-closed', function() {
+  // On OS X it is common for applications and their menu bar
+  // to stay active until the user quits explicitly with Cmd + Q
+  if (process.platform != 'darwin') {
+    app.quit();
+  }
+});
+
+// This method will be called when Electron has finished
+// initialization and is ready to create browser windows.
+app.on('ready', function() {
+  // Create the browser window.
+  mainWindow = new BrowserWindow({width: 800, height: 600});
+
+  // and load the index.html of the app.
+  mainWindow.loadURL('file://' + __dirname + '/index.html');
+
+  // Open the DevTools.
+  //mainWindow.webContents.openDevTools();
+
+  // Emitted when the window is closed.
+  mainWindow.on('closed', function() {
+    // Dereference the window object, usually you would store windows
+    // in an array if your app supports multi windows, this is the time
+    // when you should delete the corresponding element.
+    mainWindow = null;
+  });
+});

+ 4 - 1
package.json

@@ -4,7 +4,7 @@
   "description": "A GUI tool for flashing the Espruino JavaScript runtime on Adafruit Huzzah (ESP8366 based) boards",
   "main": "index.js",
   "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
+    "start": "electron index.js"
   },
   "repository": {
     "type": "git",
@@ -25,5 +25,8 @@
   "homepage": "https://github.com/thingsSDK/especially-flasher#readme",
   "dependencies": {
     "serialport": "^2.0.6"
+  },
+  "devDependencies": {
+    "electron-prebuilt": "^0.36.9"
   }
 }