| 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 | #[cfg(target_os = "linux")] |
| 17 | #[path = "drag_out_wayland.rs"] |
| 18 | mod drag_out_wayland; |
| 19 | #[cfg(target_os = "linux")] |
| 20 | #[path = "drag_out_x11.rs"] |
| 21 | mod drag_out_x11; |
| 22 | #[cfg(target_os = "windows")] |
| 23 | #[path = "drag_out_windows.rs"] |
| 24 | mod drag_out_windows; |
| 25 | use eframe::egui; |
| 26 | fn main() -> eframe::Result { |
| 27 | zipelo_ui_memory_app::log_info!( |
| 28 | "Zipelo {} 시작 (로그 단계 {:?}, ZIPELO_LOG로 변경 가능)", |
| 29 | env!("CARGO_PKG_VERSION"), |
| 30 | zipelo_ui_memory_app::applog::level() |
| 31 | ); |
| 32 | let result = run(); |
| 33 | match &result { |
| 34 | Ok(()) => zipelo_ui_memory_app::log_info!("Zipelo 정상 종료"), |
| 35 | Err(error) => zipelo_ui_memory_app::log_error!("Zipelo 시작 또는 실행 실패: {error}"), |
| 36 | } |
| 37 | #[cfg(all( |
| 38 | target_os = "windows", |
| 39 | not(all(feature = "ui-fixture", debug_assertions)) |
| 40 | ))] |
| 41 | if let Err(error) = &result { |
| 42 | let message = if matches!(error, eframe::Error::AppCreation(_)) { |
| 43 | "앱을 시작하지 못했습니다. 설치 파일을 다시 설치한 뒤 시도해 주세요." |
| 44 | } else { |
| 45 | "이 PC에서 화면을 표시할 수 없습니다. 그래픽 드라이버를 업데이트해 주세요." |
| 46 | }; |
| 47 | show_startup_error(message); |
| 48 | } |
| 49 | result |
| 50 | } |
| 51 | |
| 52 | #[cfg(all( |
| 53 | target_os = "windows", |
| 54 | not(all(feature = "ui-fixture", debug_assertions)) |
| 55 | ))] |
| 56 | fn show_startup_error(message: &str) { |
| 57 | #[link(name = "user32")] |
| 58 | unsafe extern "system" { |
| 59 | fn MessageBoxW( |
| 60 | window: *mut std::ffi::c_void, |
| 61 | text: *const u16, |
| 62 | caption: *const u16, |
| 63 | kind: u32, |
| 64 | ) -> i32; |
| 65 | } |
| 66 | let text: Vec<u16> = message.encode_utf16().chain(Some(0)).collect(); |
| 67 | let caption: Vec<u16> = "Zipelo".encode_utf16().chain(Some(0)).collect(); |
| 68 | // 종료까지 유효한 NUL 종료 문자열로 기본 오류 창을 표시함. |
| 69 | unsafe { |
| 70 | MessageBoxW(std::ptr::null_mut(), text.as_ptr(), caption.as_ptr(), 0x10); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | fn run() -> eframe::Result { |
| 75 | let args: Vec<_> = std::env::args_os().skip(1).collect(); |
| 76 | #[cfg(all(feature = "ui-fixture", debug_assertions))] |
| 77 | let (args, scenario) = { |
| 78 | use zipelo_ui_memory_app::archive_screen::scenarios::{self, Launch}; |
| 79 | match scenarios::launch(args) |
| 80 | .map_err(|e| eframe::Error::AppCreation(Box::new(std::io::Error::other(e))))? |
| 81 | { |
| 82 | Launch::List => { |
| 83 | print!("{}", scenarios::listing()); |
| 84 | return Ok(()); |
| 85 | } |
| 86 | Launch::Scenario(scenario) => (Vec::new(), Some(scenario)), |
| 87 | Launch::Normal(args) => (args, None), |
| 88 | } |
| 89 | }; |
| 90 | #[cfg(not(all(feature = "ui-fixture", debug_assertions)))] |
| 91 | if args |
| 92 | .iter() |
| 93 | .any(|arg| arg == "--ui-scenario" || arg == "--list-ui-scenarios") |
| 94 | { |
| 95 | return Err(eframe::Error::AppCreation(Box::new(std::io::Error::other( |
| 96 | "지원하지 않는 명령줄 옵션입니다", |
| 97 | )))); |
| 98 | } |
| 99 | let (fixture, startup) = zipelo_ui_memory_app::archive_ui::launch_args( |
| 100 | args, |
| 101 | std::env::current_dir().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?, |
| 102 | ) |
| 103 | .map_err(|e| eframe::Error::AppCreation(Box::new(std::io::Error::other(e))))?; |
| 104 | let custom_frame = zipelo_ui_memory_app::window_frame::custom_frame_needed(); |
| 105 | zipelo_ui_memory_app::log_debug!( |
| 106 | "실행 인자 해석: 시험 모드={fixture}, 시작 파일={:?}, 직접 그린 창 테두리={custom_frame}", |
| 107 | startup |
| 108 | ); |
| 109 | // 운영체제 한글 글꼴은 Pretendard에 없는 글자를 위한 대체 글꼴로만 씀. |
| 110 | let fallback = system_font::load() |
| 111 | .ok() |
| 112 | .map(|font| (font.bytes, font.face_index)); |
| 113 | renderer::run_native( |
| 114 | "Zipelo", |
| 115 | eframe::NativeOptions { |
| 116 | viewport: egui::ViewportBuilder::default() |
| 117 | .with_inner_size([1060.0, 720.0]) |
| 118 | .with_min_inner_size([760.0, 540.0]) |
| 119 | .with_decorations(!custom_frame), |
| 120 | ..Default::default() |
| 121 | }, |
| 122 | || { |
| 123 | let fallback = fallback.clone(); |
| 124 | let startup = startup.clone(); |
| 125 | Box::new(move |cc| { |
| 126 | cc.egui_ctx |
| 127 | .set_fonts(zipelo_ui_memory_app::archive_theme::fonts(fallback)); |
| 128 | zipelo_ui_memory_app::archive_theme::apply(&cc.egui_ctx); |
| 129 | #[cfg(all(feature = "ui-fixture", debug_assertions))] |
| 130 | if let Some(scenario) = scenario { |
| 131 | let app = scenario.build_with_frame(custom_frame); |
| 132 | return Ok(Box::new( |
| 133 | zipelo_ui_memory_app::archive_screen::scenarios::Preview::new( |
| 134 | app, |
| 135 | &cc.egui_ctx, |
| 136 | ) |
| 137 | .with_scenario(scenario), |
| 138 | ) as Box<dyn eframe::App>); |
| 139 | } |
| 140 | let factory: Box<dyn zipelo_ui_memory_app::archive_ui::Factory> = if fixture { |
| 141 | #[cfg(feature = "ui-fixture")] |
| 142 | { |
| 143 | Box::new(fake::FakeFactory::default()) |
| 144 | } |
| 145 | #[cfg(not(feature = "ui-fixture"))] |
| 146 | { |
| 147 | return Err(Box::new(std::io::Error::other( |
| 148 | "ui-fixture feature가 필요합니다", |
| 149 | ))); |
| 150 | } |
| 151 | } else { |
| 152 | Box::new( |
| 153 | zipelo_ui_memory_app::archive_process::ProcessFactory::sibling() |
| 154 | .map_err(std::io::Error::other)?, |
| 155 | ) |
| 156 | }; |
| 157 | let mut app = zipelo_ui_memory_app::archive_screen::ArchiveApp::new( |
| 158 | factory, |
| 159 | startup.clone(), |
| 160 | fixture, |
| 161 | ); |
| 162 | app.set_custom_frame(custom_frame); |
| 163 | // 목록 항목을 창 밖으로 끌어 놓아 풀 수 있게 함. |
| 164 | #[cfg(target_os = "linux")] |
| 165 | if !fixture { |
| 166 | if let Some(drag) = drag_out_wayland::create(cc, cc.egui_ctx.clone()) { |
| 167 | app.set_drag_out(Box::new(drag)); |
| 168 | } else if let Some(drag) = drag_out_x11::create(cc, cc.egui_ctx.clone()) { |
| 169 | app.set_drag_out(Box::new(drag)); |
| 170 | } |
| 171 | } |
| 172 | #[cfg(target_os = "windows")] |
| 173 | if !fixture && let Some(drag) = drag_out_windows::create(cc, cc.egui_ctx.clone()) { |
| 174 | app.set_drag_out(Box::new(drag)); |
| 175 | } |
| 176 | app.set_work_window_in_parent(custom_frame); |
| 177 | Ok(Box::new(app)) |
| 178 | }) |
| 179 | }, |
| 180 | ) |
| 181 | } |