|
|
|
@ -1,7 +1,7 @@ |
|
|
|
import { invoke } from "@tauri-apps/api/core"; |
|
|
|
import { invoke } from "@tauri-apps/api/core"; |
|
|
|
import { open, save } from '@tauri-apps/plugin-dialog'; |
|
|
|
import { open, save } from '@tauri-apps/plugin-dialog'; |
|
|
|
import "./App.css"; |
|
|
|
import "./App.css"; |
|
|
|
import { useEffect, useState } from "react"; |
|
|
|
import { useEffect, useRef, useState } from "react"; |
|
|
|
import { AvailableQualities } from "./params"; |
|
|
|
import { AvailableQualities } from "./params"; |
|
|
|
import { listenToPrints, clearPrints, deletePrint, createTestFile } from "./utils/backend"; |
|
|
|
import { listenToPrints, clearPrints, deletePrint, createTestFile } from "./utils/backend"; |
|
|
|
import { saveToDisk, loadSettings, saveSettings } from "./utils/fs"; |
|
|
|
import { saveToDisk, loadSettings, saveSettings } from "./utils/fs"; |
|
|
|
@ -13,6 +13,7 @@ const OptionTypes=[ |
|
|
|
'quality_options', |
|
|
|
'quality_options', |
|
|
|
] |
|
|
|
] |
|
|
|
const ENABLE_OPTIONS=false; |
|
|
|
const ENABLE_OPTIONS=false; |
|
|
|
|
|
|
|
const DEBUG_MODE=true; |
|
|
|
|
|
|
|
|
|
|
|
function App() { |
|
|
|
function App() { |
|
|
|
|
|
|
|
|
|
|
|
@ -23,6 +24,8 @@ function App() { |
|
|
|
|
|
|
|
|
|
|
|
const [prints, setPrints] = useState([]); |
|
|
|
const [prints, setPrints] = useState([]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const refPrintingFiles=useRef([]); |
|
|
|
|
|
|
|
|
|
|
|
function getPrinters() { |
|
|
|
function getPrinters() { |
|
|
|
invoke("get_all_printers") |
|
|
|
invoke("get_all_printers") |
|
|
|
.then((printers) => { |
|
|
|
.then((printers) => { |
|
|
|
@ -75,7 +78,10 @@ function App() { |
|
|
|
|
|
|
|
|
|
|
|
function printDocument() { |
|
|
|
function printDocument() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(DEBUG_MODE){ |
|
|
|
|
|
|
|
console.log('debug mode, skipping print'); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
const file= selectedFile; |
|
|
|
const file= selectedFile; |
|
|
|
if (!file) { |
|
|
|
if (!file) { |
|
|
|
console.error("No document selected for printing."); |
|
|
|
console.error("No document selected for printing."); |
|
|
|
@ -128,6 +134,11 @@ function App() { |
|
|
|
const latestPrint = prints[prints.length - 1]; |
|
|
|
const latestPrint = prints[prints.length - 1]; |
|
|
|
console.log("Latest print job:", latestPrint); |
|
|
|
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); |
|
|
|
setPrinting(latestPrint.id); |
|
|
|
|
|
|
|
|
|
|
|
// save url to local disk |
|
|
|
// save url to local disk |
|
|
|
@ -143,11 +154,15 @@ function App() { |
|
|
|
console.log("Print job sent successfully for latest print."); |
|
|
|
console.log("Print job sent successfully for latest print."); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: clear print records |
|
|
|
// TODO: clear print records |
|
|
|
deletePrint(latestPrint.id); // Clear the print record after sending the job |
|
|
|
deletePrint(latestPrint.id).then(() => { |
|
|
|
console.log("Print record deleted:", latestPrint.id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Print record deleted:", latestPrint.id); |
|
|
|
setPrinting(); |
|
|
|
setPrinting(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}).catch((error) => { |
|
|
|
|
|
|
|
console.error("Error deleting print record:", error); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}).catch((error) => { |
|
|
|
}).catch((error) => { |
|
|
|
console.error("Error sending print job for latest print:", error); |
|
|
|
console.error("Error sending print job for latest print:", error); |
|
|
|
|
|
|
|
|
|
|
|
|