diff --git a/index.html b/index.html
index 58b51582..818fa917 100644
--- a/index.html
+++ b/index.html
@@ -238,7 +238,16 @@
Settings
+
+
diff --git a/js/state.js b/js/state.js
index 1f00d6dc..a326c912 100644
--- a/js/state.js
+++ b/js/state.js
@@ -34,7 +34,8 @@ export class State {
this.local = true,
this.incrementor = 1,
this.UUID = 0,
- this.track = true
+ this.track = true,
+ this.powerSaveBlocker = false
}
diff --git a/js/ui.js b/js/ui.js
index d2796c91..7cad8986 100644
--- a/js/ui.js
+++ b/js/ui.js
@@ -506,9 +506,9 @@ async function showOpenDialog(fileOrFolder) {
}
}
-// function powerSave(on) {
-// return window.electron.powerSaveBlocker(on);
-// }
+function powerSave(on) {
+ return window.electron.powerSaveBlocker(on);
+}
const openFileInList = async (e) => {
if (!PREDICTING && e.target.tagName === 'A') {
@@ -1520,7 +1520,8 @@ const defaultConfig = {
limit: 500,
track: true,
debug: false,
- VERSION: VERSION
+ VERSION: VERSION,
+ powerSaveBlocker: false
};
let appPath, tempPath, isMac;
window.onload = async () => {
@@ -1604,7 +1605,6 @@ window.onload = async () => {
document.getElementById('mid-color').value = config.customColormap.mid;
document.getElementById('quiet-color').value = config.customColormap.quiet;
document.getElementById('color-threshold-slider').value = config.customColormap.threshold;
-
// Audio preferences:
DOM.gain.value = config.audio.gain;
DOM.gainAdjustment.textContent = config.audio.gain + 'dB';
@@ -1619,6 +1619,10 @@ window.onload = async () => {
DOM.audioDownmix.checked = config.audio.downmix;
setNocmig(config.detect.nocmig);
modelSettingsDisplay();
+ // Block powersave?
+ document.getElementById('power-save-block').checked = config.powerSaveBlocker;
+ powerSave(config.powerSaveBlocker);
+
contextAwareIconDisplay();
DOM.debugMode.checked = config.debug;
showThreshold(config.detect.confidence);
@@ -2453,11 +2457,9 @@ function onChartData(args) {
const backendEL = document.getElementById(config.backend);
backendEL.checked = true;
if (config.backend === 'webgl' || config.backend === 'webgpu') {
- //powerSave(true)
SNRSlider.disabled = true;
config.filters.SNR = 0;
} else {
- // powerSave(false)
DOM.contextAware.disabled = false;
if (DOM.contextAware.checked) {
config.detect.contextAware = true;
@@ -3661,7 +3663,6 @@ function onChartData(args) {
nodeOnly.forEach(element => element.classList.add('d-none'));
}
}
-
}
const contextAwareIconDisplay = () => {
@@ -4420,6 +4421,11 @@ DOM.gain.addEventListener('input', () => {
config.audio.notification = element.checked;
break;
}
+ case 'power-save-block': {
+ config.powerSaveBlocker = element.checked;
+ powerSave(config.powerSaveBlocker);
+ break;
+ }
case 'species-week': {
config.useWeek = element.checked;
diff --git a/main.js b/main.js
index 6e910a76..0d596218 100644
--- a/main.js
+++ b/main.js
@@ -1,4 +1,4 @@
-const { app, Menu, dialog, ipcMain, MessageChannelMain, BrowserWindow, globalShortcut } = require('electron');
+const { app, Menu, dialog, ipcMain, MessageChannelMain, BrowserWindow, globalShortcut, powerSaveBlocker } = require('electron');
app.commandLine.appendSwitch('disable-renderer-backgrounding');
// WebGPU flags needed for Linux
app.commandLine.appendSwitch('enable-unsafe-webgpu');
@@ -17,6 +17,7 @@ let files = [];
let DEBUG = false;
let unsavedRecords = false;
+
//-------------------------------------------------------------------
// Logging
@@ -436,6 +437,8 @@ app.whenReady().then(async () => {
properties: ['openDirectory']
});
})
+
+
mainWindow.webContents.setWindowOpenHandler(({ url, frameName }) => {
require('electron').shell.openExternal(url);
@@ -526,3 +529,15 @@ ipcMain.handle('saveFile', (event, arg) => {
mainWindow.webContents.send('saveFile', { message: 'file saved!' });
});
+
+let powerSaveID = powerSaveBlocker.start('prevent-app-suspension');
+powerSaveBlocker.stop(powerSaveID);
+ipcMain.handle('powerSaveControl', (e, on) => {
+ if (on){
+ powerSaveID = powerSaveBlocker.start('prevent-app-suspension')
+ //console.log(powerSaveBlocker.isStarted(powerSaveID), powerSaveID)
+ } else {
+ powerSaveBlocker.stop(powerSaveID)
+ //console.log(powerSaveBlocker.isStarted(powerSaveID), powerSaveID)
+ }
+})
\ No newline at end of file
diff --git a/preload.js b/preload.js
index e3953102..3b8b976d 100644
--- a/preload.js
+++ b/preload.js
@@ -1,4 +1,4 @@
-const {contextBridge, ipcRenderer} = require("electron");
+const {contextBridge, ipcRenderer } = require("electron");
const fs = require('node:fs');
const colormap = require("colormap");
const p = require('node:path');
@@ -53,7 +53,8 @@ contextBridge.exposeInMainWorld('electron', {
getVersion: () => ipcRenderer.invoke('getVersion'),
getAudio: () => ipcRenderer.invoke('getAudio'),
isMac: () => ipcRenderer.invoke('isMac'),
- exitApplication: () => ipcRenderer.invoke('exitApplication')
+ exitApplication: () => ipcRenderer.invoke('exitApplication'),
+ powerSaveBlocker: (onOff) => ipcRenderer.invoke('powerSaveControl', onOff)
});
contextBridge.exposeInMainWorld('module', {