mod.rs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. //! Internal runtime between Tauri and the underlying webview runtime.
  5. use crate::{
  6. runtime::window::{DetachedWindow, PendingWindow},
  7. Icon, Params, WindowBuilder,
  8. };
  9. pub(crate) mod app;
  10. pub mod flavors;
  11. pub(crate) mod manager;
  12. pub mod tag;
  13. pub mod webview;
  14. pub mod window;
  15. /// The webview runtime interface.
  16. pub trait Runtime: Sized + 'static {
  17. /// The message dispatcher.
  18. type Dispatcher: Dispatch<Runtime = Self>;
  19. /// Creates a new webview runtime.
  20. fn new() -> crate::Result<Self>;
  21. /// Create a new webview window.
  22. fn create_window<P: Params<Runtime = Self>>(
  23. &mut self,
  24. pending: PendingWindow<P>,
  25. ) -> crate::Result<DetachedWindow<P>>;
  26. /// Run the webview runtime.
  27. fn run(self);
  28. }
  29. /// Webview dispatcher. A thread-safe handle to the webview API.
  30. pub trait Dispatch: Clone + Send + Sized + 'static {
  31. /// The runtime this [`Dispatch`] runs under.
  32. type Runtime: Runtime;
  33. /// The winoow builder type.
  34. type WindowBuilder: WindowBuilder + Clone;
  35. /// Run a task on the main thread.
  36. fn run_on_main_thread<F: FnOnce() + Send + 'static>(&self, f: F) -> crate::Result<()>;
  37. /// Create a new webview window.
  38. fn create_window<P: Params<Runtime = Self::Runtime>>(
  39. &mut self,
  40. pending: PendingWindow<P>,
  41. ) -> crate::Result<DetachedWindow<P>>;
  42. /// Updates the window resizable flag.
  43. fn set_resizable(&self, resizable: bool) -> crate::Result<()>;
  44. /// Updates the window title.
  45. fn set_title<S: Into<String>>(&self, title: S) -> crate::Result<()>;
  46. /// Maximizes the window.
  47. fn maximize(&self) -> crate::Result<()>;
  48. /// Unmaximizes the window.
  49. fn unmaximize(&self) -> crate::Result<()>;
  50. /// Minimizes the window.
  51. fn minimize(&self) -> crate::Result<()>;
  52. /// Unminimizes the window.
  53. fn unminimize(&self) -> crate::Result<()>;
  54. /// Shows the window.
  55. fn show(&self) -> crate::Result<()>;
  56. /// Hides the window.
  57. fn hide(&self) -> crate::Result<()>;
  58. /// Closes the window.
  59. fn close(&self) -> crate::Result<()>;
  60. /// Updates the hasDecorations flag.
  61. fn set_decorations(&self, decorations: bool) -> crate::Result<()>;
  62. /// Updates the window alwaysOnTop flag.
  63. fn set_always_on_top(&self, always_on_top: bool) -> crate::Result<()>;
  64. /// Updates the window width.
  65. fn set_width(&self, width: f64) -> crate::Result<()>;
  66. /// Updates the window height.
  67. fn set_height(&self, height: f64) -> crate::Result<()>;
  68. /// Resizes the window.
  69. fn resize(&self, width: f64, height: f64) -> crate::Result<()>;
  70. /// Updates the window min size.
  71. fn set_min_size(&self, min_width: f64, min_height: f64) -> crate::Result<()>;
  72. /// Updates the window max size.
  73. fn set_max_size(&self, max_width: f64, max_height: f64) -> crate::Result<()>;
  74. /// Updates the X position.
  75. fn set_x(&self, x: f64) -> crate::Result<()>;
  76. /// Updates the Y position.
  77. fn set_y(&self, y: f64) -> crate::Result<()>;
  78. /// Updates the window position.
  79. fn set_position(&self, x: f64, y: f64) -> crate::Result<()>;
  80. /// Updates the window fullscreen state.
  81. fn set_fullscreen(&self, fullscreen: bool) -> crate::Result<()>;
  82. /// Updates the window icon.
  83. fn set_icon(&self, icon: Icon) -> crate::Result<()>;
  84. /// Starts dragging the window.
  85. fn start_dragging(&self) -> crate::Result<()>;
  86. /// Executes javascript on the window this [`Dispatch`] represents.
  87. fn eval_script<S: Into<String>>(&self, script: S) -> crate::Result<()>;
  88. }