feat: improve DX of events (#12)
* feat: improve DX of events * Update global_shortcut.rs * Update event.rs * deploy docs to gh pages * Delete rustdoc.yml * add tests for global shortcut * improve logs produced by tauri_log * wip docs * update docs * move error to separate module * feat: simplify functions returning array backed iterators * rebase and cleanup * fixes
This commit is contained in:
parent
300fe18d22
commit
e28a0bb749
18 changed files with 655 additions and 289 deletions
31
examples/test/src/global_shortcut.rs
Normal file
31
examples/test/src/global_shortcut.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use futures::StreamExt;
|
||||
use tauri_sys::global_shortcut;
|
||||
|
||||
pub async fn register_all() -> anyhow::Result<()> {
|
||||
let task = async {
|
||||
let shortcuts = ["CommandOrControl+Shift+C", "Ctrl+Alt+F12"];
|
||||
|
||||
let streams = futures::future::try_join_all(shortcuts.map(|s| async move {
|
||||
let stream = global_shortcut::register(s).await?;
|
||||
|
||||
anyhow::Ok(stream.map(move |_| s))
|
||||
}))
|
||||
.await?;
|
||||
|
||||
let mut events = futures::stream::select_all(streams);
|
||||
|
||||
while let Some(shortcut) = events.next().await {
|
||||
log::debug!("Shortcut {} triggered", shortcut)
|
||||
}
|
||||
|
||||
anyhow::Ok(())
|
||||
};
|
||||
|
||||
let timeout = gloo_timers::future::sleep(Duration::from_secs(20));
|
||||
|
||||
futures::future::select(Box::pin(task), timeout).await;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue