| Name | Message | Date |
|---|---|---|
| 📄 main.rs | 1 month ago | |
| 📄 proto.rs | - | |
| 📄 receipt_printer_service.rs | 1 month ago | |
| 📄 receipt_printer.rs | 1 month ago | |
| 📄 typst_renderer.rs | 1 month ago |
📄
src/receipt_printer_service.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use tonic::{Request, Response, Status}; use crate::proto::print_request::Content; use crate::proto::receipt_printer_server; use crate::proto::{PrintRequest, PrintResponse, TypstContent}; use crate::receipt_printer::ReceiptPrinter; use crate::typst_renderer::render_typst_receipt; pub struct ReceiptPrinterService { template_path: String, receipt_printer: ReceiptPrinter, } impl ReceiptPrinterService { pub fn new(template_path: String, receipt_printer: ReceiptPrinter) -> Self { Self { template_path, receipt_printer, } } } #[tonic::async_trait] impl receipt_printer_server::ReceiptPrinter for ReceiptPrinterService { async fn print( &self, request: Request<PrintRequest>, ) -> Result<Response<PrintResponse>, Status> { let Some(Content::Typst(TypstContent { content: Some(content), })) = &request.get_ref().content else { println!("No Typst content received"); return Ok(Response::new(PrintResponse::default())); }; let image = match render_typst_receipt(self.template_path.as_ref(), content) { Ok(image) => image, Err(error) => { println!("Error rendering receipt: {error}"); return Ok(Response::new(PrintResponse::default())); } }; println!("Connecting to printer..."); if let Err(error) = self.receipt_printer.print_image(image.into()).await { println!("Error when printing: {error}"); return Ok(Response::new(PrintResponse::default())); } println!("Done!"); Ok(Response::new(PrintResponse::default())) } }