mirror of https://github.com/tauri-apps/tauri
feat(lib) open link command (#10)
This commit is contained in:
parent
a1c46cd86f
commit
32b2e951be
|
@ -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 = []
|
||||
|
|
|
@ -64,6 +64,12 @@ pub fn handler<T: 'static>(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
|
||||
|
|
|
@ -42,4 +42,6 @@ pub enum Cmd {
|
|||
callback: String,
|
||||
error: String,
|
||||
},
|
||||
#[cfg(any(feature = "all-api", feature = "open"))]
|
||||
Open { uri: String }
|
||||
}
|
||||
|
|
|
@ -23,6 +23,16 @@ use threadpool::ThreadPool;
|
|||
|
||||
thread_local!(static POOL: ThreadPool = ThreadPool::new(4));
|
||||
|
||||
pub fn spawn<F: FnOnce() -> () + Send + 'static>(
|
||||
what: F
|
||||
) {
|
||||
POOL.with(|thread| {
|
||||
thread.execute(move || {
|
||||
what();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn run_async<T: 'static, F: FnOnce() -> Result<String, String> + Send + 'static>(
|
||||
webview: &mut WebView<'_, T>,
|
||||
what: F,
|
||||
|
|
Loading…
Reference in New Issue