From d96b82500a35efbef4464d9d23869f81a7d6da48 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Sun, 27 Mar 2016 20:40:07 +0200 Subject: [PATCH 1/6] Added electron wrapper --- README.md | 3 ++- js/electron.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 27 ++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100755 js/electron.js create mode 100755 package.json diff --git a/README.md b/README.md index 12657fcd..84fb123b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # MagicMirror V2 -This version of the Magic Mirror software focusses on a modular plugin system. +This version of the Magic Mirror software focusses on a modular plugin system. +To start the software run `npm install && npm start`. #WARNING: THIS VERSION IS IN A VERY EARLY STAGE. IT IS NOT COMPLETED YET. PLEASE USE THE MASTER BRANCH. diff --git a/js/electron.js b/js/electron.js new file mode 100755 index 00000000..3c37f0f3 --- /dev/null +++ b/js/electron.js @@ -0,0 +1,51 @@ +'use strict'; + +const electron = require('electron'); +// Module to control application life. +const app = electron.app; +// Module to create native browser window. +const BrowserWindow = electron.BrowserWindow; + +// 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. +let mainWindow; + +function createWindow () { + // Create the browser window. + mainWindow = new BrowserWindow({width: 800, height: 600, fullscreen: true}); + + // 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; + }); +} + +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +app.on('ready', createWindow); + +// 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(); + } +}); + +app.on('activate', function () { + // On OS X it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (mainWindow === null) { + createWindow(); + } +}); diff --git a/package.json b/package.json new file mode 100755 index 00000000..b69c8cef --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "Magic-Mirror", + "version": "2.0.0", + "description": "A modular interface for smart mirrors.", + "main": "js/electron.js", + "scripts": { + "start": "electron js/electron.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/MichMich/MagicMirror.git" + }, + "keywords": [ + "magic mirror", + "smart mirror", + "mirror UI" + ], + "author": "MichMich and others", + "license": "?", + "bugs": { + "url": "https://github.com/MichMich/MagicMirror/issues" + }, + "homepage": "https://github.com/MichMich/MagicMirror#readme", + "devDependencies": { + "electron-prebuilt": "^0.36.0" + } +} From d7844a1e39ffdad6ff8b80c193ebc15ff0dcca3b Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Sun, 27 Mar 2016 22:22:04 +0200 Subject: [PATCH 2/6] electron now searches for node helper scripts on module folders --- js/electron.js | 18 ++++++++++++++++++ modules/helper_test/node_helper.js | 2 ++ package.json | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 modules/helper_test/node_helper.js diff --git a/js/electron.js b/js/electron.js index 3c37f0f3..610285a3 100755 --- a/js/electron.js +++ b/js/electron.js @@ -1,5 +1,8 @@ 'use strict'; +//for searching modules +const walk = require('walk'); + const electron = require('electron'); // Module to control application life. const app = electron.app; @@ -29,6 +32,21 @@ function createWindow () { }); } +//Start helper scripts +var walker = walk.walk(__dirname + '/../modules', { followLinks: false }); + +walker.on('file', function(root, stat, next) { + if (stat.name == "node_helper.js"){ + require(root + '/' + stat.name); + } + + next(); +}); + +walker.on('end', function() { + console.log("Helpers startet"); +}); + // This method will be called when Electron has finished // initialization and is ready to create browser windows. app.on('ready', createWindow); diff --git a/modules/helper_test/node_helper.js b/modules/helper_test/node_helper.js new file mode 100644 index 00000000..ea00fc25 --- /dev/null +++ b/modules/helper_test/node_helper.js @@ -0,0 +1,2 @@ +'use strict'; +console.log("test"); \ No newline at end of file diff --git a/package.json b/package.json index b69c8cef..b517fc66 100755 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "homepage": "https://github.com/MichMich/MagicMirror#readme", "devDependencies": { - "electron-prebuilt": "^0.36.0" + "electron-prebuilt": "^0.36.0", + "walk": "latest" } } From 331c12269cb043858fa6bcba18d8ff63aa8be9f8 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Mon, 28 Mar 2016 00:26:24 +0200 Subject: [PATCH 3/6] disable node-integration so jquery works again --- js/electron.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/electron.js b/js/electron.js index 610285a3..16482f6d 100755 --- a/js/electron.js +++ b/js/electron.js @@ -15,7 +15,7 @@ let mainWindow; function createWindow () { // Create the browser window. - mainWindow = new BrowserWindow({width: 800, height: 600, fullscreen: true}); + mainWindow = new BrowserWindow({width: 800, height: 600, fullscreen: true, "node-integration": false}); // and load the index.html of the app. mainWindow.loadURL('file://' + __dirname + '../../index.html'); @@ -33,9 +33,9 @@ function createWindow () { } //Start helper scripts -var walker = walk.walk(__dirname + '/../modules', { followLinks: false }); +var module_loader = walk.walk(__dirname + '/../modules', { followLinks: false }); -walker.on('file', function(root, stat, next) { +module_loader.on('file', function(root, stat, next) { if (stat.name == "node_helper.js"){ require(root + '/' + stat.name); } @@ -43,7 +43,7 @@ walker.on('file', function(root, stat, next) { next(); }); -walker.on('end', function() { +module_loader.on('end', function() { console.log("Helpers startet"); }); From df153ee1a1e57e170808c2c36f8acbd689456698 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Mon, 28 Mar 2016 01:59:05 +0200 Subject: [PATCH 4/6] Hide menu-bar on Raspberry Pi and some comments --- js/electron.js | 12 ++++++++---- package.json | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/js/electron.js b/js/electron.js index 16482f6d..c61d238c 100755 --- a/js/electron.js +++ b/js/electron.js @@ -15,7 +15,7 @@ let mainWindow; function createWindow () { // Create the browser window. - mainWindow = new BrowserWindow({width: 800, height: 600, fullscreen: true, "node-integration": false}); + mainWindow = new BrowserWindow({width: 800, height: 600, fullscreen: true, "auto-hide-menu-bar": true, "node-integration": false}); // and load the index.html of the app. mainWindow.loadURL('file://' + __dirname + '../../index.html'); @@ -32,19 +32,23 @@ function createWindow () { }); } -//Start helper scripts +//Walk module folder and get file names var module_loader = walk.walk(__dirname + '/../modules', { followLinks: false }); +//for each file in modules module_loader.on('file', function(root, stat, next) { + //if file is called node_helper.js load it if (stat.name == "node_helper.js"){ require(root + '/' + stat.name); + //Log module name + var module = (root + '/' + stat.name).split("/") + console.log("Started helper script for module " + module[module.length-2] + "."); } - next(); }); module_loader.on('end', function() { - console.log("Helpers startet"); + console.log("All helpers started."); }); // This method will be called when Electron has finished diff --git a/package.json b/package.json index b517fc66..68b23972 100755 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "mirror UI" ], "author": "MichMich and others", - "license": "?", + "license": "MIT", "bugs": { "url": "https://github.com/MichMich/MagicMirror/issues" }, From 29db2dcd144d52d21cc575ef00aae9738de9e74b Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Mon, 28 Mar 2016 02:27:12 +0200 Subject: [PATCH 5/6] Use latest electron version --- package.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 68b23972..bd51685a 100755 --- a/package.json +++ b/package.json @@ -13,16 +13,20 @@ "keywords": [ "magic mirror", "smart mirror", - "mirror UI" + "mirror UI", + "modular" ], - "author": "MichMich and others", + "author": "Michael Teeuw", + "contributors": "https://github.com/MichMich/MagicMirror/graphs/contributors", "license": "MIT", "bugs": { "url": "https://github.com/MichMich/MagicMirror/issues" }, "homepage": "https://github.com/MichMich/MagicMirror#readme", "devDependencies": { - "electron-prebuilt": "^0.36.0", + "electron-prebuilt": "latest" + }, + "Dependencies": { "walk": "latest" - } + } } From 57bd3c5a4e6b51796d1d85a8ecfcd43830e2fe83 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Mon, 28 Mar 2016 02:29:13 +0200 Subject: [PATCH 6/6] Spelling mistake sorry... --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd51685a..9df003f5 100755 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "devDependencies": { "electron-prebuilt": "latest" }, - "Dependencies": { + "dependencies": { "walk": "latest" } }