v1.2.0 — campos texto livre vs datalist; diferença abaixo saldo esperado + badge OK/sobra; btn-anterior com datas do Supabase; ESC/POS copy fallback; modal com PIX+diferença+print; debug Supabase
This commit is contained in:
@@ -227,21 +227,45 @@ impl PrinterManager {
|
||||
|
||||
#[cfg(windows)]
|
||||
fn windows_write(&self, path: &str, data: &[u8]) -> Result<usize, String> {
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
|
||||
let file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(false)
|
||||
.open(path)
|
||||
.map_err(|e| format!("Erro ao abrir {}: {}", path, e))?;
|
||||
// Tenta via File primeiro (mais simples)
|
||||
{
|
||||
let file = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(false)
|
||||
.open(path);
|
||||
if let Ok(mut f) = file {
|
||||
let r = f.write_all(data);
|
||||
let _ = f.flush();
|
||||
if r.is_ok() {
|
||||
return Ok(data.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut f = file;
|
||||
f.write_all(data)
|
||||
.map_err(|e| format!("Erro ao escrever: {}", e))?;
|
||||
f.flush()
|
||||
.map_err(|e| format!("Erro ao fazer flush: {}", e))?;
|
||||
Ok(data.len())
|
||||
// Fallback: usa API Windows direta via std::process::Command + > arquivo
|
||||
// Isso绕过 problemas de locking do OpenOptions
|
||||
let tmp = std::env::temp_dir().join("escpos_tmp.bin");
|
||||
std::fs::write(&tmp, data)
|
||||
.map_err(|e| format!("Falha ao criar arquivo temporario: {}", e))?;
|
||||
|
||||
let status = std::process::Command::new("cmd")
|
||||
.args(["/C", &format!("copy /B {} {} /Y > nul 2>&1", tmp.display(), path)])
|
||||
.status();
|
||||
|
||||
let _ = std::fs::remove_file(&tmp);
|
||||
|
||||
if status.map(|s| s.success()).unwrap_or(false) {
|
||||
log::info!("Escritos {} bytes para {}", data.len(), path);
|
||||
Ok(data.len())
|
||||
} else {
|
||||
Err(format!(
|
||||
"Falha ao enviar dados para {}. Verifique se a impressora USB está \
|
||||
conectada e ligada. Tente configurar manualmente em Config > Impressora.",
|
||||
path
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user