Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window and webview commands are all async functions #12032

Open
Legend-Master opened this issue Dec 23, 2024 · 0 comments
Open

Window and webview commands are all async functions #12032

Legend-Master opened this issue Dec 23, 2024 · 0 comments

Comments

@Legend-Master
Copy link
Contributor

Legend-Master commented Dec 23, 2024

Most of if not all of window and webview commands are sending the command to main thread and handled there, adding an async layer on top of it feels wrong to me, also this increases the binary size by 300-400 KB (tested with release build of helloworld example on Windows 3.60MB -> 3.96MB)

macro_rules! getter {
($cmd: ident, $ret: ty) => {
#[command(root = "crate")]
pub async fn $cmd<R: Runtime>(
window: Window<R>,
label: Option<String>,
) -> crate::Result<$ret> {
get_window(window, label)?.$cmd().map_err(Into::into)
}
};
}
macro_rules! setter {
($cmd: ident) => {
#[command(root = "crate")]
pub async fn $cmd<R: Runtime>(window: Window<R>, label: Option<String>) -> crate::Result<()> {
get_window(window, label)?.$cmd().map_err(Into::into)
}
};
($cmd: ident, $input: ty) => {
#[command(root = "crate")]
pub async fn $cmd<R: Runtime>(
window: Window<R>,
label: Option<String>,
value: $input,
) -> crate::Result<()> {
get_window(window, label)?.$cmd(value).map_err(Into::into)
}
};
}

I wonder why we did this, since pretty much everything else uses normal functions

I'm aware of the dead lock I mentioned in #10210 (comment), if that's the reason we did this, I feel like probably should fix that instead

Edit: did a bit more digging, seems like the dead lock is caused by us locking the plugins for invoking commands, and during the invoke, the command sends an event to the event loop synchronously and the event handler also needs to lock plugins for the event listeners, not sure why on_event and extend_api take mut self though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant