Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions desktop/src-tauri/src/macos_file_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,27 @@ mod tests {
"ModalFuture::new returns Self; a bare `return;` on the sync nil-panel path is E0069"
);
}

#[test]
fn patched_rfd_async_nil_panel_cancels_before_callback_move() {
// dialog_callback is a non-Copy Fn. The async sheet path used to
// move it into RcBlock, then call it again on a nil panel (E0382).
let sheet = RFD_MODAL
.split("if unsafe { app.isRunning() }")
.nth(1)
.and_then(|s| s.split("} else {").next())
.expect("async sheet path in ModalFuture::new");
let build = sheet
.find("let Some(modal) = build_modal")
.expect("async nil-panel guard");
let block = sheet.find("RcBlock::new").expect("sheet completion block");
assert!(
build < block,
"nil-panel cancel must run before dialog_callback moves into RcBlock (E0382)"
);
assert!(
sheet.contains("NSModalResponseCancel"),
"nil panel must complete the sheet path as cancelled"
);
}
}
13 changes: 8 additions & 5 deletions desktop/src-tauri/vendor/rfd/src/backend/macos/modal_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,20 @@ impl<R: 'static + Default, D: AsModal + 'static> ModalFuture<R, D> {
run_on_main(move |mtm| {
let window = window;

// Stock rfd builds the panel, then moves dialog_callback into
// RcBlock. After Option<D>, the nil-panel cancel must run
// first — the Fn is not Copy (E0382).
let Some(modal) = build_modal(mtm) else {
dialog_callback(state, NSModalResponseCancel);
return;
};

let completion = {
let state = state.clone();
block2::RcBlock::new(move |result| {
dialog_callback(state.clone(), result);
})
};

let Some(modal) = build_modal(mtm) else {
dialog_callback(state, NSModalResponseCancel);
return;
};
let inner = modal.inner_modal().retain();

state.lock().unwrap().modal = Some(modal);
Expand Down