feat(lib) open link command (#10)

This commit is contained in:
Lucas Fernandes Nogueira 2019-07-24 19:44:05 -03:00 committed by GitHub
parent a1c46cd86f
commit 32b2e951be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 1 deletions

View File

@ -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 = []

View File

@ -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

View File

@ -42,4 +42,6 @@ pub enum Cmd {
callback: String,
error: String,
},
#[cfg(any(feature = "all-api", feature = "open"))]
Open { uri: String }
}

View File

@ -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,