main.js aktualisiert

This commit is contained in:
2025-09-24 19:30:49 +00:00
parent bba2e2c416
commit 45276945dc

18
main.js
View File

@@ -6,7 +6,7 @@ const chokidar = require("chokidar");
const axios = require("axios"); const axios = require("axios");
let OUT_DIR; // endgültiger Eingangsordner (wird in app.whenReady gesetzt) let OUT_DIR; // endgültiger Eingangsordner (wird in app.whenReady gesetzt)
let IMG_DIR; // Ausgabeordner für latest.png let IMG_DIR; // Ausgabeordner für PNGs (History)
let win; let win;
function createWindow() { function createWindow() {
@@ -217,23 +217,17 @@ async function processFile(filePath) {
return; return;
} }
// PNG speichern (latest.png) — alte PNGs löschen // PNG speichern — neue Datei mit Timestamp (History)
const pngBuffer = renderResult.buffer; const pngBuffer = renderResult.buffer;
try { const timestamp = Date.now();
fs.readdirSync(IMG_DIR).forEach(f => { const outFile = path.join(IMG_DIR, `label-${timestamp}.png`);
const fileToDelete = path.join(IMG_DIR, f);
try { if (fs.lstatSync(fileToDelete).isFile()) fs.unlinkSync(fileToDelete); } catch(e){}
});
} catch(e){}
const outFile = path.join(IMG_DIR, "latest.png");
fs.writeFileSync(outFile, pngBuffer); fs.writeFileSync(outFile, pngBuffer);
console.log("PNG erstellt:", outFile); console.log("PNG erstellt:", outFile);
// verarbeitete ZPL-Datei löschen (optional) // ZPL-Datei löschen (optional)
try { fs.unlinkSync(filePath); } catch(e){ console.warn("Konnte ZPL nicht löschen:", e.message); } try { fs.unlinkSync(filePath); } catch(e){ console.warn("Konnte ZPL nicht löschen:", e.message); }
// Fenster benachrichtigen // Fenster benachrichtigen (sende neuen PNG-Pfad)
win.webContents.send("show-png", outFile); win.webContents.send("show-png", outFile);
} catch (err) { } catch (err) {