team-ljyzipelo

공개
95줄3.5 KB
1#![cfg_attr(target_os = "windows", windows_subsystem = "windows")]
2
3#[cfg(feature = "ui-fixture")]
4#[path = "../../../tests/rust-app-ui/fake.rs"]
5mod fake;
6#[path = "renderer.rs"]
7mod renderer;
8#[path = "system_font.rs"]
9mod system_font;
10use eframe::egui;
11fn 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")]
26fn 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
44fn run() -> eframe::Result {
45 let custom_frame = zipelo_ui_memory_app::window_frame::custom_frame_needed();
46 // 운영체제 한글 글꼴은 Pretendard에 없는 글자를 위한 대체 글꼴로만 씀.
47 let fallback = system_font::load()
48 .ok()
49 .map(|font| (font.bytes, font.face_index));
50 renderer::run_native(
51 "Zipelo",
52 eframe::NativeOptions {
53 viewport: egui::ViewportBuilder::default()
54 .with_inner_size([1060.0, 720.0])
55 .with_min_inner_size([760.0, 540.0])
56 .with_decorations(!custom_frame),
57 ..Default::default()
58 },
59 || {
60 let fallback = fallback.clone();
61 Box::new(move |cc| {
62 cc.egui_ctx
63 .set_fonts(zipelo_ui_memory_app::archive_theme::fonts(fallback));
64 zipelo_ui_memory_app::archive_theme::apply(&cc.egui_ctx);
65 let (fixture, startup) = zipelo_ui_memory_app::archive_ui::launch_args(
66 std::env::args_os().skip(1).collect(),
67 std::env::current_dir()?,
68 )
69 .map_err(std::io::Error::other)?;
70 let factory: Box<dyn zipelo_ui_memory_app::archive_ui::Factory> = if fixture {
71 #[cfg(feature = "ui-fixture")]
72 {
73 Box::new(fake::FakeFactory::default())
74 }
75 #[cfg(not(feature = "ui-fixture"))]
76 {
77 return Err(Box::new(std::io::Error::other(
78 "ui-fixture feature가 필요합니다",
79 )));
80 }
81 } else {
82 Box::new(
83 zipelo_ui_memory_app::archive_process::ProcessFactory::sibling()
84 .map_err(std::io::Error::other)?,
85 )
86 };
87 let mut app = zipelo_ui_memory_app::archive_screen::ArchiveApp::new(
88 factory, startup, fixture,
89 );
90 app.set_custom_frame(custom_frame);
91 Ok(Box::new(app))
92 })
93 },
94 )
95}