Skip to content

Commit f5f9b3d

Browse files
committed
add SceneRequested event
1 parent eb51b13 commit f5f9b3d

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-12
lines changed

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri-runtime-wry/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,10 @@ fn handle_event_loop<T: UserEvent>(
42834283
} => callback(RunEvent::Reopen {
42844284
has_visible_windows,
42854285
}),
4286+
#[cfg(target_os = "ios")]
4287+
Event::SceneRequested { scene, options } => {
4288+
callback(RunEvent::SceneRequested { scene, options });
4289+
}
42864290
_ => (),
42874291
}
42884292
}

crates/tauri-runtime/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,20 @@ pub enum RunEvent<T: UserEvent> {
238238
},
239239
/// A custom event defined by the user.
240240
UserEvent(T),
241+
/// Emitted when a scene is requested by the system.
242+
///
243+
/// This event is emitted when a scene is requested by the system.
244+
/// Scenes created by [`Window::new`] are not emitted with this event.
245+
/// It is also not emitted for the main scene.
246+
#[cfg(target_os = "ios")]
247+
SceneRequested {
248+
/// Scene that was requested by the system.
249+
scene: objc2::rc::Retained<objc2_ui_kit::UIScene>,
250+
/// Options that were used to request the scene.
251+
///
252+
/// This lets you determine why the scene was requested.
253+
options: objc2::rc::Retained<objc2_ui_kit::UISceneConnectionOptions>,
254+
},
241255
}
242256

243257
/// Action to take when the event loop is about to exit

crates/tauri/src/app.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,20 @@ pub enum RunEvent {
252252
/// Indicates whether the NSApplication object found any visible windows in your application.
253253
has_visible_windows: bool,
254254
},
255+
/// Emitted when a scene is requested by the system.
256+
///
257+
/// This event is emitted when a scene is requested by the system.
258+
/// Scenes created by [`Window::new`] are not emitted with this event.
259+
/// It is also not emitted for the main scene.
260+
#[cfg(target_os = "ios")]
261+
SceneRequested {
262+
/// Scene that was requested by the system.
263+
scene: objc2::rc::Retained<objc2_ui_kit::UIScene>,
264+
/// Options that were used to request the scene.
265+
///
266+
/// This lets you determine why the scene was requested.
267+
options: objc2::rc::Retained<objc2_ui_kit::UISceneConnectionOptions>,
268+
},
255269
}
256270

257271
impl From<EventLoopMessage> for RunEvent {
@@ -2505,6 +2519,10 @@ fn on_event_loop_event<R: Runtime>(
25052519
} => RunEvent::Reopen {
25062520
has_visible_windows,
25072521
},
2522+
#[cfg(target_os = "ios")]
2523+
RuntimeRunEvent::SceneRequested { scene, options } => {
2524+
RunEvent::SceneRequested { scene, options }
2525+
}
25082526
_ => unimplemented!(),
25092527
};
25102528

examples/api/src-tauri/src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn run_app<R: Runtime, F: FnOnce(&App<R>) + Send + 'static>(
8686

8787
let number = created_window_count.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
8888

89-
let builder = tauri::WebviewWindowBuilder::new(
89+
let builder = WebviewWindowBuilder::new(
9090
&app_,
9191
format!("new-{number}"),
9292
tauri::WebviewUrl::External("about:blank".parse().unwrap()),
@@ -181,9 +181,12 @@ pub fn run_app<R: Runtime, F: FnOnce(&App<R>) + Send + 'static>(
181181
#[cfg(target_os = "macos")]
182182
app.set_activation_policy(tauri::ActivationPolicy::Regular);
183183

184+
#[cfg(target_os = "ios")]
185+
let mut counter = 0;
184186
app.run(move |_app_handle, _event| {
185-
#[cfg(all(desktop, not(test)))]
187+
#[cfg(not(test))]
186188
match &_event {
189+
#[cfg(desktop)]
187190
RunEvent::ExitRequested { api, code, .. } => {
188191
// Keep the event loop running even if all windows are closed
189192
// This allow us to catch tray icon events when there is no window
@@ -192,6 +195,7 @@ pub fn run_app<R: Runtime, F: FnOnce(&App<R>) + Send + 'static>(
192195
api.prevent_exit();
193196
}
194197
}
198+
#[cfg(desktop)]
195199
RunEvent::WindowEvent {
196200
event: tauri::WindowEvent::CloseRequested { api, .. },
197201
label,
@@ -207,6 +211,17 @@ pub fn run_app<R: Runtime, F: FnOnce(&App<R>) + Send + 'static>(
207211
.destroy()
208212
.unwrap();
209213
}
214+
#[cfg(target_os = "ios")]
215+
RunEvent::SceneRequested { .. } => {
216+
counter += 1;
217+
WebviewWindowBuilder::new(
218+
_app_handle,
219+
format!("main-from-scene-{counter}"),
220+
WebviewUrl::default(),
221+
)
222+
.build()
223+
.unwrap();
224+
}
210225
_ => (),
211226
}
212227
})

0 commit comments

Comments
 (0)