mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-01-31 00:35:19 +01:00
add SceneRequested event
This commit is contained in:
20
Cargo.lock
generated
20
Cargo.lock
generated
@@ -1319,7 +1319,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2342,7 +2342,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4311,7 +4311,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5839,7 +5839,7 @@ dependencies = [
|
||||
"aes-gcm",
|
||||
"aes-kw",
|
||||
"argon2",
|
||||
"base64 0.22.1",
|
||||
"base64 0.21.7",
|
||||
"bitfield",
|
||||
"block-padding",
|
||||
"blowfish",
|
||||
@@ -6419,7 +6419,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"socket2",
|
||||
"tracing",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7138,7 +7138,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys 0.4.15",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7151,7 +7151,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys 0.9.4",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -9028,7 +9028,7 @@ dependencies = [
|
||||
"getrandom 0.2.15",
|
||||
"once_cell",
|
||||
"rustix 0.38.43",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -10344,7 +10344,7 @@ version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -10976,7 +10976,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"
|
||||
|
||||
[[package]]
|
||||
name = "wry"
|
||||
version = "0.53.4"
|
||||
version = "0.53.5"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"block2 0.6.0",
|
||||
|
||||
@@ -4283,6 +4283,10 @@ fn handle_event_loop<T: UserEvent>(
|
||||
} => callback(RunEvent::Reopen {
|
||||
has_visible_windows,
|
||||
}),
|
||||
#[cfg(target_os = "ios")]
|
||||
Event::SceneRequested { scene, options } => {
|
||||
callback(RunEvent::SceneRequested { scene, options });
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,6 +238,20 @@ pub enum RunEvent<T: UserEvent> {
|
||||
},
|
||||
/// A custom event defined by the user.
|
||||
UserEvent(T),
|
||||
/// Emitted when a scene is requested by the system.
|
||||
///
|
||||
/// This event is emitted when a scene is requested by the system.
|
||||
/// Scenes created by [`Window::new`] are not emitted with this event.
|
||||
/// It is also not emitted for the main scene.
|
||||
#[cfg(target_os = "ios")]
|
||||
SceneRequested {
|
||||
/// Scene that was requested by the system.
|
||||
scene: objc2::rc::Retained<objc2_ui_kit::UIScene>,
|
||||
/// Options that were used to request the scene.
|
||||
///
|
||||
/// This lets you determine why the scene was requested.
|
||||
options: objc2::rc::Retained<objc2_ui_kit::UISceneConnectionOptions>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Action to take when the event loop is about to exit
|
||||
|
||||
@@ -252,6 +252,20 @@ pub enum RunEvent {
|
||||
/// Indicates whether the NSApplication object found any visible windows in your application.
|
||||
has_visible_windows: bool,
|
||||
},
|
||||
/// Emitted when a scene is requested by the system.
|
||||
///
|
||||
/// This event is emitted when a scene is requested by the system.
|
||||
/// Scenes created by [`Window::new`] are not emitted with this event.
|
||||
/// It is also not emitted for the main scene.
|
||||
#[cfg(target_os = "ios")]
|
||||
SceneRequested {
|
||||
/// Scene that was requested by the system.
|
||||
scene: objc2::rc::Retained<objc2_ui_kit::UIScene>,
|
||||
/// Options that were used to request the scene.
|
||||
///
|
||||
/// This lets you determine why the scene was requested.
|
||||
options: objc2::rc::Retained<objc2_ui_kit::UISceneConnectionOptions>,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<EventLoopMessage> for RunEvent {
|
||||
@@ -2505,6 +2519,10 @@ fn on_event_loop_event<R: Runtime>(
|
||||
} => RunEvent::Reopen {
|
||||
has_visible_windows,
|
||||
},
|
||||
#[cfg(target_os = "ios")]
|
||||
RuntimeRunEvent::SceneRequested { scene, options } => {
|
||||
RunEvent::SceneRequested { scene, options }
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ pub fn run_app<R: Runtime, F: FnOnce(&App<R>) + Send + 'static>(
|
||||
|
||||
let number = created_window_count.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
|
||||
let builder = tauri::WebviewWindowBuilder::new(
|
||||
let builder = WebviewWindowBuilder::new(
|
||||
&app_,
|
||||
format!("new-{number}"),
|
||||
tauri::WebviewUrl::External("about:blank".parse().unwrap()),
|
||||
@@ -181,9 +181,12 @@ pub fn run_app<R: Runtime, F: FnOnce(&App<R>) + Send + 'static>(
|
||||
#[cfg(target_os = "macos")]
|
||||
app.set_activation_policy(tauri::ActivationPolicy::Regular);
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
let mut counter = 0;
|
||||
app.run(move |_app_handle, _event| {
|
||||
#[cfg(all(desktop, not(test)))]
|
||||
#[cfg(not(test))]
|
||||
match &_event {
|
||||
#[cfg(desktop)]
|
||||
RunEvent::ExitRequested { api, code, .. } => {
|
||||
// Keep the event loop running even if all windows are closed
|
||||
// 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>(
|
||||
api.prevent_exit();
|
||||
}
|
||||
}
|
||||
#[cfg(desktop)]
|
||||
RunEvent::WindowEvent {
|
||||
event: tauri::WindowEvent::CloseRequested { api, .. },
|
||||
label,
|
||||
@@ -207,6 +211,17 @@ pub fn run_app<R: Runtime, F: FnOnce(&App<R>) + Send + 'static>(
|
||||
.destroy()
|
||||
.unwrap();
|
||||
}
|
||||
#[cfg(target_os = "ios")]
|
||||
RunEvent::SceneRequested { .. } => {
|
||||
counter += 1;
|
||||
WebviewWindowBuilder::new(
|
||||
_app_handle,
|
||||
format!("main-from-scene-{counter}"),
|
||||
WebviewUrl::default(),
|
||||
)
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user