fix(windows): run new_window_req_handler on main thread#1660
fix(windows): run new_window_req_handler on main thread#1660Legend-Master wants to merge 5 commits intotauri-apps:devfrom
new_window_req_handler on main thread#1660Conversation
new_window_req_handler on main thread
Package Changes Through dc93dccThere are 1 changes which include wry with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
|
Thanks for taking this on. Because the field is pub struct Foo {
pub f: Box<dyn Fn() + Send + Sync>, // remove Send + Sync breaks the code
}
fn main() {
let f = move || {};
let foo = Foo { f: Box::new(f) };
std::thread::scope(|s| {
s.spawn(|| &foo);
});
} |
src/webview2/mod.rs
Outdated
| /// Send `function` to run on `hwnd`'s thread | ||
| /// | ||
| /// ## SAFETY: | ||
| /// | ||
| /// This function doesn't force a `Send` to make it easier to use, | ||
| /// the caller must call this function on the same thread as `hwnd` | ||
| /// or ensure the function is safe to `Send` |
There was a problem hiding this comment.
I don't know enough about the code to judge this, but I just briefly sanity-checked whether the function passed is ever Send.
All the call sites pass a function that is not Send, so it might be sensible to drop the second precondition even if it were correct. Judging a more complex precondition is more difficult than a simple one. It also seems like a precondition that would warrant a comment referencing external documentation on PostMessageW, since this is the only unsafe function called in this block.
There was a problem hiding this comment.
Not sure what's the better words here 🤔
There was a problem hiding this comment.
Would this be incorrect or incomplete? The closures passed are already not Send.
| /// Send `function` to run on `hwnd`'s thread | |
| /// | |
| /// ## SAFETY: | |
| /// | |
| /// This function doesn't force a `Send` to make it easier to use, | |
| /// the caller must call this function on the same thread as `hwnd` | |
| /// or ensure the function is safe to `Send` | |
| /// Send `function` to run on `hwnd`'s thread | |
| /// | |
| /// ## SAFETY: | |
| /// | |
| /// The caller must call this function on the same thread as `hwnd`. |
There was a problem hiding this comment.
It's quite tricky here, our custom protocol handler is !Send but marked with unsafe impl Send to send to another thread for async tasks, and then send back and called through dispatch_handler, so technically, it is only accessed on the hwnd's thread but it is not called on hwnd's thread
Implement the solution in #1657 (comment), closes #1657
Run
new_window_req_handleron main thread and remove theSend + Syncrestriction on itAlso fixed:
NewWindowResponse::Createnot working if no custom protocol's registeredtauri-runtime-wry's usage ofRefCellon another thread pointed out by @sftse in Redraw Sync bounds tauri#14805