Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron update #944

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ app/css/local.css
.gitignore
.prettierrc
.editorconfig
plugins/
!.gitkeep
32 changes: 32 additions & 0 deletions .gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins/autosleep
plugins/calendar
plugins/commands
plugins/commitstrip
plugins/datetime
plugins/dilbert
plugins/fitbit
plugins/_general
plugins/geolocation
plugins/giphy
plugins/greeting
plugins/ha-display
plugins/light
plugins/maker
plugins/map
plugins/pluginconfig
plugins/reminder
plugins/remote
plugins/rss
plugins/scrobbler
plugins/search
plugins/soundcloud
plugins/speech
plugins/spotify
plugins/stock
plugins/timebox
plugins/timer
plugins/todoist
plugins/traffic
plugins/tvshows
plugins/weather
plugins/xkcd
9 changes: 0 additions & 9 deletions app/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Focus,
SpeechService,
AutoSleepService,
// LightService,
$rootScope,
$scope,
$timeout,
Expand Down Expand Up @@ -183,14 +182,6 @@
console.debug("It is", moment().format("h:mm:ss a"));
});

// Control light
/* SpeechService.addCommand("light_action", function (
state,
target,
action
) {
LightService.performUpdate([state, target, action].join(" "));
}); */
};

_this.init();
Expand Down
48 changes: 44 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const remote = require("./remote.js");
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
// Replace with:
const debug =false;
//const { BrowserWindow } = require('@electron/remote/main')

// In the main process:
require('@electron/remote/main').initialize()
// Prevent the monitor from going to sleep.
const powerSaveBlocker = electron.powerSaveBlocker;
powerSaveBlocker.start("prevent-display-sleep");
Expand All @@ -17,7 +23,31 @@ const getPort = require("get-port");

// Launching the mirror in dev mode
const DevelopmentMode = process.argv.includes("dev");
const usepm2 = process.argv.includes("usepm2");
let usepm2 = false;

//if (debug) console.log("getting pm2 process list");
exec("pm2 jlist", (error, stdout) => {
if (!error) {
let output = JSON.parse(stdout);
if (debug)
console.log(
"processing pm2 jlist output, " + output.length + " entries"
);
output.forEach((managed_process) => {
if(debug)
console.log("comparing "+__dirname +" with "+ managed_process.pm2_env.pm_cwd )
// if we find a pm2 process matching our location
// and that process is online, then it is us
if (managed_process.pm2_env.pm_cwd.startsWith(__dirname) && managed_process.pm2_env.status ==="online") {
if (debug)
console.log(
"found our pm2 entry, id=" + managed_process.pm_id
);
usepm2 = true;
}
});
}
});
//var atomScreen = null;
// Load the smart mirror config
let config;
Expand Down Expand Up @@ -67,6 +97,7 @@ function createWindow() {
break;
}
}

const { width, height } = atomScreen.getPrimaryDisplay().workAreaSize;
var browserWindowOptions = {
width: width,
Expand All @@ -80,14 +111,16 @@ function createWindow() {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false,
additionalArguments:["sonusPort:"+global.sonusSocket]
},
};
if (externalDisplay) {
browserWindowOptions.x = width; //+ 2; //externalDisplay.bounds.x + 50
browserWindowOptions.y = height; //externalDisplay.bounds.y + 50
console.log(
"display size=" + browserWindowOptions.x + "+" + browserWindowOptions.y
);
if(debug)
console.log(
"display size=" + browserWindowOptions.x + "+" + browserWindowOptions.y
);
}

// Create the browser window.
Expand Down Expand Up @@ -148,6 +181,9 @@ function startSonus(port) {
if (config && config.speech && !firstRun) {
// get the sonus communications socket port
getPort({ port: getPort.makeRange(9000, 9500) }).then((port) => {
if(debug)
console.log("found port="+port)
//console.log("global="+JSON.stringify(global,null,2))
global.sonusSocket = port;
config.communications_port = port;
startSonus(config.communications_port);
Expand Down Expand Up @@ -216,10 +252,14 @@ if ((config.remote && config.remote.enabled) || firstRun) {
remote.on("relaunch", function (newConfig) {
console.log("Relaunching...");
// rebuild the html file plugin position info, from the NEW config data
// if pm2 is not being used for this process control
if (!usepm2) {
// recalc plugin info since something changed
loader.loadPluginInfo(__dirname + "/index.html", newConfig);
// force reload
app.relaunch();
}
// else die and pm2 will restart us
app.quit();
});
}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smart-mirror",
"version": "0.0.30",
"version": "0.0.31",
"description": "The fairest of them all",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -36,11 +36,12 @@
"devDependencies": {
"angular-i18n": "^1.8.2",
"bower": "^1.8.12",
"electron": "11.3.0",
"electron": "17.2.0",
"eslint": "^6.8.0",
"wiredep-cli": "^0.1.0"
},
"dependencies": {
"@electron/remote": "^2.0.8",
"@google-cloud/speech": "^4.2.0",
"@grpc/grpc-js": "^1.2.11",
"alphavantage": "1.2.6",
Expand All @@ -54,7 +55,7 @@
"fitbit-oauth2": "0.0.1",
"humanize-duration": "^3.25.1",
"hyperion-client": "1.0.3",
"jsonform": "git://github.com/jsonform/jsonform.git",
"jsonform": "git+https://git@github.com/jsonform/jsonform.git",
"moment": "^2.29.1",
"pretty-ms": "^7.0.1",
"recorder": "git+https://git@github.com/sdetweil/recorder.git",
Expand Down
74 changes: 38 additions & 36 deletions plugins/geolocation/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,45 @@
var geoloc = null;

service.getLocation = function (parms) {
var deferred = $q.defer();
// Use geo postion from config file if it is defined
if( config.geoPosition
&& typeof config.geoPosition.latitude != 'undefined'
&& typeof config.geoPosition.longitude != 'undefined') {
deferred.resolve({
coords: {
latitude: config.geoPosition.latitude,
longitude: config.geoPosition.longitude,
},
});
geoloc = deferred.promise;
} else {
// if we haven't requested info yet
if (geoloc == null) {
var body={};
if(parms!=null)
body = parms
// if we have a key
if(config.geoPosition && config.geoPosition.key) {
geoloc = deferred.promise;
body.considerIp=true;
$http.post("https://www.googleapis.com/geolocation/v1/geolocate?key="+config.geoPosition.key, body).then(
function (result) {
var location = angular.fromJson(result).data.location
deferred.resolve({ 'coords': { 'latitude': location.lat, 'longitude': location.lng } })
},
function (err) {
deferred.reject("Failed to retrieve geolocation.eeror ="+ err)
}
);
//var deferred = $q.defer();
return new Promise((resolve,reject)=>{
// Use geo postion from config file if it is defined
if( config.geoPosition
&& typeof config.geoPosition.latitude != 'undefined'
&& typeof config.geoPosition.longitude != 'undefined') {
/*deferred.*/resolve({
coords: {
latitude: config.geoPosition.latitude,
longitude: config.geoPosition.longitude,
},
});
//geoloc = deferred.promise;
} else {
// if we haven't requested info yet
//if (geoloc == null) {
var body={};
if(parms!=null)
body = parms
// if we have a key
if(config.geoPosition && config.geoPosition.key) {
//geoloc = deferred.promise;
body.considerIp=true;
$http.post("https://www.googleapis.com/geolocation/v1/geolocate?key="+config.geoPosition.key, body).then(
function (result) {
var location = angular.fromJson(result).data.location
/*deferred.*/resolve({ 'coords': { 'latitude': location.lat, 'longitude': location.lng } })
},
function (err) {
/*deferred.*/ reject("Failed to retrieve geolocation.eeror ="+ err)
}
);
}
else
/*deferred.*/ reject("Failed to retrieve geolocation.eeror ="+ "no key provided");
}
else
deferred.reject("Failed to retrieve geolocation.eeror ="+ "no key provided");
}
}
return geoloc;
//}
})
//return geoloc?geoloc:deferred.promise;
}
return service;
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/giphy/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ function Giphy($scope, $http, SpeechService, Focus) {
SpeechService.addCommand('image_giphy', function (img) {
$http.get("http://api.giphy.com/v1/gifs/random?api_key=" + config.giphy.key + "&tag=" + img)
.then(function (response) {
$scope.gifimg = response.data.data.image_url;
$scope.gifimg = response.data.data.images.original.url;
//console.log(JSON.stringify(response.data.data,null,2))
Focus.change("gif");
})
});
Expand Down
7 changes: 7 additions & 0 deletions plugins/reminder/controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const __rm = require("path");
let __rmpath = document.currentScript.src.substring(
7,
document.currentScript.src.lastIndexOf(__sp.sep)
);

function Reminder($scope, SpeechService, $translate, Focus) {
const storage = require("electron-json-storage");
storage.setDataPath(__rmpath);
// Service variable
var remind = {};
remind.reminders = [];
Expand Down
21 changes: 18 additions & 3 deletions plugins/speech/service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
const { ipcRenderer, remote } = require("electron");
const { ipcRenderer } = require("electron");
//const remote = require("@electron/remote")
//const remote = require("electron").remote;

(function () {
"use strict";
try {
//console.log("args="+JSON.stringify(window.process.argv,null,2))
}
catch(ex){

}
finally {
//config.communications_port = 5200
for(let p of window.process.argv){
if(p.startsWith("sonusPort")){
config.communications_port=p.split(":")[1]
break;
}
}
}
//console.log("SpeechService sonusPort="+config.communications_port)
function SpeechService($rootScope, $translate) {
var service = {};
var callbacks = {};
var commandList = [];
var commandPage = [];

config.communications_port = remote.getGlobal("sonusSocket");
service.init = function (cb) {
// workaround so we can trigger requests at any time
annyang.isListening = () => {
Expand Down Expand Up @@ -139,7 +154,7 @@ const { ipcRenderer, remote } = require("electron");
//
// the recorder library asks sm sonus to disconnect from mic, then start up our own version without
// hotword (assistant) and maybe reco all together (alexa)
// after each recording we have no idea is more prompts are coming
// after each recording we have no idea if more prompts are coming
// so the library has to disconnect and tell sm sonus.js to reconnect
// the plugin needing this service needs to call startVoiceRecognition
// to start each sequence
Expand Down