lib.rs 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. use tauri::{
  5. plugin::{Builder, TauriPlugin},
  6. Manager, Runtime,
  7. };
  8. pub use models::*;
  9. #[cfg(desktop)]
  10. mod desktop;
  11. #[cfg(mobile)]
  12. mod mobile;
  13. mod error;
  14. mod models;
  15. #[cfg(desktop)]
  16. use desktop::Sample;
  17. #[cfg(mobile)]
  18. use mobile::Sample;
  19. pub use error::*;
  20. /// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the sample APIs.
  21. pub trait SampleExt<R: Runtime> {
  22. fn sample(&self) -> &Sample<R>;
  23. }
  24. impl<R: Runtime, T: Manager<R>> crate::SampleExt<R> for T {
  25. fn sample(&self) -> &Sample<R> {
  26. self.state::<Sample<R>>().inner()
  27. }
  28. }
  29. pub fn init<R: Runtime>() -> TauriPlugin<R> {
  30. Builder::new("sample")
  31. .setup(|app, api| {
  32. #[cfg(mobile)]
  33. let sample = mobile::init(app, api)?;
  34. #[cfg(desktop)]
  35. let sample = desktop::init(app, api)?;
  36. app.manage(sample);
  37. Ok(())
  38. })
  39. .build()
  40. }