BlueGit

timfa posprint

Files

posprint / src / main.rs

main.rs

main.rs 2.0 KiB Download Raw
1#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
2
3mod app;
4mod print_dialog;
5mod print_only_app;
6mod shell_integration;
7
8use std::sync::Arc;
9
10use clap::Parser;
11
12fn load_viewport_icon() -> Option<Arc<eframe::egui::IconData>> {
13 eframe::icon_data::from_png_bytes(include_bytes!("../pos-logo.png"))
14 .ok()
15 .map(Arc::new)
16}
17
18fn main() -> eframe::Result<()> {
19 shell_integration::ensure_print_context_menu();
20
21 let cli = posprint::cli::Cli::parse();
22 if cli.command.is_some() {
23 std::process::exit(posprint::cli::run(cli));
24 }
25
26 if cli.print {
27 let Some(path) = cli.file else {
28 eprintln!("--print requires a .pos file path");
29 std::process::exit(1);
30 };
31 return run_print_only(path);
32 }
33
34 let open_file = cli.file;
35
36 let mut viewport = eframe::egui::ViewportBuilder::default().with_inner_size([1200.0, 750.0]);
37 if let Some(icon) = load_viewport_icon() {
38 viewport = viewport.with_icon(icon);
39 }
40
41 let options = eframe::NativeOptions {
42 viewport,
43 ..Default::default()
44 };
45 eframe::run_native(
46 "posprint",
47 options,
48 Box::new(move |_cc| {
49 Ok(Box::new(app::PosPrintApp::new_with_file(open_file)) as Box<dyn eframe::App>)
50 }),
51 )
52}
53
54fn run_print_only(path: std::path::PathBuf) -> eframe::Result<()> {
55 let mut viewport = eframe::egui::ViewportBuilder::default()
56 .with_inner_size([440.0, 420.0])
57 .with_min_inner_size([380.0, 320.0]);
58 if let Some(icon) = load_viewport_icon() {
59 viewport = viewport.with_icon(icon);
60 }
61
62 let options = eframe::NativeOptions {
63 viewport,
64 ..Default::default()
65 };
66 eframe::run_native(
67 "posprint",
68 options,
69 Box::new(move |_cc| {
70 Ok(Box::new(print_only_app::PrintOnlyApp::new(path)) as Box<dyn eframe::App>)
71 }),
72 )
73}