From ab98c8a4a702ee34781851f58b142176b0751540 Mon Sep 17 00:00:00 2001 From: Mattk70 Date: Thu, 7 Mar 2024 17:03:43 +0000 Subject: [PATCH] Fixed 'export selected audio on file menu' Fixed analyse all for situations where all files are saved in diskDB --- js/ui.js | 16 ++++++++++------ js/worker.js | 12 ++++++++---- package.json | 6 +++--- prebuild.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 prebuild.js diff --git a/js/ui.js b/js/ui.js index d410a991..33ca7f38 100644 --- a/js/ui.js +++ b/js/ui.js @@ -1215,9 +1215,10 @@ function adjustSpecDims(redraw, fftSamples) { specElement.style.zIndex = 0; document.querySelector('.spec-labels').style.width = '55px'; } - if (wavesurfer && redraw) {} - specOffset = DOM.spectrogramWrapper.offsetHeight; - } else { + if (wavesurfer && redraw) { + specOffset = DOM.spectrogramWrapper.offsetHeight; + } + } else { specOffset = 0 } DOM.resultTableElement.style.height = (contentHeight - specOffset - formOffset) + 'px'; @@ -1482,6 +1483,7 @@ window.onload = async () => { if (config.model === 'birdnet') config.backend = 'tensorflow'; // Rename migrants list from old versions to new name: nocturnal if (config.list === 'migrants') config.list = 'nocturnal'; + // switch off fullscreen mode - we don't want to persist that setting config.fullscreen = false; // switch off debug mode we don't want this to be remembered @@ -4060,7 +4062,7 @@ DOM.gain.addEventListener('input', () => { case 'open': { showOpenDialog(); break } case 'saveLabels': { showSaveDialog(); break } case 'saveCSV': { export2CSV(); break } - case 'export-audio': { export2audio(); break } + case 'export-audio': { exportAudio(); break } case 'exit': { exitApplication(); break } case 'save2db': { worker.postMessage({ action: 'save2db', file: currentFile }); break } @@ -4468,10 +4470,12 @@ function track(event, action, name, value){ } const xc = document.getElementById('context-xc'); if (region?.attributes.label || hideInSummary) { + // the following line errors out when there's no active row: "undefined is not iterable" + // will need to think how to get sname in that situation (and how you can have a lebel without an active row!) let [,,,sname,cname] = activeRow?.getAttribute('name').split('|'); const XC_type = cname.includes('(song)') ? "song" : - cname.includes('call)') ? "nocturnal flight call" : ""; - xc.href = `https://xeno-canto.org/explore?query=${sname}%20type:"${XC_type}`; + cname.includes('call)') ? "call" : ""; + xc.href = `https://xeno-canto.org/explore?query=${sname}%20type:"${XC_type}"`; // only offer XC lookup if we have an sname sname && xc.classList.remove('d-none'); } diff --git a/js/worker.js b/js/worker.js index 42d7a3af..d557bef2 100644 --- a/js/worker.js +++ b/js/worker.js @@ -761,10 +761,14 @@ const prepSummaryStatement = (included) => { // BECAUSE we want to change state.db to disk if they are let allCached = true; for (let i = 0; i < FILE_QUEUE.length; i++) { - if (!await getSavedFileInfo(FILE_QUEUE[i])) { + const file = FILE_QUEUE[i]; + const row = await getSavedFileInfo(file) + if (row) { + await setMetadata({file: file}) + } else { allCached = false; break; - } + } } const retrieveFromDatabase = ((allCached && !reanalyse && !STATE.selection) || circleClicked); if (retrieveFromDatabase) { @@ -906,7 +910,7 @@ const prepSummaryStatement = (included) => { goToRegion = true }) { - const found = await getWorkingFile(file); + const found = metadata[file]?.proxy || await getWorkingFile(file); if (found) { await fetchAudioBuffer({ file, start, end }) .then((buffer) => { @@ -2548,7 +2552,7 @@ const prepSummaryStatement = (included) => { if (!row) { const baseName = file.replace(/^(.*)\..*$/g, '$1%'); row = await diskDB.getAsync('SELECT * FROM files LEFT JOIN locations ON files.locationID = locations.id WHERE name LIKE (?)',baseName); - } + } return row }; diff --git a/package.json b/package.json index 08c0fa9d..512de6be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chirpity", - "version": "1.5.0", + "version": "1.5.1", "description": "Chirpity Nocmig", "main": "main.js", "scripts": { @@ -13,6 +13,7 @@ "type": "git", "url": "git+https://github.com/mattk70/Chirpity-Electron.git" }, + "beforeBuild": "prebuild.js", "build": { "appId": "com.electron.chirpity", "publish": [ @@ -29,6 +30,7 @@ "!.vscode${/*}", "!.idea{*/}", "!kernels.txt", + "!prebuild.js", "!minify.js", "!playwright.*", "!dist${/*}", @@ -36,11 +38,9 @@ "!*fixed_roll*${/*}", "!Help/example.mp3", "!venv${/*}", - "!test${/*}", "!custom_tfjs${/*}", "!*git*${/*}", "!package-lock.json", - "!poetry.lock*", "!pyproject.toml", "!README.md", "!saved_model$(/*)", diff --git a/prebuild.js b/prebuild.js new file mode 100644 index 00000000..2562e7d6 --- /dev/null +++ b/prebuild.js @@ -0,0 +1,47 @@ +const fs = require('fs'); +const path = require('path'); + +// Define the directory where your source files are located +const SOURCE_DIR = "C:/Users/simpo/PycharmProjects/Chirpity-Electron"; + +// Function to recursively search for patterns in files +function searchPatterns(directory, patterns) { + const files = fs.readdirSync(directory); + + files.forEach(file => { + const filePath = path.join(directory, file); + const stats = fs.statSync(filePath); + if (stats.isDirectory() || file.endsWith('.js')){ + if (stats.isDirectory()) { + if (! filePath.includes('node_modules')) { + searchPatterns(filePath, patterns); + } + } else if (stats.isFile()) { + const content = fs.readFileSync(filePath, 'utf8'); + patterns.forEach(pattern => { + if (content.match(pattern)) { + throw new Error(`Pattern '${pattern}' found in file: ${filePath}`); + // You can add further actions here if needed + } + }); + } + } + }); +} + +// Define the patterns you want to search for +const patterns = [ + /DEBUG\s*=\s*true/, + /ID_SITE\s*=\s*3/ + // Add more patterns as needed +]; + +// Search for the patterns in the source directory +try { + searchPatterns(SOURCE_DIR, patterns); + console.log("No patterns found. Proceeding with the build..."); +} catch (error) { + console.error("An error occurred while searching for the patterns:", error.message); + console.error("One or more patterns found. Aborting the build."); + process.exit(1); +}