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