1use anyhow::Result;
2use fission_core::{Action, ActionRegistry, Env, GlobalState, Widget};
3use fission_shell::async_host::AsyncRegistry;
4use fission_shell_winit::WinitApp;
5
6pub use fission_shell_winit::{
7 BarcodeScannerHost, BiometricHost, BluetoothHost, CameraHost, ClipboardHost, GeolocationHost,
8 HapticHost, MemoryBarcodeScannerHost, MemoryBiometricHost, MemoryBluetoothHost,
9 MemoryCameraHost, MemoryClipboardHost, MemoryGeolocationHost, MemoryHapticHost,
10 MemoryMicrophoneHost, MemoryNfcHost, MemoryNotificationHost, MemoryPasskeyHost,
11 MemoryVolumeHost, MemoryWifiHost, MicrophoneHost, NfcHost, NotificationHost, PasskeyHost,
12 UnsupportedBarcodeScannerHost, UnsupportedBiometricHost, UnsupportedBluetoothHost,
13 UnsupportedCameraHost, UnsupportedGeolocationHost, UnsupportedHapticHost,
14 UnsupportedMicrophoneHost, UnsupportedNfcHost, UnsupportedNotificationHost,
15 UnsupportedPasskeyHost, UnsupportedVolumeHost, UnsupportedWifiHost, VolumeHost, WifiHost,
16};
17
18pub struct WebApp<S: GlobalState, W>
19where
20 W: Clone + Into<Widget>,
21{
22 inner: WinitApp<S, W>,
23}
24
25impl<S, W> WebApp<S, W>
26where
27 S: GlobalState + Default,
28 W: Clone + Into<Widget> + 'static,
29{
30 pub fn new(root_widget: W) -> Self {
31 Self {
32 inner: WinitApp::new(root_widget),
33 }
34 }
35
36 pub fn new_with_global_state(root_widget: W, global_state: S) -> Self {
37 Self {
38 inner: WinitApp::new_with_global_state(root_widget, global_state),
39 }
40 }
41
42 pub fn with_global_state(mut self, global_state: S) -> Self {
43 self.inner = self.inner.with_global_state(global_state);
44 self
45 }
46
47 pub fn with_title(mut self, title: impl Into<String>) -> Self {
48 self.inner = self.inner.with_title(title);
49 self
50 }
51
52 pub fn with_mount_selector(mut self, selector: impl Into<String>) -> Self {
53 self.inner = self.inner.with_mount_selector(selector);
54 self
55 }
56
57 pub fn mount(self, selector: impl Into<String>) -> Self {
58 self.with_mount_selector(selector)
59 }
60
61 pub fn with_state_init<F>(mut self, init: F) -> Self
62 where
63 F: FnOnce(&mut S),
64 {
65 self.inner = self.inner.with_state_init(init);
66 self
67 }
68
69 pub fn with_startup_action<A: Action>(mut self, action: A) -> Self {
70 self.inner = self.inner.with_startup_action(action);
71 self
72 }
73
74 pub fn with_design_system<D: fission_theme::DesignSystem>(
75 mut self,
76 mode: fission_theme::DesignMode,
77 ) -> Self {
78 self.inner = self.inner.with_design_system::<D>(mode);
79 self
80 }
81
82 pub fn with_sync_env<F>(mut self, sync: F) -> Self
83 where
84 F: Fn(&S, &mut Env) + Send + Sync + 'static,
85 {
86 self.inner = self.inner.with_sync_env(sync);
87 self
88 }
89
90 pub fn with_frame_hook<F>(mut self, hook: F) -> Self
91 where
92 F: Fn(&mut S) -> bool + Send + Sync + 'static,
93 {
94 self.inner = self.inner.with_frame_hook(hook);
95 self
96 }
97
98 pub fn with_async<F>(mut self, configure: F) -> Self
99 where
100 F: FnOnce(&mut AsyncRegistry),
101 {
102 self.inner = self.inner.with_async(configure);
103 self
104 }
105
106 pub fn with_notification_host<H>(mut self, host: H) -> Self
107 where
108 H: NotificationHost,
109 {
110 self.inner = self.inner.with_notification_host(host);
111 self
112 }
113
114 pub fn with_nfc_host<H>(mut self, host: H) -> Self
115 where
116 H: NfcHost,
117 {
118 self.inner = self.inner.with_nfc_host(host);
119 self
120 }
121
122 pub fn with_biometric_host<H>(mut self, host: H) -> Self
123 where
124 H: BiometricHost,
125 {
126 self.inner = self.inner.with_biometric_host(host);
127 self
128 }
129
130 pub fn with_passkey_host<H>(mut self, host: H) -> Self
131 where
132 H: PasskeyHost,
133 {
134 self.inner = self.inner.with_passkey_host(host);
135 self
136 }
137
138 pub fn with_bluetooth_host<H>(mut self, host: H) -> Self
139 where
140 H: BluetoothHost,
141 {
142 self.inner = self.inner.with_bluetooth_host(host);
143 self
144 }
145
146 pub fn with_barcode_scanner_host<H>(mut self, host: H) -> Self
147 where
148 H: BarcodeScannerHost,
149 {
150 self.inner = self.inner.with_barcode_scanner_host(host);
151 self
152 }
153
154 pub fn with_camera_host<H>(mut self, host: H) -> Self
155 where
156 H: CameraHost,
157 {
158 self.inner = self.inner.with_camera_host(host);
159 self
160 }
161
162 pub fn with_clipboard_host<H>(mut self, host: H) -> Self
163 where
164 H: ClipboardHost,
165 {
166 self.inner = self.inner.with_clipboard_host(host);
167 self
168 }
169
170 pub fn with_geolocation_host<H>(mut self, host: H) -> Self
171 where
172 H: GeolocationHost,
173 {
174 self.inner = self.inner.with_geolocation_host(host);
175 self
176 }
177
178 pub fn with_haptic_host<H>(mut self, host: H) -> Self
179 where
180 H: HapticHost,
181 {
182 self.inner = self.inner.with_haptic_host(host);
183 self
184 }
185
186 pub fn with_microphone_host<H>(mut self, host: H) -> Self
187 where
188 H: MicrophoneHost,
189 {
190 self.inner = self.inner.with_microphone_host(host);
191 self
192 }
193
194 pub fn with_wifi_host<H>(mut self, host: H) -> Self
195 where
196 H: WifiHost,
197 {
198 self.inner = self.inner.with_wifi_host(host);
199 self
200 }
201
202 pub fn with_volume_host<H>(mut self, host: H) -> Self
203 where
204 H: VolumeHost,
205 {
206 self.inner = self.inner.with_volume_host(host);
207 self
208 }
209
210 pub fn with_deep_link_config(mut self, config: fission_core::DeepLinkConfig) -> Self {
211 self.inner = self.inner.with_deep_link_config(config);
212 self
213 }
214
215 pub fn with_deep_link_scheme(mut self, scheme: impl Into<String>) -> Self {
216 self.inner = self.inner.with_deep_link_scheme(scheme);
217 self
218 }
219
220 pub fn with_deep_link_domain(mut self, domain: impl Into<String>) -> Self {
221 self.inner = self.inner.with_deep_link_domain(domain);
222 self
223 }
224
225 pub fn with_startup_deep_link(mut self, link: fission_core::DeepLink) -> Self {
226 self.inner = self.inner.with_startup_deep_link(link);
227 self
228 }
229
230 pub fn with_startup_notification_response(
231 mut self,
232 response: fission_core::NotificationResponse,
233 ) -> Self {
234 self.inner = self.inner.with_startup_notification_response(response);
235 self
236 }
237
238 pub fn on_deep_link<H>(mut self, handler: H) -> Self
239 where
240 H: fission_core::registry::IntoHandler<S, fission_core::DeepLinkReceived>
241 + Send
242 + Sync
243 + 'static,
244 {
245 self.inner = self.inner.on_deep_link(handler);
246 self
247 }
248
249 pub fn on_notification_response<H>(mut self, handler: H) -> Self
250 where
251 H: fission_core::registry::IntoHandler<S, fission_core::NotificationResponseReceived>
252 + Send
253 + Sync
254 + 'static,
255 {
256 self.inner = self.inner.on_notification_response(handler);
257 self
258 }
259
260 pub fn absorb_registry(&mut self, registry: ActionRegistry<S>) {
261 self.inner.absorb_registry(registry);
262 }
263
264 pub fn run(self) -> Result<()> {
265 self.inner.run()
266 }
267}