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

Electron18 uprade #167

Merged
merged 5 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Then unplug and replug the blink(1) device.
Install the following pre-requisites:

```sh
sudo apt install libgnome-keyring-dev icnsutils xz-utils rpm bsdtar libusb-1.0.0-dev libudev-dev
sudo apt install pkg-config libgnome-keyring-dev icnsutils xz-utils rpm bsdtar libusb-1.0-0-dev libudev-dev
```

(see: https://github.com/electron-userland/electron-builder/issues/1407)
Expand Down
9 changes: 5 additions & 4 deletions app/about.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script>
var pkg = require('./package.json');
var conf = require('./configuration');
var conffile = conf.getFilepath();
const pkg = require('./package.json');
const { app } = require('@electron/remote')
const conf_dir = app.getPath('userData');
const conf_file = conf_dir + '/blink1control2-config.json';

var aHomepage = '<a href="' + pkg.homepage + '">' + pkg.homepage + '</a>';
var aBugs = '<a href="' + pkg.bugs + '">' + pkg.bugs + '</a>';

var conffilelink = '<a href="file://' + conffile + '">' + conffile + '</a>';
var conffilelink = '<a href="file://' + conf_file + '">' + conf_file + '</a>';
</script>

<html>
Expand Down
9 changes: 3 additions & 6 deletions app/components/gui/bigButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ var React = require('react');

var Button = require('react-bootstrap').Button;

var remote = require('electron').remote;
var Menu = remote.Menu;
var MenuItem = remote.MenuItem;
const Menu = require('@electron/remote').Menu
const MenuItem = require('@electron/remote').MenuItem
const currentWindow = require('@electron/remote').getCurrentWindow();

var tinycolor = require('tinycolor2');

var log = require('../../logger');

var currentWindow = remote.getCurrentWindow();


var BigButton = React.createClass({
propTypes: {
idx: React.PropTypes.number,
Expand Down
7 changes: 3 additions & 4 deletions app/components/gui/blink1Status.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ var Panel = require('react-bootstrap').Panel;
var Well = require('react-bootstrap').Well;

var ipcRenderer = require('electron').ipcRenderer;
var remote = require('electron').remote;
var Menu = remote.Menu;
var MenuItem = remote.MenuItem;
var currentWindow = remote.getCurrentWindow();
const Menu = require('@electron/remote').Menu
const MenuItem = require('@electron/remote').MenuItem
const currentWindow = require('@electron/remote').getCurrentWindow();

var Blink1Service = require('../../server/blink1Service');
var PatternsService = require('../../server/patternsService');
Expand Down
2 changes: 1 addition & 1 deletion app/components/gui/eventList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var ListGroup = require('react-bootstrap').ListGroup;
var ListGroupItem = require('react-bootstrap').ListGroupItem;
var Button = require('react-bootstrap').Button;

var BrowserWindow = require('electron').remote.BrowserWindow;
const BrowserWindow = require('@electron/remote').BrowserWindow;

var log = require('../../logger');
var Eventer = require('../../eventer');
Expand Down
2 changes: 1 addition & 1 deletion app/components/gui/preferencesModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var Eventer = require('../../eventer');

var Blink1SerialOption = require('./blink1SerialOption');

var app = require('electron').remote.app;
var app = require('@electron/remote').app;
var path = require('path');

const propTypes = {
Expand Down
6 changes: 3 additions & 3 deletions app/components/gui/scriptForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var Checkbox = require('react-bootstrap').Checkbox;

var Switch = require('react-bootstrap-switch');

var dialog = require('electron').remote.dialog;
var dialog = require('@electron/remote').dialog;

var Blink1SerialOption = require('./blink1SerialOption');

Expand Down Expand Up @@ -59,7 +59,7 @@ var ScriptForm = React.createClass({
},
openFileDialog: async function() {
var self = this;
const result = await dialog.showOpenDialog();
const result = await dialog.showOpenDialog( { properties: ['openFile']} );
if( result.filePaths[0] ) {
self.setState({path: result.filePaths[0]});
}
Expand Down Expand Up @@ -115,7 +115,7 @@ var ScriptForm = React.createClass({
</FormGroup>
<FormGroup controlId="formPath" >
<Col sm={3} componentClass={ControlLabel}> {pathlabel} </Col>
<Col sm={8}>
<Col sm={8} title="Click to change path">
{type==='url' ?
<FormControl type="text" placeholder={pathplaceholder}
name="path" value={this.state.path} onChange={this.handleInputChange} />
Expand Down
15 changes: 8 additions & 7 deletions app/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ var isRenderer = require('is-electron-renderer');
var confdefaults = require('./blink1control2-config-defaults.json');
// var log = require('./logger');

// const { nconf, app } = require('@electron/remote')

// make sure we only use 'nconf' from non-renderer process
// because nconf uses yargs which makes webpack choke
if( isRenderer ) {
var remote = require('electron').remote;
nconf = remote.require('nconf');
app = remote.app;
nconf = require('@electron/remote').require('nconf')
app = require('@electron/remote').app
}
else {
nconf = require('nconf');
Expand Down Expand Up @@ -58,10 +59,10 @@ var Config = {
nconf.load();
return nconf.get(settingKey);
},
getFilepath: function() {
return conf_file;
// return nconf.stores.file.file; //FIXME: seems weird
},
// getFilepath: function() {
// return conf_file;
// // return nconf.stores.file.file; //FIXME: seems weird
// },
// getUserDataHome: function() {
// var userDataHome = app.getPath('userData');
// return userDataHome;
Expand Down
16 changes: 14 additions & 2 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ var isAccelerator = require("electron-is-accelerator");

var updater = require('./updater');

require('@electron/remote/main').initialize()

var isDevelopment = process.env.NODE_ENV === 'development';

var mainWindow = null;


console.log("isDevelopment:",isDevelopment);

const instanceLock = app.requestSingleInstanceLock()
Expand All @@ -44,6 +47,9 @@ else {
var pkg = require('./package.json');
var config = require('./configuration');

//console.log("PKG: ", pkg);
console.log("config: ", config);

crashReporter.start({
productName: pkg.productName,
companyName: pkg.companyName,
Expand Down Expand Up @@ -111,8 +117,13 @@ var openAboutWindow = function () {
autoHideMenuBar: true,
height: 375,
width: 500,
webPreferences: { nodeIntegration: true, contextIsolation: false, enableRemoteModule: true }
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
});
require("@electron/remote/main").enable(aboutWindow.webContents);
//aboutWindow.webContents.openDevTools({mode:'detach'});
aboutWindow.webContents.on('new-window', function(e,url) { handleUrl(e,url); } );
aboutWindow.webContents.on('will-navigate', function(e,url) { handleUrl(e,url); } );
aboutWindow.loadURL( 'file://' + __dirname + '/about.html') //+autoUpdateMsg );
Expand Down Expand Up @@ -233,10 +244,11 @@ app.on('ready', function () {
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
backgroundThrottling: false
}
});
require("@electron/remote/main").enable(mainWindow.webContents);

mainWindow.loadURL(loadurl);
if(isDevelopment) {
mainWindow.webContents.openDevTools({mode:'detach'});
Expand Down
5 changes: 0 additions & 5 deletions app/maingui.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ require('../node_modules/react-bootstrap-switch/dist/css/bootstrap3/react-bootst
var React = require('react');
var ReactDOM = require('react-dom');

// console.log("NOD_ENV:",process.env.NODE_ENV);

// var Perf = require('react-addons-perf');

var ipcRenderer = require('electron').ipcRenderer;


var conf = require('./configuration');
var log = require('./logger');

Expand Down
12 changes: 8 additions & 4 deletions app/menuMaker.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"use strict";

var remote = require('electron').remote;
var Menu = remote.Menu;
var Tray = remote.Tray;
var app = remote.app;
const Menu = require('@electron/remote').Menu
const Tray = require('@electron/remote').Tray
const app = require('@electron/remote').app

// var remote = require('electron').remote;
// var Menu = remote.Menu;
// var Tray = remote.Tray;
// var app = remote.app;
var ipcRenderer = require('electron').ipcRenderer;

var config = require('./configuration');
Expand Down
3 changes: 2 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Blink1Control2",
"version": "2.2.7",
"version": "2.2.8",
"author": "ThingM <blink1@thingm.com> (https://blink1.thingm.com/)",
"description": "Blink1Control2 GUI app for blink(1) devices",
"productName": "Blink1Control2",
Expand All @@ -11,6 +11,7 @@
"license": "ISC",
"main": "main.js",
"dependencies": {
"@electron/remote": "^2.0.8",
"d3-timer": "^1.0.10",
"debug": "^2.2.0",
"electron-is-accelerator": "^0.2.0",
Expand Down
25 changes: 15 additions & 10 deletions app/server/blink1Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ var Blink1Service = {
/**
* Add a blink1 to the device list.
* @constructor
* @param {string} serialnumber - serialnumber of blink1 to add
* @param {string} serialnumber - serialnumber of blink1 to add, will be converted to uppercase if needed
*/
_addDevice: function(serialnumber) {
log.msg("Blink1Service._addDevice:", serialnumber);
var olddev = blink1s.find( (blink1) => blink1.serial===serialnumber );
serialnumber = serialnumber.toUpperCase()
var olddev = blink1s.find( (blink1) => blink1.serial===serialnumber);
if( !olddev ) {
log.msg("Blink1Service._addDevice: new serial ", serialnumber);
blink1s.push( { serial: serialnumber, device: null } );
blink1s.push( { serial: serialnumber, device: null } ); // standardize that serials are uppercase
}
// set up all devices at once
// we wait 500msec because it was failing without it (USB HID delay?)
Expand All @@ -140,10 +141,14 @@ var Blink1Service = {
_setupFoundDevices: function() {
var self = this;
log.msg("Blink1Service._setupFoundDevices", blink1s, "conf: ", self.conf);
blink1s.map( function(b1) {
if( !b1.device ) {
log.msg("Blink1Service._setupFoundDevices: opening ",b1.serial);
b1.device = new Blink1(b1.serial);
blink1s.map( function(b) {
if( !b.device ) {
log.msg("Blink1Service._setupFoundDevices: opening ",b.serial);
var dev = new Blink1(b.serial.toLowerCase());
if( !dev ) {
dev = new Blink1(b.serial);
}
b.device = dev
}
});

Expand All @@ -159,7 +164,7 @@ var Blink1Service = {
_removeDevice: function(serialnumber) {
log.msg("Blink1Service._removeDevice: current devices:", blink1s);
blink1s = blink1s.filter( (blink1) => {
if( blink1.serial === serialnumber ) {
if( blink1.serial.toUpperCase() === serialnumber ) {
if( blink1.device ) { blink1.device.close(); blink1.device==null; }
return false; // remove it
}
Expand Down Expand Up @@ -230,7 +235,7 @@ var Blink1Service = {
* @return {Array} array of blink1 serialnumbers
*/
getAllSerials: function() {
return blink1s.map(function(b1) { return b1.serial; });
return blink1s.map(function(b) { return b.serial; });
},
// FIXME: support multiple blink1s
/**
Expand Down Expand Up @@ -373,7 +378,7 @@ var Blink1Service = {
// otherwise it's a blink1 serialnumber, so search for it
blink1id = blink1id.toString().toUpperCase();
blink1s.map( function(b,idx) {
if( blink1id === b.serial ) {
if( blink1id.toUpperCase() === b.serial ) {
blink1idx = idx;
}
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Blink1Control2",
"version": "2.2.7",
"version": "2.2.8",
"author": "ThingM <blink1@thingm.com> (https://blink1.thingm.com/)",
"description": "Blink1Control2 GUI app for blink(1) devices",
"keywords": [
Expand Down Expand Up @@ -126,7 +126,7 @@
"cross-env": "^5.0.5",
"css-loader": "^2.1.1",
"devtron": "^1.4.0",
"electron": "^12.2.2",
"electron": "^18.3.5",
"electron-builder": "^23.0.3",
"electron-notarize": "^1.0.0",
"file-loader": "^3.0.1",
Expand Down