| 1 | #![cfg_attr( |
| 2 | all( |
| 3 | target_os = "windows", |
| 4 | not(all(feature = "ui-fixture", debug_assertions)) |
| 5 | ), |
| 6 | windows_subsystem = "windows" |
| 7 | )] |
| 8 | |
| 9 | #[cfg(feature = "ui-fixture")] |
| 10 | #[path = "../../../tests/rust-app-ui/fake.rs"] |
| 11 | mod fake; |
| 12 | #[path = "renderer.rs"] |
| 13 | mod renderer; |
| 14 | #[path = "system_font.rs"] |
| 15 | mod system_font; |
| 16 | use eframe::egui; |
| 17 | fn main() -> eframe::Result { |
| 18 | let result = run(); |
| 19 | #[cfg(all( |
| 20 | target_os = "windows", |
| 21 | not(all(feature = "ui-fixture", debug_assertions)) |
| 22 | ))] |
| 23 | if let Err(error) = &result { |
| 24 | let message = if matches!(error, eframe::Error::AppCreation(_)) { |
| 25 | "앱을 시작하지 못했습니다. 설치 파일을 다시 설치한 뒤 시도해 주세요." |
| 26 | } else { |
| 27 | "이 PC에서 화면을 표시할 수 없습니다. 그래픽 드라이버를 업데이트해 주세요." |
| 28 | }; |
| 29 | show_startup_error(message); |
| 30 | } |
| 31 | result |
| 32 | } |
| 33 | |
| 34 | #[cfg(all( |
| 35 | target_os = "windows", |
| 36 | not(all(feature = "ui-fixture", debug_assertions)) |
| 37 | ))] |
| 38 | fn show_startup_error(message: &str) { |
| 39 | #[link(name = "user32")] |
| 40 | unsafe extern "system" { |
| 41 | fn MessageBoxW( |
| 42 | window: *mut std::ffi::c_void, |
| 43 | text: *const u16, |
| 44 | caption: *const u16, |
| 45 | kind: u32, |
| 46 | ) -> i32; |
| 47 | } |
| 48 | let text: Vec<u16> = message.encode_utf16().chain(Some(0)).collect(); |
| 49 | let caption: Vec<u16> = "Zipelo".encode_utf16().chain(Some(0)).collect(); |
| 50 | // 종료까지 유효한 NUL 종료 문자열로 기본 오류 창을 표시함. |
| 51 | unsafe { |
| 52 | MessageBoxW(std::ptr::null_mut(), text.as_ptr(), caption.as_ptr(), 0x10); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | fn run() -> eframe::Result { |
| 57 | let args: Vec<_> = std::env::args_os().skip(1).collect(); |
| 58 | #[cfg(all(feature = "ui-fixture", debug_assertions))] |
| 59 | let (args, scenario) = { |
| 60 | use zipelo_ui_memory_app::archive_screen::scenarios::{self, Launch}; |
| 61 | match scenarios::launch(args) |
| 62 | .map_err(|e| eframe::Error::AppCreation(Box::new(std::io::Error::other(e))))? |
| 63 | { |
| 64 | Launch::List => { |
| 65 | print!("{}", scenarios::listing()); |
| 66 | return Ok(()); |
| 67 | } |
| 68 | Launch::Scenario(scenario) => (Vec::new(), Some(scenario)), |
| 69 | Launch::Normal(args) => (args, None), |
| 70 | } |
| 71 | }; |
| 72 | #[cfg(not(all(feature = "ui-fixture", debug_assertions)))] |
| 73 | if args |
| 74 | .iter() |
| 75 | .any(|arg| arg == "--ui-scenario" || arg == "--list-ui-scenarios") |
| 76 | { |
| 77 | return Err(eframe::Error::AppCreation(Box::new(std::io::Error::other( |
| 78 | "지원하지 않는 명령줄 옵션입니다", |
| 79 | )))); |
| 80 | } |
| 81 | let (fixture, startup) = zipelo_ui_memory_app::archive_ui::launch_args( |
| 82 | args, |
| 83 | std::env::current_dir().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?, |
| 84 | ) |
| 85 | .map_err(|e| eframe::Error::AppCreation(Box::new(std::io::Error::other(e))))?; |
| 86 | let custom_frame = zipelo_ui_memory_app::window_frame::custom_frame_needed(); |
| 87 | // 운영체제 한글 글꼴은 Pretendard에 없는 글자를 위한 대체 글꼴로만 씀. |
| 88 | let fallback = system_font::load() |
| 89 | .ok() |
| 90 | .map(|font| (font.bytes, font.face_index)); |
| 91 | renderer::run_native( |
| 92 | "Zipelo", |
| 93 | eframe::NativeOptions { |
| 94 | viewport: egui::ViewportBuilder::default() |
| 95 | .with_inner_size([1060.0, 720.0]) |
| 96 | .with_min_inner_size([760.0, 540.0]) |
| 97 | .with_decorations(!custom_frame), |
| 98 | ..Default::default() |
| 99 | }, |
| 100 | || { |
| 101 | let fallback = fallback.clone(); |
| 102 | let startup = startup.clone(); |
| 103 | Box::new(move |cc| { |
| 104 | cc.egui_ctx |
| 105 | .set_fonts(zipelo_ui_memory_app::archive_theme::fonts(fallback)); |
| 106 | zipelo_ui_memory_app::archive_theme::apply(&cc.egui_ctx); |
| 107 | #[cfg(all(feature = "ui-fixture", debug_assertions))] |
| 108 | if let Some(scenario) = scenario { |
| 109 | let mut app = scenario.build(); |
| 110 | app.set_custom_frame(custom_frame); |
| 111 | return Ok(Box::new( |
| 112 | zipelo_ui_memory_app::archive_screen::scenarios::Preview::new( |
| 113 | app, |
| 114 | &cc.egui_ctx, |
| 115 | ) |
| 116 | .with_scenario(scenario), |
| 117 | ) as Box<dyn eframe::App>); |
| 118 | } |
| 119 | let factory: Box<dyn zipelo_ui_memory_app::archive_ui::Factory> = if fixture { |
| 120 | #[cfg(feature = "ui-fixture")] |
| 121 | { |
| 122 | Box::new(fake::FakeFactory::default()) |
| 123 | } |
| 124 | #[cfg(not(feature = "ui-fixture"))] |
| 125 | { |
| 126 | return Err(Box::new(std::io::Error::other( |
| 127 | "ui-fixture feature가 필요합니다", |
| 128 | ))); |
| 129 | } |
| 130 | } else { |
| 131 | Box::new( |
| 132 | zipelo_ui_memory_app::archive_process::ProcessFactory::sibling() |
| 133 | .map_err(std::io::Error::other)?, |
| 134 | ) |
| 135 | }; |
| 136 | let mut app = zipelo_ui_memory_app::archive_screen::ArchiveApp::new( |
| 137 | factory, |
| 138 | startup.clone(), |
| 139 | fixture, |
| 140 | ); |
| 141 | app.set_custom_frame(custom_frame); |
| 142 | Ok(Box::new(app)) |
| 143 | }) |
| 144 | }, |
| 145 | ) |
| 146 | } |