diff --git a/src-tauri/2 b/src-tauri/2 deleted file mode 100644 index 98f8bb3..0000000 --- a/src-tauri/2 +++ /dev/null @@ -1,12 +0,0 @@ - -added 1 package, changed 1 package, and audited 257 packages in 5s - -28 packages are looking for funding - run `npm fund` for details - -1 low severity vulnerability - -To address all issues, run: - npm audit fix - -Run `npm audit` for details. diff --git a/src/App.jsx b/src/App.jsx index b7ffd25..cf57dd4 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,7 +1,7 @@ import { invoke } from "@tauri-apps/api/core"; import { open, save } from '@tauri-apps/plugin-dialog'; import "./App.css"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { AvailableQualities } from "./params"; import { listenToPrints, clearPrints, deletePrint, createTestFile } from "./utils/backend"; import { saveToDisk, loadSettings, saveSettings } from "./utils/fs"; @@ -13,6 +13,7 @@ const OptionTypes=[ 'quality_options', ] const ENABLE_OPTIONS=false; +const DEBUG_MODE=true; function App() { @@ -23,6 +24,8 @@ function App() { const [prints, setPrints] = useState([]); + const refPrintingFiles=useRef([]); + function getPrinters() { invoke("get_all_printers") .then((printers) => { @@ -75,7 +78,10 @@ function App() { function printDocument() { - + if(DEBUG_MODE){ + console.log('debug mode, skipping print'); + return; + } const file= selectedFile; if (!file) { console.error("No document selected for printing."); @@ -128,6 +134,11 @@ function App() { const latestPrint = prints[prints.length - 1]; console.log("Latest print job:", latestPrint); + if(refPrintingFiles.current.includes(latestPrint.id)){ + console.log(`Print job with id ${latestPrint.id} is already being processed.`); + return; + } + refPrintingFiles.current.push(latestPrint.id); setPrinting(latestPrint.id); // save url to local disk @@ -143,10 +154,14 @@ function App() { console.log("Print job sent successfully for latest print."); // TODO: clear print records - deletePrint(latestPrint.id); // Clear the print record after sending the job - console.log("Print record deleted:", latestPrint.id); + deletePrint(latestPrint.id).then(() => { + + console.log("Print record deleted:", latestPrint.id); + setPrinting(); - setPrinting(); + }).catch((error) => { + console.error("Error deleting print record:", error); + }); }).catch((error) => { console.error("Error sending print job for latest print:", error); diff --git a/src/utils/backend.js b/src/utils/backend.js index 8e865e2..319acef 100644 --- a/src/utils/backend.js +++ b/src/utils/backend.js @@ -48,18 +48,17 @@ export function clearPrints() { }); } -export function deletePrint(id) { +export async function deletePrint(id) { // Delete a specific print by id const db = getFirestore(app); const printRef = doc(collection(db, CollectionName), id); - deleteDoc(printRef) - .then(() => { + try{ + const result = await deleteDoc(printRef); console.log(`Print with id ${id} deleted successfully.`); - }) - .catch((error) => { + }catch (error){ console.error(`Error deleting print with id ${id}:`, error); - }); + } } export function createTestFile(){