diff --git a/lib/rust/Cargo.toml b/lib/rust/Cargo.toml index 880c939e9..8f94edd4c 100644 --- a/lib/rust/Cargo.toml +++ b/lib/rust/Cargo.toml @@ -26,6 +26,7 @@ tar = "0.4" flate2 = "1" hyper-old-types = "0.11.0" sysinfo = "0.9" +webbrowser = "0.5.1" [features] api = [] @@ -37,4 +38,4 @@ listFiles = [] listDirs = [] setTitle = [] execute = [] - +open = [] diff --git a/lib/rust/src/api.rs b/lib/rust/src/api.rs index eb1ec05a3..2abe10bbe 100644 --- a/lib/rust/src/api.rs +++ b/lib/rust/src/api.rs @@ -64,6 +64,12 @@ pub fn handler(webview: &mut WebView<'_, T>, arg: &str) -> bool { error, } => { super::command::call(webview, command, args, callback, error); + }, + #[cfg(any(feature = "all-api", feature = "open"))] + Open { uri } => { + super::spawn(move || { + webbrowser::open(&uri).unwrap(); + }); } } true diff --git a/lib/rust/src/api/cmd.rs b/lib/rust/src/api/cmd.rs index 09efa7042..519ca643d 100644 --- a/lib/rust/src/api/cmd.rs +++ b/lib/rust/src/api/cmd.rs @@ -42,4 +42,6 @@ pub enum Cmd { callback: String, error: String, }, + #[cfg(any(feature = "all-api", feature = "open"))] + Open { uri: String } } diff --git a/lib/rust/src/lib.rs b/lib/rust/src/lib.rs index 57d46ba2b..7aa56685d 100644 --- a/lib/rust/src/lib.rs +++ b/lib/rust/src/lib.rs @@ -23,6 +23,16 @@ use threadpool::ThreadPool; thread_local!(static POOL: ThreadPool = ThreadPool::new(4)); +pub fn spawn () + Send + 'static>( + what: F +) { + POOL.with(|thread| { + thread.execute(move || { + what(); + }); + }); +} + pub fn run_async Result + Send + 'static>( webview: &mut WebView<'_, T>, what: F,