Windows 끌어 놓기를 화면 스레드에서 진행해 놓기가 끝나지 않던 문제를 고침
OLE 끌기(SHDoDragDrop)는 버튼을 누른 창의 스레드에서 불러야 마우스 입력을 받음. 별도 스레드에서 불러 놓기를 받지 못하고 끌기가 끝나지 않았음. - 화면 스레드에서 끌기를 진행하고, 앱은 끌기 전에 풀기를 먼저 시작함 - 받는 쪽이 CF_HDROP을 요청하면 데이터 객체가 앱이 넘긴 pump로 작업자 진행을 직접 받으며 다 풀리기를 기다림 - 암호 등 사용자 응답이 필요하면 끌기 중에는 실패로 넘기고, 끌기가 끝나면 기존 창으로 물음 - 끌기 동안 작업이 끝났으면 끌기에서 돌아온 직후 마무리하고 원래 풀 위치로 되돌림 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 작성자
- LeeJunyoung
- 작성 시각
- 커밋
8bd99a58987bf26d4f68a5046b8bd67827f648ac- 부모
- ed2ac3e
변경된 파일 6개
+274-103| @@ -191,6 +191,15 @@ struct Marquee { | ||
| 191 | 191 | moved: bool, |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 추가: /// 끌어 놓으려고 푼 폴더에서 넘길 항목의 경로. 실제로 있는 것만 돌려줌. | |
| 195 | 추가: fn drag_paths(folder: &Path, names: &[String]) -> Vec<PathBuf> { | |
| 196 | 추가: names | |
| 197 | 추가: .iter() | |
| 198 | 추가: .map(|name| name.split('/').fold(folder.to_path_buf(), |path, part| path.join(part))) | |
| 199 | 추가: .filter(|path| path.exists()) | |
| 200 | 추가: .collect() | |
| 201 | 추가: } | |
| 202 | 추가: | |
| 194 | 203 | /// 창 밖 끌기를 시작하려면 누른 곳에서 이만큼(px) 움직여야 함. |
| 195 | 204 | const DRAG_OUT_DISTANCE: f32 = 8.0; |
| 196 | 205 | |
| @@ -565,8 +574,10 @@ impl ArchiveApp { | ||
| 565 | 574 | // 같은 항목을 이미 풀어 두었으면 다시 풀지 않고 바로 끎. |
| 566 | 575 | let paths = paths.clone(); |
| 567 | 576 | crate::log_debug!("풀어 둔 파일로 바로 끌기: {}개", paths.len()); |
| 577 | 추가: let ready = paths.clone(); | |
| 568 | 578 | let drag = self.drag_out.as_mut().unwrap(); |
| 569 | 삭제: let started = drag.start(); | |
| 579 | 추가: // Wayland와 X11은 시작할 때 이전 경로를 지우므로 시작한 뒤 넘김. | |
| 580 | 추가: let started = drag.start(&mut || Some(Ok(ready.clone()))); | |
| 570 | 581 | if started { |
| 571 | 582 | drag.provide(&paths); |
| 572 | 583 | self.release_after_move = true; |
| @@ -574,28 +585,18 @@ impl ArchiveApp { | ||
| 574 | 585 | } |
| 575 | 586 | return started; |
| 576 | 587 | } |
| 577 | 삭제: if !self.drag_out.as_mut().is_some_and(|drag| drag.start()) { | |
| 578 | 삭제: crate::log_warn!("운영체제 끌기를 시작하지 못함"); | |
| 579 | 삭제: return false; | |
| 580 | 삭제: } | |
| 581 | 삭제: // 운영체제가 끌기를 넘겨받으면 버튼 놓기가 이 창에 오지 않으므로 대신 넣어 줌. | |
| 582 | 삭제: self.release_after_move = true; | |
| 583 | 삭제: crate::log_debug!("창 밖으로 끌기 시작: {names:?}"); | |
| 584 | 588 | self.marquee = None; |
| 585 | 589 | self.drag_cancelled = false; |
| 586 | 590 | self.last_open = None; |
| 587 | 591 | let Some(folder) = self.new_open_folder() else { |
| 588 | 삭제: if let Some(drag) = self.drag_out.as_mut() { | |
| 589 | 삭제: drag.fail(); | |
| 590 | 삭제: } | |
| 591 | 592 | return false; |
| 592 | 593 | }; |
| 593 | 594 | let request = OpenRequest { |
| 594 | 595 | folder: folder.clone(), |
| 595 | 596 | name: String::new(), |
| 596 | 삭제: destination: std::mem::replace(&mut self.destination, folder), | |
| 597 | 추가: destination: std::mem::replace(&mut self.destination, folder.clone()), | |
| 597 | 598 | automatic: std::mem::replace(&mut self.automatic_destination, true), |
| 598 | 삭제: drag: Some(names), | |
| 599 | 추가: drag: Some(names.clone()), | |
| 599 | 600 | key: Some(key), |
| 600 | 601 | }; |
| 601 | 602 | self.opening = Some(request); |
| @@ -604,12 +605,61 @@ impl ArchiveApp { | ||
| 604 | 605 | .into_iter() |
| 605 | 606 | .collect(), |
| 606 | 607 | ); |
| 607 | 삭제: if self.extract_selection(selection) { | |
| 608 | 삭제: true | |
| 609 | 삭제: } else { | |
| 608 | 추가: // 풀기를 먼저 시작함. Windows처럼 놓을 때까지 돌아오지 않는 끌기는 그동안 pump로 | |
| 609 | 추가: // 작업 진행을 받아 다 풀린 파일을 넘김. | |
| 610 | 추가: if !self.extract_selection(selection) { | |
| 610 | 611 | self.finish_open(false); |
| 611 | 삭제: false | |
| 612 | 추가: return false; | |
| 613 | 추가: } | |
| 614 | 추가: crate::log_debug!("창 밖으로 끌기 시작: {names:?}"); | |
| 615 | 추가: let started = { | |
| 616 | 추가: let model = &mut self.model; | |
| 617 | 추가: let mut pump = move || { | |
| 618 | 추가: model.poll(); | |
| 619 | 추가: if model.busy() { | |
| 620 | 추가: // 암호, 큰 작업 승인 등 사용자 응답이 필요하면 끌기 중에는 넘길 수 없음. | |
| 621 | 추가: return (model.challenge.is_some() | |
| 622 | 추가: || model.resource.is_some() | |
| 623 | 추가: || model.conflict.is_some()) | |
| 624 | 추가: .then_some(Err(())); | |
| 625 | 추가: } | |
| 626 | 추가: let completed = model.confirmed | |
| 627 | 추가: && model | |
| 628 | 추가: .terminal | |
| 629 | 추가: .as_ref() | |
| 630 | 추가: .is_some_and(|t| t.outcome == Outcome::Completed); | |
| 631 | 추가: let paths = drag_paths(&folder, &names); | |
| 632 | 추가: Some(if completed && !paths.is_empty() { | |
| 633 | 추가: Ok(paths) | |
| 634 | 추가: } else { | |
| 635 | 추가: Err(()) | |
| 636 | 추가: }) | |
| 637 | 추가: }; | |
| 638 | 추가: self.drag_out.as_mut().unwrap().start(&mut pump) | |
| 639 | 추가: }; | |
| 640 | 추가: if !started { | |
| 641 | 추가: crate::log_warn!("운영체제 끌기를 시작하지 못함"); | |
| 642 | 추가: // 받을 곳이 없으므로 풀던 작업을 취소하고 결과 창은 띄우지 않음. | |
| 643 | 추가: self.drag_cancelled = true; | |
| 644 | 추가: self.clear_password(); | |
| 645 | 추가: self.model.cancel(); | |
| 646 | 추가: return false; | |
| 612 | 647 | } |
| 648 | 추가: // 운영체제가 끌기를 넘겨받으면 버튼 놓기가 이 창에 오지 않으므로 대신 넣어 줌. | |
| 649 | 추가: self.release_after_move = true; | |
| 650 | 추가: // 끌기 동안 pump가 작업을 끝까지 받았으면 다음 화면의 끝남 감지를 거치지 않으므로 | |
| 651 | 추가: // 여기서 마무리함. | |
| 652 | 추가: if !self.model.busy() && self.opening.is_some() { | |
| 653 | 추가: let completed = self.model.confirmed | |
| 654 | 추가: && self | |
| 655 | 추가: .model | |
| 656 | 추가: .terminal | |
| 657 | 추가: .as_ref() | |
| 658 | 추가: .is_some_and(|t| t.outcome == Outcome::Completed); | |
| 659 | 추가: self.owned_destination = None; | |
| 660 | 추가: self.finish_open(completed); | |
| 661 | 추가: } | |
| 662 | 추가: true | |
| 613 | 663 | } |
| 614 | 664 | |
| 615 | 665 | /// 운영체제 끌기에서 온 사건을 처리함. |
| @@ -647,14 +697,11 @@ impl ArchiveApp { | ||
| 647 | 697 | self.automatic_destination = request.automatic; |
| 648 | 698 | if let Some(names) = request.drag { |
| 649 | 699 | let cancelled = std::mem::take(&mut self.drag_cancelled); |
| 650 | 삭제: let paths: Vec<PathBuf> = names | |
| 651 | 삭제: .iter() | |
| 652 | 삭제: .map(|name| { | |
| 653 | 삭제: name.split('/') | |
| 654 | 삭제: .fold(request.folder.clone(), |path, part| path.join(part)) | |
| 655 | 삭제: }) | |
| 656 | 삭제: .filter(|path| completed && path.exists()) | |
| 657 | 삭제: .collect(); | |
| 700 | 추가: let paths = if completed { | |
| 701 | 추가: drag_paths(&request.folder, &names) | |
| 702 | 추가: } else { | |
| 703 | 추가: Vec::new() | |
| 704 | 추가: }; | |
| 658 | 705 | let Some(drag) = self.drag_out.as_mut() else { |
| 659 | 706 | return; |
| 660 | 707 | }; |
| @@ -18,15 +18,21 @@ pub enum DragEvent { | ||
| 18 | 18 | Cancelled, |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 추가: /// 끌기가 끝날 때까지 돌아오지 않는 구현(Windows)이 받는 쪽의 요청을 기다리는 동안 | |
| 22 | 추가: /// 앱의 작업 진행을 받으려고 부르는 함수. 다 풀렸으면 `Some(Ok(경로))`, 실패했거나 | |
| 23 | 추가: /// 사용자 응답(암호 등)이 필요해 지금 넘길 수 없으면 `Some(Err(()))`, 아직이면 `None`. | |
| 24 | 추가: pub type Pump<'a> = dyn FnMut() -> Option<Result<Vec<PathBuf>, ()>> + 'a; | |
| 25 | 추가: | |
| 21 | 26 | /// 운영체제별 끌어 놓기 시작 구현. |
| 22 | 27 | /// |
| 23 | 삭제: /// 끌기를 먼저 시작하고, 받는 쪽이 놓은 뒤 데이터를 요청하면 풀기가 끝날 때까지 기다렸다가 | |
| 24 | 삭제: /// [`DragOut::provide`]로 받은 경로를 넘김(지연 제공). 그래서 파일 크기와 관계없이 | |
| 25 | 삭제: /// 놓은 위치에 바로 풀림. | |
| 28 | 추가: /// 앱은 풀기를 먼저 시작한 뒤 끌기를 시작함. 받는 쪽이 놓은 뒤 데이터를 요청하면 풀기가 | |
| 29 | 추가: /// 끝날 때까지 기다렸다가 경로를 넘김(지연 제공). 그래서 파일 크기와 관계없이 놓은 위치에 | |
| 30 | 추가: /// 바로 풀림. Wayland와 X11은 끌기를 시작하고 바로 돌아오며 [`DragOut::provide`]로 경로를 | |
| 31 | 추가: /// 받음. Windows OLE 끌기는 버튼을 누른 창의 스레드(화면 스레드)에서 놓을 때까지 돌아오지 | |
| 32 | 추가: /// 않으므로, 그동안 `pump`로 작업 진행을 받음. | |
| 26 | 33 | pub trait DragOut { |
| 27 | 34 | /// 지금 누르고 있는 마우스 버튼으로 운영체제 끌기를 시작함. 시작하지 못하면 false. |
| 28 | 삭제: /// 끌기 자체는 돌아온 뒤에도 계속되며 끝나면 [`DragOut::poll`]로 알림. | |
| 29 | 삭제: fn start(&mut self) -> bool; | |
| 35 | 추가: fn start(&mut self, pump: &mut Pump<'_>) -> bool; | |
| 30 | 36 | /// 지난 화면 이후 들어온 끌기 사건. |
| 31 | 37 | fn poll(&mut self) -> Option<DragEvent>; |
| 32 | 38 | /// 풀기가 끝난 파일과 폴더의 절대 경로를 넘김. 이미 들어온 요청과 이후 요청에 씀. |
| @@ -146,7 +146,7 @@ pub fn create( | ||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | impl DragOut for WaylandDrag { |
| 149 | 삭제: fn start(&mut self) -> bool { | |
| 149 | 추가: fn start(&mut self, _: &mut zipelo_ui_memory_app::drag_out::Pump<'_>) -> bool { | |
| 150 | 150 | let mut shared = self.shared.lock().unwrap(); |
| 151 | 151 | let Some(serial) = shared.press else { |
| 152 | 152 | zipelo_ui_memory_app::log_debug!("끌기 시작 실패: 누르고 있는 버튼 없음"); |
| @@ -4,15 +4,18 @@ | ||
| 4 | 4 | //! 동시에 풀기를 시작함. 탐색기나 브라우저에 놓으면 받는 쪽이 CF_HDROP을 요청하는데, |
| 5 | 5 | //! 그때 다 풀릴 때까지 기다렸다가 풀린 파일 경로를 넘겨 받는 쪽이 놓은 위치로 복사함. |
| 6 | 6 | //! |
| 7 | 삭제: //! OLE 끌기(SHDoDragDrop)는 놓거나 취소할 때까지 돌아오지 않으므로 별도 스레드에서 | |
| 8 | 삭제: //! 진행함. 그동안 화면 스레드는 작업자의 풀기 진행을 계속 받음. | |
| 7 | 추가: //! OLE 끌기(SHDoDragDrop)는 버튼을 누른 창의 스레드(화면 스레드)에서 불러야 마우스 입력을 | |
| 8 | 추가: //! 받음(다른 스레드에서 부르면 놓기를 받지 못해 끝나지 않음). 놓거나 취소할 때까지 | |
| 9 | 추가: //! 돌아오지 않으므로, 받는 쪽이 파일을 요청하면 앱이 넘긴 pump로 작업자의 풀기 진행을 | |
| 10 | 추가: //! 직접 받으며 다 풀리기를 기다림. | |
| 9 | 11 | |
| 10 | 12 | use std::{ |
| 13 | 추가: cell::Cell, | |
| 11 | 14 | collections::VecDeque, |
| 12 | 15 | ffi::c_void, |
| 13 | 16 | path::PathBuf, |
| 14 | 17 | sync::{ |
| 15 | 삭제: Arc, Condvar, Mutex, | |
| 18 | 추가: Arc, Mutex, | |
| 16 | 19 | atomic::{AtomicU32, Ordering}, |
| 17 | 20 | }, |
| 18 | 21 | time::Duration, |
| @@ -22,7 +25,7 @@ use windows_sys::{ | ||
| 22 | 25 | Foundation::{DRAGDROP_S_DROP, HWND}, |
| 23 | 26 | System::{ |
| 24 | 27 | Memory::{GHND, GlobalAlloc, GlobalLock, GlobalUnlock}, |
| 25 | 삭제: Ole::{CF_HDROP, DROPEFFECT, DROPEFFECT_COPY, OleInitialize, OleUninitialize}, | |
| 28 | 추가: Ole::{CF_HDROP, DROPEFFECT, DROPEFFECT_COPY, OleInitialize}, | |
| 26 | 29 | }, |
| 27 | 30 | UI::{ |
| 28 | 31 | Input::KeyboardAndMouse::{GetAsyncKeyState, VK_LBUTTON, VK_RBUTTON}, |
| @@ -32,7 +35,12 @@ use windows_sys::{ | ||
| 32 | 35 | }, |
| 33 | 36 | core::{GUID, HRESULT}, |
| 34 | 37 | }; |
| 35 | 삭제: use zipelo_ui_memory_app::drag_out::{DragEvent, DragOut}; | |
| 38 | 추가: use zipelo_ui_memory_app::drag_out::{DragEvent, DragOut, Pump}; | |
| 39 | 추가: | |
| 40 | 추가: thread_local! { | |
| 41 | 추가: /// 끌기가 진행되는 동안(start 안에서만) 앱이 넘긴 작업 진행 함수. | |
| 42 | 추가: static PUMP: Cell<Option<*mut Pump<'static>>> = const { Cell::new(None) }; | |
| 43 | 추가: } | |
| 36 | 44 | |
| 37 | 45 | const S_OK: HRESULT = 0; |
| 38 | 46 | const E_NOINTERFACE: HRESULT = 0x8000_4002_u32 as i32; |
| @@ -100,7 +108,7 @@ struct Shared { | ||
| 100 | 108 | generation: u64, |
| 101 | 109 | } |
| 102 | 110 | |
| 103 | 삭제: type State = Arc<(Mutex<Shared>, Condvar)>; | |
| 111 | 추가: type State = Arc<Mutex<Shared>>; | |
| 104 | 112 | |
| 105 | 113 | pub struct WindowsDrag { |
| 106 | 114 | hwnd: isize, |
| @@ -117,10 +125,13 @@ pub fn create( | ||
| 117 | 125 | else { |
| 118 | 126 | return None; |
| 119 | 127 | }; |
| 120 | 삭제: zipelo_ui_memory_app::log_debug!("Windows 끌어 놓기 준비"); | |
| 128 | 추가: // 안전성: 화면 스레드에서 OLE를 초기화함. winit이 이미 했으면 S_FALSE이며 앱이 끝날 | |
| 129 | 추가: // 때까지 유지함. | |
| 130 | 추가: let result = unsafe { OleInitialize(std::ptr::null()) }; | |
| 131 | 추가: zipelo_ui_memory_app::log_debug!("Windows 끌어 놓기 준비 (OLE {result:#x})"); | |
| 121 | 132 | Some(WindowsDrag { |
| 122 | 133 | hwnd: window.hwnd.get(), |
| 123 | 삭제: state: Arc::new((Mutex::new(Shared::default()), Condvar::new())), | |
| 134 | 추가: state: Arc::new(Mutex::new(Shared::default())), | |
| 124 | 135 | repaint, |
| 125 | 136 | }) |
| 126 | 137 | } |
| @@ -135,67 +146,64 @@ fn button_held() -> bool { | ||
| 135 | 146 | } |
| 136 | 147 | |
| 137 | 148 | impl DragOut for WindowsDrag { |
| 138 | 삭제: fn start(&mut self) -> bool { | |
| 149 | 추가: fn start(&mut self, pump: &mut Pump<'_>) -> bool { | |
| 139 | 150 | if !button_held() { |
| 140 | 151 | return false; |
| 141 | 152 | } |
| 142 | 153 | let generation = { |
| 143 | 삭제: let mut shared = self.state.0.lock().unwrap(); | |
| 154 | 추가: let mut shared = self.state.lock().unwrap(); | |
| 144 | 155 | shared.generation += 1; |
| 145 | 156 | shared.ready = None; |
| 146 | 157 | shared.events.clear(); |
| 147 | 158 | shared.generation |
| 148 | 159 | }; |
| 149 | 삭제: let state = self.state.clone(); | |
| 150 | 삭제: let hwnd = self.hwnd; | |
| 151 | 삭제: let repaint = self.repaint.clone(); | |
| 152 | 삭제: std::thread::Builder::new() | |
| 153 | 삭제: .name("zipelo-windows-drag".into()) | |
| 154 | 삭제: .spawn(move || { | |
| 155 | 삭제: // 안전성: 이 스레드에서만 OLE를 초기화하고 끝날 때 해제함. 데이터 객체는 | |
| 156 | 삭제: // 끌기가 끝난 뒤 이 스레드가 가진 참조 하나를 놓음. | |
| 157 | 삭제: let result = unsafe { | |
| 158 | 삭제: OleInitialize(std::ptr::null()); | |
| 159 | 삭제: let object = DataObject::create(state.clone(), generation); | |
| 160 | 삭제: let mut effect: DROPEFFECT = 0; | |
| 161 | 삭제: let result = SHDoDragDrop( | |
| 162 | 삭제: hwnd as HWND, | |
| 163 | 삭제: object, | |
| 164 | 삭제: std::ptr::null_mut(), | |
| 165 | 삭제: DROPEFFECT_COPY, | |
| 166 | 삭제: &mut effect, | |
| 167 | 삭제: ); | |
| 168 | 삭제: release(object); | |
| 169 | 삭제: OleUninitialize(); | |
| 170 | 삭제: result | |
| 171 | 삭제: }; | |
| 172 | 삭제: zipelo_ui_memory_app::log_debug!("셸 끌기 끝: {result:#x}"); | |
| 173 | 삭제: let mut shared = state.0.lock().unwrap(); | |
| 174 | 삭제: if shared.generation == generation { | |
| 175 | 삭제: shared.events.push_back(if result == DRAGDROP_S_DROP { | |
| 176 | 삭제: DragEvent::Finished | |
| 177 | 삭제: } else { | |
| 178 | 삭제: DragEvent::Cancelled | |
| 179 | 삭제: }); | |
| 180 | 삭제: } | |
| 181 | 삭제: drop(shared); | |
| 182 | 삭제: repaint.request_repaint(); | |
| 183 | 삭제: }) | |
| 184 | 삭제: .is_ok() | |
| 160 | 추가: // 안전성: pump는 이 함수가 돌아오기 전까지만 쓰고, 끝나면 바로 지움. 데이터 객체의 | |
| 161 | 추가: // GetData는 SHDoDragDrop 안에서 같은 스레드로 불림. | |
| 162 | 추가: let pump: *mut Pump<'_> = pump; | |
| 163 | 추가: PUMP.with(|cell| { | |
| 164 | 추가: cell.set(Some(unsafe { | |
| 165 | 추가: std::mem::transmute::<*mut Pump<'_>, *mut Pump<'static>>(pump) | |
| 166 | 추가: })) | |
| 167 | 추가: }); | |
| 168 | 추가: // 안전성: 데이터 객체는 끌기가 끝난 뒤 이 함수가 가진 참조 하나를 놓음. | |
| 169 | 추가: let result = unsafe { | |
| 170 | 추가: let object = DataObject::create(self.state.clone(), generation); | |
| 171 | 추가: let mut effect: DROPEFFECT = 0; | |
| 172 | 추가: let result = SHDoDragDrop( | |
| 173 | 추가: self.hwnd as HWND, | |
| 174 | 추가: object, | |
| 175 | 추가: std::ptr::null_mut(), | |
| 176 | 추가: DROPEFFECT_COPY, | |
| 177 | 추가: &mut effect, | |
| 178 | 추가: ); | |
| 179 | 추가: release(object); | |
| 180 | 추가: result | |
| 181 | 추가: }; | |
| 182 | 추가: PUMP.with(|cell| cell.set(None)); | |
| 183 | 추가: zipelo_ui_memory_app::log_debug!("셸 끌기 끝: {result:#x}"); | |
| 184 | 추가: let mut shared = self.state.lock().unwrap(); | |
| 185 | 추가: if shared.generation == generation { | |
| 186 | 추가: shared.events.push_back(if result == DRAGDROP_S_DROP { | |
| 187 | 추가: DragEvent::Finished | |
| 188 | 추가: } else { | |
| 189 | 추가: DragEvent::Cancelled | |
| 190 | 추가: }); | |
| 191 | 추가: } | |
| 192 | 추가: drop(shared); | |
| 193 | 추가: self.repaint.request_repaint(); | |
| 194 | 추가: true | |
| 185 | 195 | } |
| 186 | 196 | |
| 187 | 197 | fn poll(&mut self) -> Option<DragEvent> { |
| 188 | 삭제: self.state.0.lock().unwrap().events.pop_front() | |
| 198 | 추가: self.state.lock().unwrap().events.pop_front() | |
| 189 | 199 | } |
| 190 | 200 | |
| 191 | 201 | fn provide(&mut self, paths: &[PathBuf]) { |
| 192 | 삭제: self.state.0.lock().unwrap().ready = Some(Ready::Paths(paths.to_vec())); | |
| 193 | 삭제: self.state.1.notify_all(); | |
| 202 | 추가: self.state.lock().unwrap().ready = Some(Ready::Paths(paths.to_vec())); | |
| 194 | 203 | } |
| 195 | 204 | |
| 196 | 205 | fn fail(&mut self) { |
| 197 | 삭제: self.state.0.lock().unwrap().ready = Some(Ready::Failed); | |
| 198 | 삭제: self.state.1.notify_all(); | |
| 206 | 추가: self.state.lock().unwrap().ready = Some(Ready::Failed); | |
| 199 | 207 | } |
| 200 | 208 | } |
| 201 | 209 | |
| @@ -288,23 +296,34 @@ impl DataObject { | ||
| 288 | 296 | .cast() |
| 289 | 297 | } |
| 290 | 298 | |
| 291 | 삭제: /// 다 풀릴 때까지 기다린 뒤 경로를 돌려줌. 실패했거나 새 끌기가 시작되면 None. | |
| 299 | 추가: /// 다 풀릴 때까지 작업 진행을 받으며 기다린 뒤 경로를 돌려줌. 실패했거나, 사용자 응답이 | |
| 300 | 추가: /// 필요하거나, 새 끌기가 시작됐으면 None. | |
| 292 | 301 | fn wait_paths(&self) -> Option<Vec<PathBuf>> { |
| 293 | 삭제: let (lock, ready) = &*self.state; | |
| 294 | 삭제: let mut shared = lock.lock().unwrap(); | |
| 295 | 302 | loop { |
| 296 | 삭제: if shared.generation != self.generation { | |
| 297 | 삭제: return None; | |
| 303 | 추가: { | |
| 304 | 추가: let shared = self.state.lock().unwrap(); | |
| 305 | 추가: if shared.generation != self.generation { | |
| 306 | 추가: return None; | |
| 307 | 추가: } | |
| 308 | 추가: match &shared.ready { | |
| 309 | 추가: Some(Ready::Paths(paths)) => return Some(paths.clone()), | |
| 310 | 추가: Some(Ready::Failed) => return None, | |
| 311 | 추가: None => {} | |
| 312 | 추가: } | |
| 298 | 313 | } |
| 299 | 삭제: match &shared.ready { | |
| 300 | 삭제: Some(Ready::Paths(paths)) => return Some(paths.clone()), | |
| 301 | 삭제: Some(Ready::Failed) => return None, | |
| 302 | 삭제: None => { | |
| 303 | 삭제: shared = ready | |
| 304 | 삭제: .wait_timeout(shared, Duration::from_millis(200)) | |
| 305 | 삭제: .unwrap() | |
| 306 | 삭제: .0; | |
| 314 | 추가: // 끌기 밖에서 불리면(받는 쪽이 객체를 늦게 쓰는 경우) 기다릴 방법이 없으므로 실패. | |
| 315 | 추가: let pump = PUMP.with(Cell::get)?; | |
| 316 | 추가: // 안전성: PUMP는 start가 진행 중인 같은 스레드에서만 설정돼 있음. | |
| 317 | 추가: match unsafe { (*pump)() } { | |
| 318 | 추가: Some(Ok(paths)) => { | |
| 319 | 추가: self.state.lock().unwrap().ready = Some(Ready::Paths(paths.clone())); | |
| 320 | 추가: return Some(paths); | |
| 321 | 추가: } | |
| 322 | 추가: Some(Err(())) => { | |
| 323 | 추가: self.state.lock().unwrap().ready = Some(Ready::Failed); | |
| 324 | 추가: return None; | |
| 307 | 325 | } |
| 326 | 추가: None => std::thread::sleep(Duration::from_millis(15)), | |
| 308 | 327 | } |
| 309 | 328 | } |
| 310 | 329 | } |
| @@ -119,7 +119,7 @@ impl Atoms { | ||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | impl DragOut for X11Drag { |
| 122 | 삭제: fn start(&mut self) -> bool { | |
| 122 | 추가: fn start(&mut self, _: &mut zipelo_ui_memory_app::drag_out::Pump<'_>) -> bool { | |
| 123 | 123 | match self.begin() { |
| 124 | 124 | Ok(()) => true, |
| 125 | 125 | Err(error) => { |
| @@ -7,6 +7,11 @@ struct DragLog { | ||
| 7 | 7 | accept: bool, |
| 8 | 8 | /// provide와 start가 불린 순서. |
| 9 | 9 | calls: Vec<&'static str>, |
| 10 | 추가: /// Windows처럼 놓을 때까지 start 안에 머물며, 받는 쪽 요청에 pump로 경로를 받음. | |
| 11 | 추가: /// 머무는 동안 실행할 일(가짜 작업자 끝내기 등)을 담음. | |
| 12 | 추가: blocking: Option<Box<dyn FnMut()>>, | |
| 13 | 추가: /// blocking일 때 pump로 받은 결과. | |
| 14 | 추가: pumped: Vec<Result<Vec<PathBuf>, ()>>, | |
| 10 | 15 | provided: Vec<Vec<PathBuf>>, |
| 11 | 16 | failed: usize, |
| 12 | 17 | events: std::collections::VecDeque<zipelo_ui_memory_app::drag_out::DragEvent>, |
| @@ -15,11 +20,27 @@ struct DragLog { | ||
| 15 | 20 | struct FakeDrag(std::rc::Rc<std::cell::RefCell<DragLog>>); |
| 16 | 21 | |
| 17 | 22 | impl zipelo_ui_memory_app::drag_out::DragOut for FakeDrag { |
| 18 | 삭제: fn start(&mut self) -> bool { | |
| 19 | 삭제: let mut log = self.0.borrow_mut(); | |
| 20 | 삭제: log.starts += 1; | |
| 21 | 삭제: log.calls.push("start"); | |
| 22 | 삭제: log.accept | |
| 23 | 추가: fn start(&mut self, pump: &mut zipelo_ui_memory_app::drag_out::Pump<'_>) -> bool { | |
| 24 | 추가: let mut hook = { | |
| 25 | 추가: let mut log = self.0.borrow_mut(); | |
| 26 | 추가: log.starts += 1; | |
| 27 | 추가: log.calls.push("start"); | |
| 28 | 추가: if !log.accept { | |
| 29 | 추가: return false; | |
| 30 | 추가: } | |
| 31 | 추가: log.blocking.take() | |
| 32 | 추가: }; | |
| 33 | 추가: if let Some(work) = hook.as_mut() { | |
| 34 | 추가: work(); | |
| 35 | 추가: // 받는 쪽이 놓은 뒤 파일을 요청한 것처럼 결과가 나올 때까지 pump를 부름. | |
| 36 | 추가: for _ in 0..1000 { | |
| 37 | 추가: if let Some(result) = pump() { | |
| 38 | 추가: self.0.borrow_mut().pumped.push(result); | |
| 39 | 추가: break; | |
| 40 | 추가: } | |
| 41 | 추가: } | |
| 42 | 추가: } | |
| 43 | 추가: true | |
| 23 | 44 | } |
| 24 | 45 | fn poll(&mut self) -> Option<zipelo_ui_memory_app::drag_out::DragEvent> { |
| 25 | 46 | self.0.borrow_mut().events.pop_front() |
| @@ -166,11 +187,26 @@ fn rows_do_not_start_a_drag_when_the_platform_cannot() { | ||
| 166 | 187 | let log = with_drag(&mut s); |
| 167 | 188 | log.borrow_mut().accept = false; |
| 168 | 189 | s.click("alpha.txt", egui::Modifiers::NONE); |
| 190 | 추가: s.factory.state.borrow_mut().manual = true; | |
| 169 | 191 | drag_row(&mut s, "alpha.txt"); |
| 170 | 192 | assert_eq!(log.borrow().starts, 1); |
| 171 | 삭제: // 끌기를 시작하지 못하면 아무 작업도 시작하지 않음. | |
| 193 | 추가: // 풀기를 먼저 시작하므로, 끌기를 시작하지 못하면 바로 취소하고 결과 창을 띄우지 않음. | |
| 194 | 추가: assert!(s.app.model.cancellation_requested()); | |
| 195 | 추가: { | |
| 196 | 추가: let mut worker = s.factory.state.borrow_mut(); | |
| 197 | 추가: worker.frame(Event::Accepted { encryption: false }); | |
| 198 | 추가: worker.finish(Outcome::Cancelled, Publication::None); | |
| 199 | 추가: } | |
| 200 | 추가: let mut labels = Vec::new(); | |
| 201 | 추가: for _ in 0..10 { | |
| 202 | 추가: labels = layout_text(&s.frame(egui::Modifiers::NONE, vec![])); | |
| 203 | 추가: } | |
| 172 | 204 | assert!(!s.app.model.busy()); |
| 173 | 삭제: assert_eq!(s.factory.state.borrow().starts.len(), 1); | |
| 205 | 추가: assert!(log.borrow().provided.is_empty()); | |
| 206 | 추가: assert!( | |
| 207 | 추가: !labels.iter().any(|(text, _, _)| text.contains("취소했습니다")), | |
| 208 | 추가: "{labels:?}" | |
| 209 | 추가: ); | |
| 174 | 210 | } |
| 175 | 211 | |
| 176 | 212 | #[test] |
| @@ -284,3 +320,66 @@ fn drag_temp_folder_is_hidden_next_to_the_archive() { | ||
| 284 | 320 | ".자료.zip (Zipelo 임시)" |
| 285 | 321 | ); |
| 286 | 322 | } |
| 323 | 추가: | |
| 324 | 추가: #[test] | |
| 325 | 추가: fn blocking_drag_waits_for_extraction_inside_the_drag_and_hands_over_paths() { | |
| 326 | 추가: let scratch = Folder::new(); | |
| 327 | 추가: let mut s = Explorer::new(&scratch); | |
| 328 | 추가: let log = with_drag(&mut s); | |
| 329 | 추가: s.click("alpha.txt", egui::Modifiers::NONE); | |
| 330 | 추가: s.factory.state.borrow_mut().manual = true; | |
| 331 | 추가: let folder = scratch | |
| 332 | 추가: .0 | |
| 333 | 추가: .join(zipelo_ui_memory_app::archive_present::open_root_name("sample.zip")) | |
| 334 | 추가: .join("1"); | |
| 335 | 추가: // 끌기가 진행되는 동안(화면이 그려지지 않는 동안) 작업자가 풀기를 마침. | |
| 336 | 추가: let worker = s.factory.state.clone(); | |
| 337 | 추가: let target = folder.clone(); | |
| 338 | 추가: log.borrow_mut().blocking = Some(Box::new(move || { | |
| 339 | 추가: assert!(!worker.borrow().starts.is_empty(), "끌기 전에 풀기를 시작해야 함"); | |
| 340 | 추가: fs::create_dir_all(&target).unwrap(); | |
| 341 | 추가: fs::write(target.join("alpha.txt"), "x").unwrap(); | |
| 342 | 추가: let mut worker = worker.borrow_mut(); | |
| 343 | 추가: worker.frame(Event::Accepted { encryption: false }); | |
| 344 | 추가: worker.finish(Outcome::Completed, Publication::Complete); | |
| 345 | 추가: })); | |
| 346 | 추가: let before = s.factory.state.borrow().starts.len(); | |
| 347 | 추가: drag_row(&mut s, "alpha.txt"); | |
| 348 | 추가: assert_eq!(s.factory.state.borrow().starts.len(), before + 1); | |
| 349 | 추가: assert_eq!(log.borrow().pumped, vec![Ok(vec![folder.join("alpha.txt")])]); | |
| 350 | 추가: // 끌기에서 돌아오면 이미 끝난 작업을 마무리하고 원래 풀 위치로 되돌림. | |
| 351 | 추가: assert!(!s.app.model.busy()); | |
| 352 | 추가: for _ in 0..5 { | |
| 353 | 추가: s.frame(egui::Modifiers::NONE, vec![]); | |
| 354 | 추가: } | |
| 355 | 추가: s.factory.state.borrow_mut().manual = false; | |
| 356 | 추가: assert!(s.app.begin_extract()); | |
| 357 | 추가: assert!(matches!( | |
| 358 | 추가: s.factory.state.borrow().starts.last(), | |
| 359 | 추가: Some(Start::Extract { destination, .. }) if !destination.starts_with(&folder) | |
| 360 | 추가: )); | |
| 361 | 추가: } | |
| 362 | 추가: | |
| 363 | 추가: #[test] | |
| 364 | 추가: fn blocking_drag_does_not_wait_for_a_password_prompt() { | |
| 365 | 추가: let scratch = Folder::new(); | |
| 366 | 추가: let mut s = Explorer::new(&scratch); | |
| 367 | 추가: let log = with_drag(&mut s); | |
| 368 | 추가: s.click("alpha.txt", egui::Modifiers::NONE); | |
| 369 | 추가: s.factory.state.borrow_mut().manual = true; | |
| 370 | 추가: let worker = s.factory.state.clone(); | |
| 371 | 추가: log.borrow_mut().blocking = Some(Box::new(move || { | |
| 372 | 추가: let mut worker = worker.borrow_mut(); | |
| 373 | 추가: worker.frame(Event::Accepted { encryption: false }); | |
| 374 | 추가: worker.frame(Event::PasswordRequired { | |
| 375 | 추가: challenge_id: 1, | |
| 376 | 추가: attempt: 1, | |
| 377 | 추가: encrypt: false, | |
| 378 | 추가: }); | |
| 379 | 추가: })); | |
| 380 | 추가: drag_row(&mut s, "alpha.txt"); | |
| 381 | 추가: // 끌기 중에는 암호를 물을 수 없으므로 실패로 넘기고, 끌기가 끝나면 암호 창을 보여 줌. | |
| 382 | 추가: assert_eq!(log.borrow().pumped, vec![Err(())]); | |
| 383 | 추가: assert!(s.app.model.busy()); | |
| 384 | 추가: assert!(s.app.model.challenge.is_some()); | |
| 385 | 추가: } |