team-ljyzipelo

공개
146줄5.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;
16use eframe::egui;
17fn 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))]
38fn 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
56fn 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 app = scenario.build_with_frame(custom_frame);
110 return Ok(Box::new(
111 zipelo_ui_memory_app::archive_screen::scenarios::Preview::new(
112 app,
113 &cc.egui_ctx,
114 )
115 .with_scenario(scenario),
116 ) as Box<dyn eframe::App>);
117 }
118 let factory: Box<dyn zipelo_ui_memory_app::archive_ui::Factory> = if fixture {
119 #[cfg(feature = "ui-fixture")]
120 {
121 Box::new(fake::FakeFactory::default())
122 }
123 #[cfg(not(feature = "ui-fixture"))]
124 {
125 return Err(Box::new(std::io::Error::other(
126 "ui-fixture feature가 필요합니다",
127 )));
128 }
129 } else {
130 Box::new(
131 zipelo_ui_memory_app::archive_process::ProcessFactory::sibling()
132 .map_err(std::io::Error::other)?,
133 )
134 };
135 let mut app = zipelo_ui_memory_app::archive_screen::ArchiveApp::new(
136 factory,
137 startup.clone(),
138 fixture,
139 );
140 app.set_custom_frame(custom_frame);
141 app.set_work_window_in_parent(custom_frame);
142 Ok(Box::new(app))
143 })
144 },
145 )
146}