|
|
|
@ -4,7 +4,7 @@ import "./App.css"; |
|
|
|
import { useEffect, useState } from "react"; |
|
|
|
import { useEffect, 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 } from "./utils/fs"; |
|
|
|
import { saveToDisk, loadSettings, saveSettings } from "./utils/fs"; |
|
|
|
|
|
|
|
|
|
|
|
const OptionTypes=[ |
|
|
|
const OptionTypes=[ |
|
|
|
'dpi_options', |
|
|
|
'dpi_options', |
|
|
|
@ -159,6 +159,25 @@ function App() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onSave() { |
|
|
|
|
|
|
|
const settings = { |
|
|
|
|
|
|
|
printer: printer, |
|
|
|
|
|
|
|
play_on_start: document.getElementById("play_on_start").checked, |
|
|
|
|
|
|
|
options: {} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
if(ENABLE_OPTIONS) { |
|
|
|
|
|
|
|
for(const optionType of OptionTypes) { |
|
|
|
|
|
|
|
const selectElement = document.getElementById(optionType); |
|
|
|
|
|
|
|
if(selectElement) { |
|
|
|
|
|
|
|
settings.options[optionType] = selectElement.value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
console.log("Saving settings:", settings); |
|
|
|
|
|
|
|
saveSettings(settings); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=>{ |
|
|
|
useEffect(()=>{ |
|
|
|
|
|
|
|
|
|
|
|
if(!printer) return; |
|
|
|
if(!printer) return; |
|
|
|
@ -203,6 +222,25 @@ function App() { |
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
|
|
|
|
getPrinters(); |
|
|
|
getPrinters(); |
|
|
|
|
|
|
|
loadSettings().then((settings) => { |
|
|
|
|
|
|
|
console.log("Loaded settings:", settings); |
|
|
|
|
|
|
|
document.getElementById("play_on_start").checked = settings.play_on_start || false; |
|
|
|
|
|
|
|
if(settings.play_on_start){ |
|
|
|
|
|
|
|
setPlaying(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(settings.printer && settings.printer !== "" ) { |
|
|
|
|
|
|
|
setPrinter(settings.printer); |
|
|
|
|
|
|
|
if (settings.options) { |
|
|
|
|
|
|
|
for (const optionType of OptionTypes) { |
|
|
|
|
|
|
|
const selectElement = document.getElementById(optionType); |
|
|
|
|
|
|
|
if (selectElement && settings.options[optionType]) { |
|
|
|
|
|
|
|
selectElement.value = settings.options[optionType]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
listenToPrints((newPrints) => { |
|
|
|
listenToPrints((newPrints) => { |
|
|
|
console.log("Received prints:", newPrints); |
|
|
|
console.log("Received prints:", newPrints); |
|
|
|
@ -214,7 +252,8 @@ function App() { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<main className="grid grid-cols-2 gap-2 p-2"> |
|
|
|
<main className="grid grid-cols-2 gap-2 p-2"> |
|
|
|
<div className="grid grid-rows-2 gap-2"> |
|
|
|
<div className="grid grid-rows-2 gap-2"> |
|
|
|
<section className="*:w-full"> |
|
|
|
<section> |
|
|
|
|
|
|
|
<h1>config</h1> |
|
|
|
<button className="!w-auto self-start !bg-amber-200" onClick={getPrinters}>refresh printers</button> |
|
|
|
<button className="!w-auto self-start !bg-amber-200" onClick={getPrinters}>refresh printers</button> |
|
|
|
<select id="printer-select" value={printer} onChange={(e) => setPrinter(e.target.value)}></select> |
|
|
|
<select id="printer-select" value={printer} onChange={(e) => setPrinter(e.target.value)}></select> |
|
|
|
{ENABLE_OPTIONS && <> |
|
|
|
{ENABLE_OPTIONS && <> |
|
|
|
@ -223,8 +262,17 @@ function App() { |
|
|
|
<select id="color_options"></select> |
|
|
|
<select id="color_options"></select> |
|
|
|
<select id="quality_options"></select> |
|
|
|
<select id="quality_options"></select> |
|
|
|
</>} |
|
|
|
</>} |
|
|
|
|
|
|
|
<div className="grid grid-cols-2 gap-2"> |
|
|
|
|
|
|
|
<span className="flex items-center gap-1"> |
|
|
|
|
|
|
|
<input type="checkbox" id="play_on_start"/> |
|
|
|
|
|
|
|
<label htmlFor="play_on_start">play on start</label> |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
<button onClick={onSave} className="!bg-amber-200">save</button> |
|
|
|
|
|
|
|
{/* <button onClick={loadSettings} className="!bg-amber-200">load</button> */} |
|
|
|
|
|
|
|
</div> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
<section className="*:w-full"> |
|
|
|
<section> |
|
|
|
|
|
|
|
<h1>test print</h1> |
|
|
|
<div className="flex flex-row gap-2 items-center"> |
|
|
|
<div className="flex flex-row gap-2 items-center"> |
|
|
|
<label id="document_path_label" className="flex-1 break-all">{selectedFile ? `${selectedFile}` : "Select a document to print:"}</label> |
|
|
|
<label id="document_path_label" className="flex-1 break-all">{selectedFile ? `${selectedFile}` : "Select a document to print:"}</label> |
|
|
|
<button onClick={openFile}>open</button> |
|
|
|
<button onClick={openFile}>open</button> |
|
|
|
@ -237,7 +285,8 @@ function App() { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<section className="*:w-full"> |
|
|
|
<section> |
|
|
|
|
|
|
|
<h1>status</h1> |
|
|
|
<div className="border flex-1 p-2 overflow-y-auto overflow-x-hidden text-sm break-all flex flex-col gap-1"> |
|
|
|
<div className="border flex-1 p-2 overflow-y-auto overflow-x-hidden text-sm break-all flex flex-col gap-1"> |
|
|
|
{prints.length > 0 ? ( |
|
|
|
{prints.length > 0 ? ( |
|
|
|
prints.map((print) => ( |
|
|
|
prints.map((print) => ( |
|
|
|
|