refactor(print): consolidate duplicate print commands and improve manifest JSON parsing #79
@@ -490,69 +490,6 @@ pub async fn run_profcheck(
|
||||
state.spawn(app, id, binary, args, cwd).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_windows_printers() -> Result<Vec<String>, String> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
crate::print::windows::get_printers().map(|list| list.into_iter().map(|p| p.name).collect())
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
Err("Windows native printing is only supported on Windows.".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn print_target_windows(
|
||||
state: State<'_, crate::print::PrinterDevModeStore>,
|
||||
printer_name: String,
|
||||
tiff_path: String,
|
||||
options: Option<crate::print::PrintOptions>,
|
||||
) -> Result<(), String> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
crate::print::windows::print_target(&printer_name, &tiff_path, options.as_ref(), Some(&state))
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let _ = (state, printer_name, tiff_path, options);
|
||||
Err("Windows native printing is only supported on Windows.".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_cups_printers() -> Result<Vec<crate::print::Printer>, String> {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
crate::print::unix::get_printers()
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
Err("CUPS printing is only supported on macOS and Linux.".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn print_target_cups(
|
||||
printer_name: String,
|
||||
tiff_path: String,
|
||||
options: Option<crate::print::PrintOptions>,
|
||||
) -> Result<(), String> {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
crate::print::unix::print_target(
|
||||
&printer_name,
|
||||
&tiff_path,
|
||||
options.as_ref(),
|
||||
)
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
let _ = (printer_name, tiff_path, options);
|
||||
Err("CUPS printing is only supported on macOS and Linux.".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_printers() -> Result<Vec<crate::print::Printer>, String> {
|
||||
#[cfg(windows)]
|
||||
|
||||
@@ -28,10 +28,6 @@ pub fn run() {
|
||||
commands::run_chartread,
|
||||
commands::run_colprof,
|
||||
commands::run_profcheck,
|
||||
commands::get_windows_printers,
|
||||
commands::print_target_windows,
|
||||
commands::get_cups_printers,
|
||||
commands::print_target_cups,
|
||||
commands::get_printers,
|
||||
commands::get_printer_capabilities,
|
||||
commands::show_printer_properties,
|
||||
|
||||
+6
-7
@@ -477,14 +477,13 @@ export function initPrinttarg() {
|
||||
*/
|
||||
function extractManifest(stdout) {
|
||||
try {
|
||||
const jsonStart = stdout.lastIndexOf('{\n "event": "manifest"');
|
||||
if (jsonStart === -1) return null;
|
||||
const jsonEnd = stdout.indexOf('\n}', jsonStart);
|
||||
if (jsonEnd === -1) return null;
|
||||
const jsonStr = stdout.substring(jsonStart, jsonEnd + 2);
|
||||
return JSON.parse(jsonStr);
|
||||
const match = stdout.match(/\{[\s\S]*?"event"\s*:\s*"manifest"[\s\S]*?\n\}/);
|
||||
if (match) {
|
||||
return JSON.parse(match[0]);
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
console.error("Failed to parse printtarg manifest:", e);
|
||||
console.error("Failed to parse printtarg manifest JSON:", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user