| 1 | #[path = "system_font.rs"] |
| 2 | mod system_font; |
| 3 | |
| 4 | use eframe::egui::{self, Color32, FontData, FontDefinitions, FontFamily, FontId, TextStyle}; |
| 5 | use zipelo_ui_memory_app::{ |
| 6 | controller::{CloseState, Controller}, |
| 7 | runtime::Action, |
| 8 | }; |
| 9 | |
| 10 | #[derive(Default)] |
| 11 | struct App { |
| 12 | controller: Controller, |
| 13 | } |
| 14 | |
| 15 | impl eframe::App for App { |
| 16 | fn ui(&mut self, root: &mut egui::Ui, _frame: &mut eframe::Frame) { |
| 17 | self.controller.poll(); |
| 18 | let ctx = root.ctx().clone(); |
| 19 | if ctx.input(|i| i.viewport().close_requested()) { |
| 20 | self.controller.request_close(); |
| 21 | if self.controller.close != CloseState::Allowed { |
| 22 | ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose); |
| 23 | } |
| 24 | } |
| 25 | if self.controller.close == CloseState::Allowed { |
| 26 | ctx.send_viewport_cmd(egui::ViewportCommand::Close); |
| 27 | } |
| 28 | egui::Panel::top("actions").show(root, |ui| { |
| 29 | ui.heading("Zipelo 메모리 작업실"); |
| 30 | ui.label("합성 입력 전용 / 파일 저장 미지원"); |
| 31 | ui.horizontal_wrapped(|ui| { |
| 32 | for (label, action) in [ |
| 33 | ("ZIP 생성", Action::Zip), |
| 34 | ("USTAR 목록과 내용", Action::Ustar), |
| 35 | ("GZip 검증과 내용", Action::Gzip), |
| 36 | ("합성 오류 확인", Action::InvalidGzip), |
| 37 | ] { |
| 38 | if ui |
| 39 | .add_enabled( |
| 40 | !self.controller.busy() && self.controller.close == CloseState::Open, |
| 41 | egui::Button::new(label), |
| 42 | ) |
| 43 | .clicked() |
| 44 | { |
| 45 | self.controller.start(action); |
| 46 | } |
| 47 | } |
| 48 | if ui |
| 49 | .add_enabled(self.controller.busy(), egui::Button::new("취소 요청")) |
| 50 | .clicked() |
| 51 | { |
| 52 | self.controller.cancel(); |
| 53 | } |
| 54 | if ui.button("닫기").clicked() { |
| 55 | self.controller.request_close(); |
| 56 | } |
| 57 | }); |
| 58 | }); |
| 59 | egui::Panel::bottom("status").show(root, |ui| { |
| 60 | ui.label(self.controller.status_text()); |
| 61 | if let Some(progress) = self.controller.progress { |
| 62 | ui.label(format!("{:?}: {}", progress.metric, progress.value)); |
| 63 | } |
| 64 | ui.label("USTAR 내용 무결성 검증 정보는 제공되지 않음"); |
| 65 | if self.controller.busy() { |
| 66 | ui.label("작업 스레드 종료 확인 전에는 다시 시작하거나 닫지 않습니다"); |
| 67 | } |
| 68 | if let Some(error) = &self.controller.spawn_error { |
| 69 | ui.label(format!( |
| 70 | "작업 시작 실패: {}", |
| 71 | format!("{error:?}").chars().take(256).collect::<String>() |
| 72 | )); |
| 73 | } |
| 74 | if let Some(completion) = &self.controller.terminal { |
| 75 | if !completion.outcome.is_ok() || completion.delivery.is_some() { |
| 76 | let detail = match &completion.outcome { |
| 77 | zipelo_ui_memory_app::runtime::Outcome::Zip(t) => { |
| 78 | format!("{:?}", t.result().err()) |
| 79 | } |
| 80 | zipelo_ui_memory_app::runtime::Outcome::Ustar(t) => { |
| 81 | format!("{:?}", t.result().err()) |
| 82 | } |
| 83 | zipelo_ui_memory_app::runtime::Outcome::Gzip(t) => { |
| 84 | format!("{:?}", t.result().err()) |
| 85 | } |
| 86 | }; |
| 87 | ui.label(format!( |
| 88 | "반환 원인: {}", |
| 89 | detail.chars().take(512).collect::<String>() |
| 90 | )); |
| 91 | if let Some(fault) = completion.delivery { |
| 92 | ui.label(format!( |
| 93 | "UI 전달 원인: {:?}, 최초 누락 {}", |
| 94 | fault.kind, fault.first_missing_sequence |
| 95 | )); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | }); |
| 100 | egui::CentralPanel::default_margins().show(root, |ui| { |
| 101 | ui.columns(2, |columns| { |
| 102 | columns[0].heading("메모리 결과 목록"); |
| 103 | let rows: Vec<String> = self |
| 104 | .controller |
| 105 | .rows() |
| 106 | .into_iter() |
| 107 | .map(str::to_owned) |
| 108 | .collect(); |
| 109 | for (index, name) in rows.iter().enumerate() { |
| 110 | if columns[0] |
| 111 | .selectable_label( |
| 112 | self.controller.selected.is_some_and(|(_, _, i)| i == index), |
| 113 | name, |
| 114 | ) |
| 115 | .clicked() |
| 116 | { |
| 117 | if let Some(task) = &self.controller.task { |
| 118 | self.controller |
| 119 | .select(task.id, self.controller.generation, index); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | columns[1].heading("선택한 내용"); |
| 124 | if let Some(bytes) = self.controller.selected_bytes() { |
| 125 | columns[1].label(format!("원본 {} bytes / 텍스트 최대 2048자", bytes.len())); |
| 126 | } |
| 127 | columns[1].label(self.controller.preview()); |
| 128 | }); |
| 129 | }); |
| 130 | if self.controller.close == CloseState::Confirming { |
| 131 | egui::Window::new("작업 중 닫기") |
| 132 | .collapsible(false) |
| 133 | .resizable(false) |
| 134 | .show(&ctx, |ui| { |
| 135 | ui.label("취소를 요청하고 작업 스레드 종료를 기다릴까요?"); |
| 136 | if ui.button("계속 열기").clicked() { |
| 137 | self.controller.keep_open(); |
| 138 | } |
| 139 | if ui.button("취소 후 닫기").clicked() { |
| 140 | self.controller.confirm_close(); |
| 141 | } |
| 142 | }); |
| 143 | } |
| 144 | if self.controller.close == CloseState::Waiting { |
| 145 | egui::Window::new("종료 대기") |
| 146 | .collapsible(false) |
| 147 | .show(&ctx, |ui| { |
| 148 | ui.label("취소 요청은 전송됐습니다. 작업 종료를 기다립니다."); |
| 149 | if ui.button("닫기 철회").clicked() { |
| 150 | self.controller.keep_open(); |
| 151 | } |
| 152 | }); |
| 153 | } |
| 154 | if self.controller.busy() { |
| 155 | ctx.request_repaint_after(std::time::Duration::from_millis(30)); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | fn main() -> eframe::Result { |
| 161 | let font = system_font::load().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?; |
| 162 | eframe::run_native( |
| 163 | "Zipelo 합성 메모리 작업", |
| 164 | eframe::NativeOptions { |
| 165 | renderer: eframe::Renderer::Glow, |
| 166 | viewport: egui::ViewportBuilder::default() |
| 167 | .with_inner_size([1060.0, 720.0]) |
| 168 | .with_min_inner_size([760.0, 540.0]), |
| 169 | ..Default::default() |
| 170 | }, |
| 171 | Box::new(move |cc| { |
| 172 | let mut fonts = FontDefinitions::empty(); |
| 173 | let mut data = FontData::from_owned(font.bytes); |
| 174 | data.index = font.face_index; |
| 175 | fonts.font_data.insert("noto-kr".into(), data.into()); |
| 176 | fonts |
| 177 | .families |
| 178 | .insert(FontFamily::Proportional, vec!["noto-kr".into()]); |
| 179 | cc.egui_ctx.set_fonts(fonts); |
| 180 | cc.egui_ctx.set_visuals(egui::Visuals::light()); |
| 181 | cc.egui_ctx.style_mut_of(egui::Theme::Light, |style| { |
| 182 | style |
| 183 | .text_styles |
| 184 | .insert(TextStyle::Body, FontId::proportional(18.0)); |
| 185 | style |
| 186 | .text_styles |
| 187 | .insert(TextStyle::Button, FontId::proportional(18.0)); |
| 188 | style |
| 189 | .text_styles |
| 190 | .insert(TextStyle::Heading, FontId::proportional(26.0)); |
| 191 | style.visuals.panel_fill = Color32::WHITE; |
| 192 | style.visuals.override_text_color = Some(Color32::from_rgb(24, 39, 57)); |
| 193 | style.visuals.selection.bg_fill = Color32::from_rgb(211, 230, 246); |
| 194 | style.spacing.item_spacing = egui::vec2(12.0, 10.0); |
| 195 | style.spacing.button_padding = egui::vec2(14.0, 10.0); |
| 196 | }); |
| 197 | Ok(Box::<App>::default()) |
| 198 | }), |
| 199 | ) |
| 200 | } |