| 1 | #![cfg_attr(target_os = "windows", windows_subsystem = "windows")] |
| 2 | |
| 3 | #[cfg(feature = "ui-fixture")] |
| 4 | #[path = "../../../tests/rust-app-ui/fake.rs"] |
| 5 | mod fake; |
| 6 | #[path = "renderer.rs"] |
| 7 | mod renderer; |
| 8 | #[path = "system_font.rs"] |
| 9 | mod system_font; |
| 10 | use eframe::egui::{self, FontData, FontDefinitions, FontFamily}; |
| 11 | fn main() -> eframe::Result { |
| 12 | let result = run(); |
| 13 | #[cfg(target_os = "windows")] |
| 14 | if let Err(error) = &result { |
| 15 | let message = if matches!(error, eframe::Error::AppCreation(_)) { |
| 16 | "앱을 시작하지 못했습니다. 설치 파일을 다시 설치한 뒤 시도해 주세요." |
| 17 | } else { |
| 18 | "이 PC에서 화면을 표시할 수 없습니다. 그래픽 드라이버를 업데이트해 주세요." |
| 19 | }; |
| 20 | show_startup_error(message); |
| 21 | } |
| 22 | result |
| 23 | } |
| 24 | |
| 25 | #[cfg(target_os = "windows")] |
| 26 | fn show_startup_error(message: &str) { |
| 27 | #[link(name = "user32")] |
| 28 | unsafe extern "system" { |
| 29 | fn MessageBoxW( |
| 30 | window: *mut std::ffi::c_void, |
| 31 | text: *const u16, |
| 32 | caption: *const u16, |
| 33 | kind: u32, |
| 34 | ) -> i32; |
| 35 | } |
| 36 | let text: Vec<u16> = message.encode_utf16().chain(Some(0)).collect(); |
| 37 | let caption: Vec<u16> = "Zipelo".encode_utf16().chain(Some(0)).collect(); |
| 38 | // 종료까지 유효한 NUL 종료 문자열로 기본 오류 창을 표시함. |
| 39 | unsafe { |
| 40 | MessageBoxW(std::ptr::null_mut(), text.as_ptr(), caption.as_ptr(), 0x10); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | fn run() -> eframe::Result { |
| 45 | let font = system_font::load().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?; |
| 46 | renderer::run_native( |
| 47 | "Zipelo", |
| 48 | eframe::NativeOptions { |
| 49 | viewport: egui::ViewportBuilder::default() |
| 50 | .with_inner_size([1060.0, 720.0]) |
| 51 | .with_min_inner_size([760.0, 540.0]), |
| 52 | ..Default::default() |
| 53 | }, |
| 54 | || { |
| 55 | let bytes = font.bytes.clone(); |
| 56 | let face_index = font.face_index; |
| 57 | Box::new(move |cc| { |
| 58 | let mut fonts = FontDefinitions::empty(); |
| 59 | let mut data = FontData::from_owned(bytes); |
| 60 | data.index = face_index; |
| 61 | fonts.font_data.insert("noto-kr".into(), data.into()); |
| 62 | fonts |
| 63 | .families |
| 64 | .insert(FontFamily::Proportional, vec!["noto-kr".into()]); |
| 65 | cc.egui_ctx.set_fonts(fonts); |
| 66 | zipelo_ui_memory_app::archive_theme::apply(&cc.egui_ctx); |
| 67 | let (fixture, startup) = zipelo_ui_memory_app::archive_ui::launch_args( |
| 68 | std::env::args_os().skip(1).collect(), |
| 69 | std::env::current_dir()?, |
| 70 | ) |
| 71 | .map_err(std::io::Error::other)?; |
| 72 | let factory: Box<dyn zipelo_ui_memory_app::archive_ui::Factory> = if fixture { |
| 73 | #[cfg(feature = "ui-fixture")] |
| 74 | { |
| 75 | Box::new(fake::FakeFactory::default()) |
| 76 | } |
| 77 | #[cfg(not(feature = "ui-fixture"))] |
| 78 | { |
| 79 | return Err(Box::new(std::io::Error::other( |
| 80 | "ui-fixture feature가 필요합니다", |
| 81 | ))); |
| 82 | } |
| 83 | } else { |
| 84 | Box::new( |
| 85 | zipelo_ui_memory_app::archive_process::ProcessFactory::sibling() |
| 86 | .map_err(std::io::Error::other)?, |
| 87 | ) |
| 88 | }; |
| 89 | Ok(Box::new( |
| 90 | zipelo_ui_memory_app::archive_screen::ArchiveApp::new( |
| 91 | factory, startup, fixture, |
| 92 | ), |
| 93 | )) |
| 94 | }) |
| 95 | }, |
| 96 | ) |
| 97 | } |