Skip to content

Commit

Permalink
Add 1.2.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pcprince committed Nov 18, 2020
1 parent 138d131 commit 7123ffe
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 25 deletions.
76 changes: 62 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const electronLog = require('electron-log');

const firmwareInterface = require('./firmwareInterface.js');
const comms = require('./communication.js');
const versionChecker = require('./versionChecker.js');

/* File size limits for local binary files */
const MAX_FILE_SIZE = 256 * 1024 - 0x4000;
Expand Down Expand Up @@ -573,38 +574,36 @@ flashButtonLocal.addEventListener('click', function () {

/* File select button for local firmware files */

function selectBinary () {
async function selectBinary () {

var isValid;
var isValid, filenames;

dialog.showOpenDialog({
filenames = await dialog.showOpenDialog({
title: 'Select firmware binary',
nameFieldLabel: 'Binary file',
multiSelections: false,
filters: [{
name: 'bin',
extensions: ['bin']
}]
}, async function (filenames) {

if (filenames) {
});

/* Check if binary is a valid firmware file */
isValid = await firmwareInterface.isFirmwareFile(filenames[0]);
if (filenames) {

if (isValid) {
/* Check if binary is a valid firmware file */
isValid = await firmwareInterface.isFirmwareFile(filenames.filePaths[0]);

firmwareInterface.updateFirmwareDirectoryDisplay(filenames[0]);
if (isValid) {

} else {
firmwareInterface.updateFirmwareDirectoryDisplay(filenames.filePaths[0]);

comms.displayError('Invalid binary', 'Chosen firmware binary is not valid AudioMoth firmware.\nSelect a different file and try again.');
} else {

}
comms.displayError('Invalid binary', 'Chosen firmware binary is not valid AudioMoth firmware.\nSelect a different file and try again.');

}

});
}

}

Expand Down Expand Up @@ -641,6 +640,55 @@ function updateStatusText () {

}

electron.ipcRenderer.on('update-check', function () {

versionChecker.checkLatestRelease(function (response) {

var buttonIndex;

if (response.error) {

console.error(response.error);

dialog.showMessageBox(electron.remote.getCurrentWindow(), {
type: 'error',
title: 'Failed to check for updates',
message: response.error
});

return;

}

if (response.updateNeeded === false) {

dialog.showMessageBox(electron.remote.getCurrentWindow(), {
type: 'info',
title: 'Update not needed',
message: 'Your app is on the latest version (' + response.latestVersion + ').'
});

return;

}

buttonIndex = dialog.showMessageBoxSync({
type: 'warning',
buttons: ['Yes', 'No'],
title: 'Are you sure?',
message: 'A newer version of this app is available (' + response.latestVersion + '), would you like to download it?'
});

if (buttonIndex === 0) {

electron.shell.openExternal('https://www.openacousticdevices.info/applications');

}

});

});

/* Prepare UI */

firmwareInterface.updateFirmwareDirectoryDisplay('');
Expand Down
2 changes: 2 additions & 0 deletions firmwareInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

'use strict';

/* global XMLHttpRequest */

const electron = require('electron');
const dialog = electron.remote.dialog;
const app = electron.remote.app;
Expand Down
7 changes: 7 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,13 @@ app.on('ready', function () {

mainWindow.webContents.send('logfile');

}
}, {
label: 'Check For Updates',
click: function () {

mainWindow.webContents.send('update-check');

}
}, {
type: 'separator'
Expand Down
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"name": "AudioMoth-Flash",
"version": "1.1.0",
"version": "1.2.0",
"description": "The flashing app used to apply firmware to the AudioMoth acoustic monitoring device.",
"main": "main.js",
"author": "openacousticdevices.info",
"license": "ISC",
"repository": {
"type" : "git",
"url" : "https://github.com/OpenAcousticDevices/AudioMoth-Flash-App.git"
},
"scripts": {
"postinstall": "install-app-deps",
"start": "electron .",
Expand Down Expand Up @@ -51,26 +55,26 @@
}
},
"devDependencies": {
"electron": "6.0.1",
"electron-builder": "^21.2.0",
"eslint": "^6.7.2",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.19.1",
"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.1"
"eslint-plugin-standard": "^4.0.2"
},
"dependencies": {
"audiomoth-hid": "^2.0.4",
"audiomoth-hid": "^2.1.0",
"bootstrap": "4.3.1",
"drivelist": "^8.0.7",
"drivelist": "9.1.0",
"electron-debug": "3.0.1",
"electron-dl": "^1.14.0",
"electron-log": "^4.0.6",
"electron-log": "^4.3.0",
"electron-progressbar": "^1.2.0",
"jquery": "^3.5.1",
"popper.js": "^1.15.0",
"serialport": "^8.0.7",
"serialport": "^8.0.8",
"showdown": "^1.9.1"
},
"engines": {
Expand Down
99 changes: 99 additions & 0 deletions versionChecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/****************************************************************************
* versionChecker.js
* openacousticdevices.info
* November 2020
*****************************************************************************/

'use strict';

/* global XMLHttpRequest */

const electron = require('electron');

var pjson = require('./package.json');

/* 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;

}

/* 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;

/* Check for internet connection */

if (!navigator.onLine) {

callback({updateNeeded: false, error: 'No internet connection, failed to request app version information.'});
return;

}

version = electron.remote.app.getVersion();

/* Transform repository URL into release API URL */

repoGitURL = pjson.repository.url;
repoURL = repoGitURL.replace('.git', '/releases');
repoURL = repoURL.replace('github.com', 'api.github.com/repos');

xmlHttp = new XMLHttpRequest();
xmlHttp.open('GET', repoURL, true);

xmlHttp.onload = function () {

if (xmlHttp.status === 200) {

responseJson = JSON.parse(xmlHttp.responseText);

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);

callback({updateNeeded: updateNeeded, latestVersion: updateNeeded ? latestVersion : version});

}

};

xmlHttp.onerror = function () {

console.error('Failed to pull release information.');
callback({updateNeeded: false, error: 'HTTP connection error, failed to request app version information.'});

};

/* Send request */

xmlHttp.send(null);

};

0 comments on commit 7123ffe

Please sign in to comment.