team-ljyzipelo

공개
113줄4.6 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, Color32, FontData, FontDefinitions, FontFamily, FontId, TextStyle};
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 font = system_font::load().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?;
46 renderer::run_native(
47 "Zipelo",
48 eframe::NativeOptions {
49 viewport: egui::ViewportBuilder::default()
50 .with_inner_size([1060.0, 720.0])
51 .with_min_inner_size([760.0, 540.0]),
52 ..Default::default()
53 },
54 || {
55 let bytes = font.bytes.clone();
56 let face_index = font.face_index;
57 Box::new(move |cc| {
58 let mut fonts = FontDefinitions::empty();
59 let mut data = FontData::from_owned(bytes);
60 data.index = face_index;
61 fonts.font_data.insert("noto-kr".into(), data.into());
62 fonts
63 .families
64 .insert(FontFamily::Proportional, vec!["noto-kr".into()]);
65 cc.egui_ctx.set_fonts(fonts);
66 cc.egui_ctx.set_visuals(egui::Visuals::light());
67 cc.egui_ctx.style_mut_of(egui::Theme::Light, |style| {
68 style
69 .text_styles
70 .insert(TextStyle::Body, FontId::proportional(18.0));
71 style
72 .text_styles
73 .insert(TextStyle::Button, FontId::proportional(18.0));
74 style
75 .text_styles
76 .insert(TextStyle::Heading, FontId::proportional(26.0));
77 style.visuals.panel_fill = Color32::WHITE;
78 style.visuals.override_text_color = Some(Color32::from_rgb(24, 39, 57));
79 style.visuals.selection.bg_fill = Color32::from_rgb(211, 230, 246);
80 style.spacing.item_spacing = egui::vec2(12.0, 10.0);
81 style.spacing.button_padding = egui::vec2(14.0, 10.0);
82 });
83 let (fixture, startup) = zipelo_ui_memory_app::archive_ui::launch_args(
84 std::env::args_os().skip(1).collect(),
85 std::env::current_dir()?,
86 )
87 .map_err(std::io::Error::other)?;
88 let factory: Box<dyn zipelo_ui_memory_app::archive_ui::Factory> = if fixture {
89 #[cfg(feature = "ui-fixture")]
90 {
91 Box::new(fake::FakeFactory::default())
92 }
93 #[cfg(not(feature = "ui-fixture"))]
94 {
95 return Err(Box::new(std::io::Error::other(
96 "ui-fixture feature가 필요합니다",
97 )));
98 }
99 } else {
100 Box::new(
101 zipelo_ui_memory_app::archive_process::ProcessFactory::sibling()
102 .map_err(std::io::Error::other)?,
103 )
104 };
105 Ok(Box::new(
106 zipelo_ui_memory_app::archive_screen::ArchiveApp::new(
107 factory, startup, fixture,
108 ),
109 ))
110 })
111 },
112 )
113}