team-ljyzipelo

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