lib.rs 977 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #[macro_use]
  2. extern crate serde_derive;
  3. #[macro_use]
  4. mod macros;
  5. pub mod api;
  6. pub mod command;
  7. pub mod dir;
  8. pub mod file;
  9. pub mod file_system;
  10. pub mod http;
  11. pub mod platform;
  12. pub mod process;
  13. pub mod rpc;
  14. pub mod tcp;
  15. pub mod updater;
  16. pub mod version;
  17. use proton_ui::WebView;
  18. use threadpool::ThreadPool;
  19. thread_local!(static POOL: ThreadPool = ThreadPool::new(4));
  20. pub fn spawn<F: FnOnce() -> () + Send + 'static>(
  21. what: F
  22. ) {
  23. POOL.with(|thread| {
  24. thread.execute(move || {
  25. what();
  26. });
  27. });
  28. }
  29. pub fn run_async<T: 'static, F: FnOnce() -> Result<String, String> + Send + 'static>(
  30. webview: &mut WebView<'_, T>,
  31. what: F,
  32. callback: String,
  33. error: String,
  34. ) {
  35. let handle = webview.handle();
  36. POOL.with(|thread| {
  37. thread.execute(move || {
  38. let callback_string = rpc::format_callback_result(what(), callback, error);
  39. handle
  40. .dispatch(move |_webview| _webview.eval(callback_string.as_str()))
  41. .unwrap()
  42. });
  43. });
  44. }