|
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 | // SPDX-License-Identifier: MIT |
4 | 4 |
|
| 5 | +// we re-export the default_args! macro as pub(crate) so we can use it easily from other modules |
| 6 | +#![allow(clippy::single_component_path_imports)] |
| 7 | + |
5 | 8 | use crate::{ |
6 | 9 | api::{ |
7 | 10 | assets::Assets, |
@@ -71,41 +74,78 @@ pub(crate) fn tauri_event<Event: Tag>(tauri_event: &str) -> Event { |
71 | 74 | }) |
72 | 75 | } |
73 | 76 |
|
74 | | -pub struct InnerWindowManager<P: Params = DefaultArgs> { |
75 | | - windows: Mutex<HashMap<P::Label, Window<P>>>, |
76 | | - plugins: Mutex<PluginStore<P>>, |
77 | | - listeners: Listeners<P::Event, P::Label>, |
78 | | - pub(crate) state: Arc<StateManager>, |
| 77 | +crate::manager::default_args! { |
| 78 | + pub struct InnerWindowManager<P: Params> { |
| 79 | + windows: Mutex<HashMap<P::Label, Window<P>>>, |
| 80 | + plugins: Mutex<PluginStore<P>>, |
| 81 | + listeners: Listeners<P::Event, P::Label>, |
| 82 | + pub(crate) state: Arc<StateManager>, |
79 | 83 |
|
80 | | - /// The JS message handler. |
81 | | - invoke_handler: Box<InvokeHandler<P>>, |
| 84 | + /// The JS message handler. |
| 85 | + invoke_handler: Box<InvokeHandler<P>>, |
82 | 86 |
|
83 | | - /// The page load hook, invoked when the webview performs a navigation. |
84 | | - on_page_load: Box<OnPageLoad<P>>, |
| 87 | + /// The page load hook, invoked when the webview performs a navigation. |
| 88 | + on_page_load: Box<OnPageLoad<P>>, |
85 | 89 |
|
86 | | - config: Arc<Config>, |
87 | | - assets: Arc<P::Assets>, |
88 | | - default_window_icon: Option<Vec<u8>>, |
| 90 | + config: Arc<Config>, |
| 91 | + assets: Arc<P::Assets>, |
| 92 | + default_window_icon: Option<Vec<u8>>, |
89 | 93 |
|
90 | | - /// A list of salts that are valid for the current application. |
91 | | - salts: Mutex<HashSet<Uuid>>, |
92 | | - package_info: PackageInfo, |
93 | | - /// The webview protocols protocols available to all windows. |
94 | | - uri_scheme_protocols: HashMap<String, Arc<CustomProtocol>>, |
95 | | - /// The menu set to all windows. |
96 | | - #[cfg(feature = "menu")] |
97 | | - menu: Vec<Menu<P::MenuId>>, |
98 | | - /// Maps runtime id to a strongly typed menu id. |
99 | | - #[cfg(feature = "menu")] |
100 | | - menu_ids: HashMap<u32, P::MenuId>, |
101 | | - /// Menu event listeners to all windows. |
102 | | - #[cfg(feature = "menu")] |
103 | | - menu_event_listeners: Arc<Vec<GlobalMenuEventListener<P>>>, |
104 | | - /// Window event listeners to all windows. |
105 | | - window_event_listeners: Arc<Vec<GlobalWindowEventListener<P>>>, |
| 94 | + /// A list of salts that are valid for the current application. |
| 95 | + salts: Mutex<HashSet<Uuid>>, |
| 96 | + package_info: PackageInfo, |
| 97 | + /// The webview protocols protocols available to all windows. |
| 98 | + uri_scheme_protocols: HashMap<String, Arc<CustomProtocol>>, |
| 99 | + /// The menu set to all windows. |
| 100 | + #[cfg(feature = "menu")] |
| 101 | + menu: Vec<Menu<P::MenuId>>, |
| 102 | + /// Maps runtime id to a strongly typed menu id. |
| 103 | + #[cfg(feature = "menu")] |
| 104 | + menu_ids: HashMap<u32, P::MenuId>, |
| 105 | + /// Menu event listeners to all windows. |
| 106 | + #[cfg(feature = "menu")] |
| 107 | + menu_event_listeners: Arc<Vec<GlobalMenuEventListener<P>>>, |
| 108 | + /// Window event listeners to all windows. |
| 109 | + window_event_listeners: Arc<Vec<GlobalWindowEventListener<P>>>, |
| 110 | + } |
106 | 111 | } |
107 | 112 |
|
| 113 | +/// struct declaration using params + default args which includes optional feature wry |
| 114 | +macro_rules! default_args { |
| 115 | + ( |
| 116 | + $(#[$attrs_struct:meta])* |
| 117 | + $vis_struct:vis struct $name:ident<$p:ident: $params:ident> { |
| 118 | + $( |
| 119 | + $(#[$attrs_field:meta])* |
| 120 | + $vis_field:vis $field:ident: $field_type:ty, |
| 121 | + )* |
| 122 | + } |
| 123 | + ) => { |
| 124 | + $(#[$attrs_struct])* |
| 125 | + #[cfg(feature = "wry")] |
| 126 | + $vis_struct struct $name<$p: $params = crate::manager::DefaultArgs> { |
| 127 | + $( |
| 128 | + $(#[$attrs_field])* |
| 129 | + $vis_field $field: $field_type, |
| 130 | + )* |
| 131 | + } |
| 132 | + |
| 133 | + $(#[$attrs_struct])* |
| 134 | + #[cfg(not(feature = "wry"))] |
| 135 | + $vis_struct struct $name<$p: $params> { |
| 136 | + $( |
| 137 | + $(#[$attrs_field])* |
| 138 | + $vis_field $field: $field_type, |
| 139 | + )* |
| 140 | + } |
| 141 | + }; |
| 142 | +} |
| 143 | + |
| 144 | +// export it to allow use from other modules |
| 145 | +pub(crate) use default_args; |
| 146 | + |
108 | 147 | /// This type should always match `Builder::default()`, otherwise the default type is useless. |
| 148 | +#[cfg(feature = "wry")] |
109 | 149 | pub(crate) type DefaultArgs = |
110 | 150 | Args<String, String, String, String, crate::api::assets::EmbeddedAssets, crate::Wry>; |
111 | 151 |
|
@@ -151,10 +191,12 @@ impl<E: Tag, L: Tag, MID: MenuId, TID: MenuId, A: Assets, R: Runtime> Params |
151 | 191 | type Runtime = R; |
152 | 192 | } |
153 | 193 |
|
154 | | -pub struct WindowManager<P: Params = DefaultArgs> { |
155 | | - pub inner: Arc<InnerWindowManager<P>>, |
156 | | - #[allow(clippy::type_complexity)] |
157 | | - _marker: Args<P::Event, P::Label, P::MenuId, P::SystemTrayMenuId, P::Assets, P::Runtime>, |
| 194 | +crate::manager::default_args! { |
| 195 | + pub struct WindowManager<P: Params> { |
| 196 | + pub inner: Arc<InnerWindowManager<P>>, |
| 197 | + #[allow(clippy::type_complexity)] |
| 198 | + _marker: Args<P::Event, P::Label, P::MenuId, P::SystemTrayMenuId, P::Assets, P::Runtime>, |
| 199 | + } |
158 | 200 | } |
159 | 201 |
|
160 | 202 | impl<P: Params> Clone for WindowManager<P> { |
|
0 commit comments