team-ljyzipelo

공개
99줄3.8 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::{self, FontData, FontDefinitions, FontFamily};
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 let font = system_font::load().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?;
47 renderer::run_native(
48 "Zipelo",
49 eframe::NativeOptions {
50 viewport: egui::ViewportBuilder::default()
51 .with_inner_size([1060.0, 720.0])
52 .with_min_inner_size([760.0, 540.0])
53 .with_decorations(!custom_frame),
54 ..Default::default()
55 },
56 || {
57 let bytes = font.bytes.clone();
58 let face_index = font.face_index;
59 Box::new(move |cc| {
60 let mut fonts = FontDefinitions::empty();
61 let mut data = FontData::from_owned(bytes);
62 data.index = face_index;
63 fonts.font_data.insert("noto-kr".into(), data.into());
64 fonts
65 .families
66 .insert(FontFamily::Proportional, vec!["noto-kr".into()]);
67 cc.egui_ctx.set_fonts(fonts);
68 zipelo_ui_memory_app::archive_theme::apply(&cc.egui_ctx);
69 let (fixture, startup) = zipelo_ui_memory_app::archive_ui::launch_args(
70 std::env::args_os().skip(1).collect(),
71 std::env::current_dir()?,
72 )
73 .map_err(std::io::Error::other)?;
74 let factory: Box<dyn zipelo_ui_memory_app::archive_ui::Factory> = if fixture {
75 #[cfg(feature = "ui-fixture")]
76 {
77 Box::new(fake::FakeFactory::default())
78 }
79 #[cfg(not(feature = "ui-fixture"))]
80 {
81 return Err(Box::new(std::io::Error::other(
82 "ui-fixture feature가 필요합니다",
83 )));
84 }
85 } else {
86 Box::new(
87 zipelo_ui_memory_app::archive_process::ProcessFactory::sibling()
88 .map_err(std::io::Error::other)?,
89 )
90 };
91 let mut app = zipelo_ui_memory_app::archive_screen::ArchiveApp::new(
92 factory, startup, fixture,
93 );
94 app.set_custom_frame(custom_frame);
95 Ok(Box::new(app))
96 })
97 },
98 )
99}