-
diff --git a/main.js b/main.js
index 39fdd54..7b0b2b8 100644
--- a/main.js
+++ b/main.js
@@ -6,24 +6,21 @@
'use strict';
-var electron = require('electron');
-var app = electron.app;
+const {app, Menu, shell, ipcMain, BrowserWindow} = require('electron');
-var BrowserWindow = electron.BrowserWindow;
-var Menu = electron.Menu;
-var shell = electron.shell;
+require('@electron/remote/main').initialize();
+
+let mainWindow, aboutWindow;
require('electron-debug')({
showDevTools: 'undocked'
});
-var path = require('path');
+const path = require('path');
function openAboutWindow () {
- var aboutWindow, iconLocation;
-
- iconLocation = '/build/icon.ico';
+ let iconLocation = '/build/icon.ico';
if (process.platform === 'linux') {
@@ -34,24 +31,64 @@ function openAboutWindow () {
aboutWindow = new BrowserWindow({
width: 400,
height: 325,
+ title: 'About AudioMoth Time App',
resizable: false,
fullscreenable: false,
icon: path.join(__dirname, iconLocation),
+ parent: mainWindow,
webPreferences: {
- nodeIntegration: true
+ enableRemoteModule: true,
+ nodeIntegration: true,
+ contextIsolation: false
}
});
aboutWindow.setMenu(null);
aboutWindow.loadURL(path.join('file://', __dirname, '/about.html'));
+ require('@electron/remote/main').enable(aboutWindow.webContents);
+
+ aboutWindow.on('closed', () => {
+
+ aboutWindow = null;
+
+ });
+
+ aboutWindow.webContents.on('dom-ready', function () {
+
+ mainWindow.webContents.send('poll-night-mode');
+
+ });
+
+ ipcMain.on('night-mode-poll-reply', (e, nightMode) => {
+
+ if (aboutWindow) {
+
+ aboutWindow.webContents.send('night-mode', nightMode);
+
+ }
+
+ });
+
+}
+
+function toggleNightMode () {
+
+ mainWindow.webContents.send('night-mode');
+
+ if (aboutWindow) {
+
+ aboutWindow.webContents.send('night-mode');
+
+ }
+
}
app.on('ready', function () {
- var mainWindow, menuTemplate, menu, windowHeight, iconLocation;
+ let iconLocation = '/build/icon.ico';
- iconLocation = '/build/icon.ico';
+ let windowHeight = 250;
if (process.platform === 'darwin') {
@@ -62,27 +99,35 @@ app.on('ready', function () {
windowHeight = 230;
iconLocation = '/build/icon.png';
- } else {
-
- windowHeight = 250;
-
}
mainWindow = new BrowserWindow({
width: 565,
height: windowHeight,
useContentSize: true,
+ title: 'AudioMoth Time App',
resizable: false,
fullscreenable: false,
icon: path.join(__dirname, iconLocation),
webPreferences: {
- nodeIntegration: true
+ enableRemoteModule: true,
+ nodeIntegration: true,
+ contextIsolation: false
}
});
- menuTemplate = [{
+ require('@electron/remote/main').enable(mainWindow.webContents);
+
+ const menuTemplate = [{
label: 'File',
submenu: [{
+ type: 'checkbox',
+ id: 'nightmode',
+ label: 'Night Mode',
+ accelerator: 'CommandOrControl+N',
+ checked: false,
+ click: toggleNightMode
+ }, {
id: 'copyid',
label: 'Copy Device ID',
accelerator: 'CommandOrControl+I',
@@ -131,7 +176,7 @@ app.on('ready', function () {
}]
}];
- menu = Menu.buildFromTemplate(menuTemplate);
+ const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
diff --git a/nightMode.js b/nightMode.js
new file mode 100644
index 0000000..5d76571
--- /dev/null
+++ b/nightMode.js
@@ -0,0 +1,50 @@
+/****************************************************************************
+ * nightMode.js
+ * openacousticdevices.info
+ * December 2019
+ *****************************************************************************/
+
+'use strict';
+
+const {app} = require('@electron/remote');
+
+let nightMode = false;
+
+exports.isEnabled = () => {
+
+ return nightMode;
+
+};
+
+function setNightMode (nm) {
+
+ nightMode = nm;
+
+ const oldLink = document.getElementById('uiCSS');
+ const newLink = document.createElement('link');
+
+ newLink.setAttribute('id', 'uiCSS');
+ newLink.setAttribute('rel', 'stylesheet');
+ newLink.setAttribute('type', 'text/css');
+
+ if (nightMode) {
+
+ newLink.setAttribute('href', app.getAppPath() + '/uiNight.css');
+
+ } else {
+
+ newLink.setAttribute('href', app.getAppPath() + '/ui.css');
+
+ }
+
+ document.getElementsByTagName('head').item(0).replaceChild(newLink, oldLink);
+
+}
+
+exports.setNightMode = setNightMode;
+
+exports.toggle = () => {
+
+ setNightMode(!nightMode);
+
+};
diff --git a/package.json b/package.json
index a34c447..9de528d 100644
--- a/package.json
+++ b/package.json
@@ -1,13 +1,13 @@
{
"name": "AudioMoth-Time",
- "version": "1.1.0",
+ "version": "1.1.1",
"description": "The time app for the AudioMoth acoustic acoustic monitoring device.",
"main": "main.js",
"author": "openacousticdevices.info",
"license": "ISC",
"repository": {
- "type" : "git",
- "url" : "https://github.com/OpenAcousticDevices/AudioMoth-Time-App.git"
+ "type": "git",
+ "url": "https://github.com/OpenAcousticDevices/AudioMoth-Time-App.git"
},
"scripts": {
"postinstall": "install-app-deps",
@@ -45,6 +45,8 @@
},
"nsis": {
"createDesktopShortcut": true,
+ "oneClick": false,
+ "allowToChangeInstallationDirectory": true,
"artifactName": "AudioMothTimeAppSetup${version}.exe",
"shortcutName": "AudioMoth Time App",
"uninstallDisplayName": "AudioMoth Time App ${version}"
@@ -55,22 +57,26 @@
}
},
"devDependencies": {
- "electron": "8.5.2",
- "electron-builder": "^22.8.1",
- "eslint": "^6.8.0",
- "eslint-config-standard": "^14.1.1",
- "eslint-plugin-import": "^2.22.1",
- "eslint-plugin-node": "^10.0.0",
- "eslint-plugin-promise": "^4.2.1",
- "eslint-plugin-standard": "^4.0.2"
+ "electron": "25.3.2",
+ "electron-builder": "^24.6.3",
+ "eslint": "^8.45.0",
+ "eslint-plugin-n": "^16.0.1",
+ "eslint-config-standard": "^17.1.0",
+ "eslint-plugin-import": "^2.27.5",
+ "eslint-plugin-node": "^11.1.0",
+ "eslint-plugin-promise": "^6.1.1",
+ "eslint-plugin-standard": "^4.1.0"
},
"dependencies": {
+ "@electron/remote": "^2.0.10",
"audiomoth-hid": "^2.1.0",
- "bootstrap": "4.3.1",
- "electron-debug": "3.0.1",
- "jquery": "^3.5.1",
+ "bootstrap": "5.3.1",
+ "electron-debug": "3.2.0",
+ "jquery": "^3.7.0",
"popper.js": "^1.15.0",
- "strftime": "0.10.0"
+ "strftime": "0.10.2",
+ "http-cache-semantics": "^4.1.1",
+ "semver": "^7.5.4"
},
"engines": {
"node": ">=10.16.2"
diff --git a/ui.css b/ui.css
new file mode 100644
index 0000000..e69de29
diff --git a/uiNight.css b/uiNight.css
new file mode 100644
index 0000000..c1bc0ed
--- /dev/null
+++ b/uiNight.css
@@ -0,0 +1,18 @@
+body {
+ background: #000000;
+ color: #FFFFFF;
+}
+
+input {
+ background: #000000;
+ color: #FFFFFF;
+}
+
+select {
+ background: #000000;
+ color: #FFFFFF;
+}
+
+.grey {
+ color:#808080;
+}
\ No newline at end of file
diff --git a/versionChecker.js b/versionChecker.js
index 016d6d8..3729025 100644
--- a/versionChecker.js
+++ b/versionChecker.js
@@ -8,42 +8,15 @@
/* global XMLHttpRequest */
-const electron = require('electron');
+const {app} = require('@electron/remote');
-var pjson = require('./package.json');
+const semver = require('semver');
-/* Compare two semantic versions and return true if older */
-
-function isOlderSemanticVersion (aVersion, bVersion) {
-
- var aVersionNum, bVersionNum;
-
- for (let i = 0; i < aVersion.length; i++) {
-
- aVersionNum = aVersion[i];
- bVersionNum = bVersion[i];
-
- if (aVersionNum > bVersionNum) {
-
- return false;
-
- } else if (aVersionNum < bVersionNum) {
-
- return true;
-
- }
-
- }
-
- return false;
-
-}
+const pjson = require('./package.json');
/* Check current app version in package.json against latest version in repository's releases */
-exports.checkLatestRelease = function (callback) {
-
- var version, repoGitURL, repoURL, xmlHttp, responseJson, latestVersion, updateNeeded;
+exports.checkLatestRelease = (callback) => {
/* Check for internet connection */
@@ -54,38 +27,38 @@ exports.checkLatestRelease = function (callback) {
}
- version = electron.remote.app.getVersion();
+ const version = app.getVersion();
/* Transform repository URL into release API URL */
- repoGitURL = pjson.repository.url;
- repoURL = repoGitURL.replace('.git', '/releases');
+ const repoGitURL = pjson.repository.url;
+ let repoURL = repoGitURL.replace('.git', '/releases');
repoURL = repoURL.replace('github.com', 'api.github.com/repos');
- xmlHttp = new XMLHttpRequest();
+ const xmlHttp = new XMLHttpRequest();
xmlHttp.open('GET', repoURL, true);
- xmlHttp.onload = function () {
+ xmlHttp.onload = () => {
if (xmlHttp.status === 200) {
- responseJson = JSON.parse(xmlHttp.responseText);
+ const responseJson = JSON.parse(xmlHttp.responseText);
- latestVersion = responseJson[0].tag_name;
+ const latestVersion = responseJson[0].tag_name;
console.log('Comparing latest release (' + latestVersion + ') with currently installed version (' + version + ')');
/* Compare current version in package.json to latest version pulled from Github */
- updateNeeded = isOlderSemanticVersion(version, latestVersion);
+ const updateNeeded = semver.lt(version, latestVersion);
- callback({updateNeeded: updateNeeded, latestVersion: updateNeeded ? latestVersion : version});
+ callback({updateNeeded, latestVersion: updateNeeded ? latestVersion : version});
}
};
- xmlHttp.onerror = function () {
+ xmlHttp.onerror = () => {
console.error('Failed to pull release information.');
callback({updateNeeded: false, error: 'HTTP connection error, failed to request app version information.'});