reng 2 months ago
parent 68fde27c7c
commit 360c092875
  1. 12
      src-tauri/2
  2. 23
      src/App.jsx
  3. 11
      src/utils/backend.js

@ -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.

@ -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,11 +154,15 @@ 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();
}).catch((error) => {
console.error("Error deleting print record:", error);
});
}).catch((error) => {
console.error("Error sending print job for latest print:", error);

@ -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(){

Loading…
Cancel
Save