mod.rs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. //! The Tauri API interface.
  5. #![warn(missing_docs)]
  6. // #![feature(const_int_pow)]
  7. /// The App API module allows you to manage application processes.
  8. pub mod app;
  9. /// The Command API module allows you to manage child processes.
  10. pub mod command;
  11. /// The Dialog API module allows you to show messages and prompt for file paths.
  12. pub mod dialog;
  13. /// The Dir module is a helper for file system directory management.
  14. pub mod dir;
  15. /// The File API module contains helpers to perform file operations.
  16. pub mod file;
  17. /// The HTTP request API.
  18. pub mod http;
  19. /// The file system path operations API.
  20. pub mod path;
  21. /// The RPC module includes utilities to send messages to the JS layer of the webview.
  22. pub mod rpc;
  23. /// The shell api.
  24. pub mod shell;
  25. /// TCP ports access API.
  26. pub mod tcp;
  27. /// The semver API.
  28. pub mod version;
  29. /// The Tauri config definition.
  30. pub use tauri_utils::config;
  31. /// The CLI args interface.
  32. #[cfg(feature = "cli")]
  33. pub mod cli;
  34. #[cfg(feature = "cli")]
  35. pub use clap;
  36. /// Global shortcuts interface.
  37. #[cfg(global_shortcut_all)]
  38. pub mod shortcuts;
  39. /// The desktop notifications API module.
  40. #[cfg(notification_all)]
  41. pub mod notification;
  42. pub use tauri_utils::*;
  43. mod error;
  44. /// Tauri API error.
  45. pub use error::Error;
  46. /// Tauri API result type.
  47. pub type Result<T> = std::result::Result<T, Error>;
  48. /// `App` package information.
  49. #[derive(Debug, Clone)]
  50. pub struct PackageInfo {
  51. /// App name.
  52. pub name: &'static str,
  53. /// App version.
  54. pub version: &'static str,
  55. }
  56. // Not public API
  57. #[doc(hidden)]
  58. pub mod private {
  59. // Core API only.
  60. pub mod async_runtime {
  61. use once_cell::sync::OnceCell;
  62. use tokio::runtime::Runtime;
  63. pub use tokio::sync::{
  64. mpsc::{channel, Receiver, Sender},
  65. Mutex,
  66. };
  67. use std::future::Future;
  68. static RUNTIME: OnceCell<Runtime> = OnceCell::new();
  69. pub fn block_on<F: Future>(task: F) -> F::Output {
  70. let runtime = RUNTIME.get_or_init(|| Runtime::new().unwrap());
  71. runtime.block_on(task)
  72. }
  73. pub fn spawn<F>(task: F)
  74. where
  75. F: Future + Send + 'static,
  76. F::Output: Send + 'static,
  77. {
  78. let runtime = RUNTIME.get_or_init(|| Runtime::new().unwrap());
  79. runtime.spawn(task);
  80. }
  81. }
  82. pub use once_cell::sync::OnceCell;
  83. pub trait AsTauriContext {
  84. fn config() -> &'static crate::api::config::Config;
  85. fn assets() -> &'static crate::api::assets::EmbeddedAssets;
  86. fn default_window_icon() -> Option<&'static [u8]>;
  87. fn package_info() -> crate::api::PackageInfo;
  88. }
  89. }