Skip to content

Commit

Permalink
Add 1.1.1 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pcprince committed Sep 26, 2023
1 parent c9e1ec0 commit d1f81ce
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 134 deletions.
2 changes: 1 addition & 1 deletion about.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<title>About AudioMoth Time App</title>
<link id="uiCSS" rel="stylesheet" href="./ui.css">
</head>

<body style="text-align: center; -webkit-user-select: none; -webkit-app-region: drag;">
Expand Down
30 changes: 23 additions & 7 deletions about.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,34 @@
/* global document */

const electron = require('electron');
const {app, process} = require('@electron/remote');
const audiomoth = require('audiomoth-hid');
const nightMode = require('./nightMode.js');

var versionDisplay = document.getElementById('version-display');
var electronVersionDisplay = document.getElementById('electron-version-display');
var audiomothHidVersionDisplay = document.getElementById('audiomoth-hid-version-display');
var websiteLink = document.getElementById('website-link');
const versionDisplay = document.getElementById('version-display');
const electronVersionDisplay = document.getElementById('electron-version-display');
const audiomothHidVersionDisplay = document.getElementById('audiomoth-hid-version-display');
const websiteLink = document.getElementById('website-link');

versionDisplay.textContent = 'Version ' + electron.remote.app.getVersion();
electronVersionDisplay.textContent = 'Running on Electron version ' + electron.remote.process.versions.electron;
versionDisplay.textContent = 'Version ' + app.getVersion();
electronVersionDisplay.textContent = 'Running on Electron version ' + process.versions.electron;
audiomothHidVersionDisplay.textContent = 'AudioMoth-HID module ' + audiomoth.version;

websiteLink.addEventListener('click', function () {
electron.ipcRenderer.on('night-mode', (e, nm) => {

if (nm !== undefined) {

nightMode.setNightMode(nm);

} else {

nightMode.toggle();

}

});

websiteLink.addEventListener('click', () => {

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

Expand Down
100 changes: 62 additions & 38 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,35 @@
/* global document */

const electron = require('electron');
const clipboard = electron.remote.clipboard;
const menu = electron.remote.Menu;
const dialog = electron.remote.dialog;
const {clipboard, Menu, dialog, getCurrentWindow} = require('@electron/remote');

const strftime = require('strftime').utc();
const audiomoth = require('audiomoth-hid');

const versionChecker = require('./versionChecker.js');
const nightMode = require('./nightMode.js');

/* UI components */

var applicationMenu = menu.getApplicationMenu();
const applicationMenu = Menu.getApplicationMenu();

var timeDisplay = document.getElementById('time-display');
var idLabel = document.getElementById('id-label');
var idDisplay = document.getElementById('id-display');
var firmwareVersionLabel = document.getElementById('firmware-version-label');
var firmwareVersionDisplay = document.getElementById('firmware-version-display');
var firmwareDescriptionLabel = document.getElementById('firmware-description-label');
var firmwareDescriptionDisplay = document.getElementById('firmware-description-display');
var batteryLabel = document.getElementById('battery-label');
var batteryDisplay = document.getElementById('battery-display');
const timeDisplay = document.getElementById('time-display');
const idLabel = document.getElementById('id-label');
const idDisplay = document.getElementById('id-display');
const firmwareVersionLabel = document.getElementById('firmware-version-label');
const firmwareVersionDisplay = document.getElementById('firmware-version-display');
const firmwareDescriptionLabel = document.getElementById('firmware-description-label');
const firmwareDescriptionDisplay = document.getElementById('firmware-description-display');
const batteryLabel = document.getElementById('battery-label');
const batteryDisplay = document.getElementById('battery-display');

var setTimeButton = document.getElementById('set-time-button');
const setTimeButton = document.getElementById('set-time-button');

var communicating = false;
const MILLISECONDS_IN_SECOND = 1000;

var currentTime, deviceId, firmwareVersion, firmwareDescription;
let communicating = false;

let currentTime, deviceId, firmwareVersion, firmwareDescription;

/* Time display functions */

Expand Down Expand Up @@ -80,7 +81,7 @@ function enableDisplayAndShowTime (date) {

}

var strftimeUTC = strftime.timezone(0);
const strftimeUTC = strftime.timezone(0);

timeDisplay.textContent = strftimeUTC('%H:%M:%S %d/%m/%Y UTC', date);

Expand Down Expand Up @@ -150,6 +151,8 @@ function requestFirmwareDescription () {

audiomoth.getFirmwareDescription(function (err, description) {

if (communicating) return;

if (err) {

errorOccurred(err);
Expand All @@ -174,6 +177,8 @@ function requestFirmwareVersion () {

audiomoth.getFirmwareVersion(function (err, versionArr) {

if (communicating) return;

if (err) {

errorOccurred(err);
Expand All @@ -198,6 +203,8 @@ function requestBatteryState () {

audiomoth.getBatteryState(function (err, batteryState) {

if (communicating) return;

if (err) {

errorOccurred(err);
Expand All @@ -224,6 +231,8 @@ function requestID () {

audiomoth.getID(function (err, id) {

if (communicating) return;

if (err) {

errorOccurred(err);
Expand All @@ -246,14 +255,12 @@ function requestID () {

function requestTime () {

if (communicating) {

return;

}
if (communicating) return;

audiomoth.getTime(function (err, date) {

if (communicating) return;

if (err) {

errorOccurred(err);
Expand All @@ -270,10 +277,16 @@ function requestTime () {

}

setTimeout(requestTime, 300);

});

const milliseconds = Date.now() % MILLISECONDS_IN_SECOND;

let delay = MILLISECONDS_IN_SECOND / 2 - milliseconds;

if (delay < 0) delay += MILLISECONDS_IN_SECOND;

setTimeout(requestTime, delay);

}

function setTime (time) {
Expand Down Expand Up @@ -315,13 +328,11 @@ electron.ipcRenderer.on('update-check', function () {

versionChecker.checkLatestRelease(function (response) {

var buttonIndex;

if (response.error) {

console.error(response.error);

dialog.showMessageBox(electron.remote.getCurrentWindow(), {
dialog.showMessageBox(getCurrentWindow(), {
type: 'error',
title: 'Failed to check for updates',
message: response.error
Expand All @@ -333,7 +344,7 @@ electron.ipcRenderer.on('update-check', function () {

if (response.updateNeeded === false) {

dialog.showMessageBox(electron.remote.getCurrentWindow(), {
dialog.showMessageBox(getCurrentWindow(), {
type: 'info',
title: 'Update not needed',
message: 'Your app is on the latest version (' + response.latestVersion + ').'
Expand All @@ -343,7 +354,7 @@ electron.ipcRenderer.on('update-check', function () {

}

buttonIndex = dialog.showMessageBoxSync({
const buttonIndex = dialog.showMessageBoxSync({
type: 'warning',
buttons: ['Yes', 'No'],
title: 'Are you sure?',
Expand All @@ -368,16 +379,15 @@ initialiseDisplay();

setTimeButton.addEventListener('click', function () {

var sendTime, now, delay, sendTimeDiff, USB_LAG, MINIMUM_DELAY, MILLISECONDS_IN_SECOND;

communicating = true;

timeDisplay.style.color = 'lightgrey';

USB_LAG = 20;
const USB_LAG = 20;

MINIMUM_DELAY = 100;
const MINIMUM_DELAY = 100;

MILLISECONDS_IN_SECOND = 1000;
const MILLISECONDS_IN_SECOND = 1000;

/* Update button */

Expand All @@ -395,18 +405,18 @@ setTimeButton.addEventListener('click', function () {

/* Increment to next second transition */

sendTime = new Date();
const sendTime = new Date();

delay = MILLISECONDS_IN_SECOND - sendTime.getMilliseconds() - USB_LAG;
let delay = MILLISECONDS_IN_SECOND - sendTime.getMilliseconds() - USB_LAG;

if (delay < MINIMUM_DELAY) delay += MILLISECONDS_IN_SECOND;

sendTime.setMilliseconds(sendTime.getMilliseconds() + delay);

/* Calculate how long to wait until second transition */

now = new Date();
sendTimeDiff = sendTime.getTime() - now.getTime();
const now = new Date();
const sendTimeDiff = sendTime.getTime() - now.getTime();

/* Either send immediately or wait until the transition */

Expand All @@ -428,4 +438,18 @@ setTimeButton.addEventListener('click', function () {

});

electron.ipcRenderer.on('night-mode', (e, nm) => {

if (nm !== undefined) {

nightMode.setNightMode(nm);

} else {

nightMode.toggle();

}

});

requestTime();
17 changes: 9 additions & 8 deletions builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@
const builder = require('electron-builder');
const Platform = builder.Platform;

var config, target;
var argTarget = process.argv[2];
let config, target;

const argTarget = process.argv[2];

switch (argTarget) {

case 'win':
case 'win64':
console.log('Using build configuration to Windows (64-bit).');
case 'win32':
console.log('Using build configuration to Windows (32-bit).');
target = Platform.WINDOWS.createTarget();
config = {
win: {
target: [
{
target: 'nsis',
arch: 'x64'
arch: 'ia32'
}
]
}
};
break;
case 'win32':
console.log('Using build configuration to Windows (32-bit).');
case 'win64':
console.log('Using build configuration to Windows (64-bit).');
target = Platform.WINDOWS.createTarget();
config = {
win: {
target: [
{
target: 'nsis',
arch: 'ia32'
arch: 'x64'
}
]
}
Expand Down
16 changes: 16 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}

*, *::after, *::before {
-webkit-user-select: none;
-webkit-user-drag: none;
-webkit-app-region: no-drag;
cursor: default;
}

.mono-text {
font-variant-numeric: tabular-nums;
}
10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

<head>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<title>AudioMoth Time App</title>
<link id="uiCSS" rel="stylesheet" href="ui.css">
</head>

<body style="background: #FFFFFF; font-size: 10pt; overflow-x:hidden; font-family: Helvetica, Arial, sans-serif; -webkit-user-select: none; -webkit-app-region: drag;">
<div class="container" style="padding: 11px;">
<body style="font-size: 10pt; overflow-x:hidden; font-family: Helvetica, Arial, sans-serif; -webkit-user-select: none; -webkit-app-region: drag;">
<div class="container" style="padding: 8px;">

<div class="row">
<div style="border: #cdcdcd thin solid; margin-left: 15px; width: 543px;">
<div class="row" style="margin-left: 0px;">
<div class="col-12" style="text-align: center; padding-top: 5px; padding-bottom: 5px">
<span style="font-size: 25px; font-family: &apos;Lucida Console&apos;, Monaco, monospace">
<span class="mono-text" style="font-size: 25px; font-family: &apos;Lucida Console&apos;, Monaco">
<div id="time-display" style="display: inline-block; color: lightgray;"></div>
</span>
</div>
Expand Down Expand Up @@ -58,7 +58,7 @@
</div>
</div>
<div class="row" style="margin-top: 8px;">
<div style="text-align: center; margin-left: 15px; width: 543px;">
<div style="text-align: center; margin-left: 15px; width: 543px; padding: 0px;">
<button id="set-time-button" class="btn btn-success" style="width: 100%;" disabled>Set Time</button>
</div>
</div>
Expand Down
Loading

0 comments on commit d1f81ce

Please sign in to comment.