add supports_multiple_windows API

This commit is contained in:
Lucas Nogueira
2025-12-02 10:01:18 -03:00
parent 7f953fceb2
commit 7f02cf5863
7 changed files with 108 additions and 13 deletions

22
Cargo.lock generated
View File

@@ -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.52.0",
]
[[package]]
@@ -2348,7 +2348,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]]
@@ -5848,7 +5848,7 @@ dependencies = [
"aes-gcm",
"aes-kw",
"argon2",
"base64 0.22.1",
"base64 0.21.7",
"bitfield",
"block-padding",
"blowfish",
@@ -6428,7 +6428,7 @@ dependencies = [
"once_cell",
"socket2",
"tracing",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@@ -7147,7 +7147,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.4.15",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@@ -7160,7 +7160,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.9.4",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@@ -8444,7 +8444,7 @@ dependencies = [
[[package]]
name = "tao"
version = "0.34.5"
source = "git+https://github.com/tauri-apps/tao?branch=feat/mobile-multi-window#e07caa1ea2edf0a8a675fadc53f301a66aa60900"
source = "git+https://github.com/tauri-apps/tao?branch=feat/mobile-multi-window#fb52c343d759521dbf9277bf8257b1323b2077a0"
dependencies = [
"bitflags 2.7.0",
"block2 0.6.0",
@@ -8494,7 +8494,7 @@ dependencies = [
[[package]]
name = "tao-macros"
version = "0.1.3"
source = "git+https://github.com/tauri-apps/tao?branch=feat/mobile-multi-window#e07caa1ea2edf0a8a675fadc53f301a66aa60900"
source = "git+https://github.com/tauri-apps/tao?branch=feat/mobile-multi-window#fb52c343d759521dbf9277bf8257b1323b2077a0"
dependencies = [
"proc-macro2",
"quote",
@@ -9040,7 +9040,7 @@ dependencies = [
"getrandom 0.2.15",
"once_cell",
"rustix 0.38.43",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@@ -10356,7 +10356,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.52.0",
]
[[package]]
@@ -10989,7 +10989,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"
[[package]]
name = "wry"
version = "0.53.5"
source = "git+https://github.com/tauri-apps/wry?branch=feat/mobile-multi-webview#5861318d87e8ac3b71ec7aae64df931923bbbc39"
source = "git+https://github.com/tauri-apps/wry?branch=feat/mobile-multi-webview#8d8836116aaaef271775e2958f3e38c4b5d18b04"
dependencies = [
"base64 0.22.1",
"block2 0.6.0",

View File

@@ -168,6 +168,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
("bundle_type", true),
("register_listener", true),
("remove_listener", true),
("supports_multiple_windows", true),
],
),
(

View File

@@ -11,6 +11,7 @@ Default permissions for the plugin.
- `allow-bundle-type`
- `allow-register-listener`
- `allow-remove-listener`
- `allow-supports-multiple-windows`
## Permission Table
@@ -336,6 +337,32 @@ Denies the set_dock_visibility command without any pre-configured scope.
<tr>
<td>
`core:app:allow-supports-multiple-windows`
</td>
<td>
Enables the supports_multiple_windows command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`core:app:deny-supports-multiple-windows`
</td>
<td>
Denies the supports_multiple_windows command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`core:app:allow-tauri-version`
</td>

File diff suppressed because one or more lines are too long

View File

@@ -648,6 +648,18 @@ impl<R: Runtime> AppHandle<R> {
pub fn set_device_event_filter(&self, filter: DeviceEventFilter) {
self.runtime_handle.set_device_event_filter(filter);
}
/// Whether the application supports multiple windows.
#[cfg(target_os = "ios")]
pub fn supports_multiple_windows(&self) -> bool {
let (tx, rx) = std::sync::mpsc::channel();
self.run_on_main_thread(move || unsafe {
let mtm = objc2::MainThreadMarker::new().unwrap();
let ui_application = objc2_ui_kit::UIApplication::sharedApplication(mtm);
tx.send(ui_application.supportsMultipleScenes()).unwrap();
});
rx.recv().unwrap()
}
}
impl<R: Runtime> Manager<R> for AppHandle<R> {
@@ -1081,6 +1093,40 @@ macro_rules! shared_app_impl {
pub fn invoke_key(&self) -> &str {
self.manager.invoke_key()
}
/// Whether the application supports multiple windows.
#[cfg(desktop)]
pub fn supports_multiple_windows(&self) -> bool {
true
}
/// Whether the application supports multiple windows.
#[cfg(target_os = "android")]
pub fn supports_multiple_windows(&self) -> bool {
let runtime_handle = match self.runtime() {
RuntimeOrDispatch::Runtime(runtime) => runtime.handle(),
RuntimeOrDispatch::RuntimeHandle(handle) => handle,
_ => unreachable!(),
};
let (tx, rx) = std::sync::mpsc::channel();
runtime_handle.run_on_android_context(move |env, _activity, _webview| {
let supports = (|| {
let version_class = env.find_class("android/os/Build$VERSION")?;
let sdk = env
.get_static_field(version_class, "SDK_INT", "I")?
.i()
.unwrap_or_default();
crate::Result::Ok(sdk >= 32)
})()
.unwrap_or(false);
let _ = tx.send(supports);
});
rx.recv().unwrap_or(false)
}
}
impl<R: Runtime> Listener<R> for $app {
@@ -1180,6 +1226,16 @@ impl<R: Runtime> App<R> {
&self.handle
}
/// Whether the application supports multiple windows.
#[cfg(target_os = "ios")]
pub fn supports_multiple_windows(&self) -> bool {
unsafe {
let mtm = objc2::MainThreadMarker::new().unwrap();
let ui_application = objc2_ui_kit::UIApplication::sharedApplication(mtm);
ui_application.supportsMultipleScenes()
}
}
/// Sets the activation policy for the application. It is set to `NSApplicationActivationPolicyRegular` by default.
///
/// # Examples

View File

@@ -115,6 +115,11 @@ pub fn bundle_type() -> Option<BundleType> {
tauri_utils::platform::bundle_type()
}
#[command(root = "crate")]
pub fn supports_multiple_windows<R: Runtime>(app: AppHandle<R>) -> bool {
app.supports_multiple_windows()
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("app")
.invoke_handler(crate::generate_handler![
@@ -131,6 +136,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
set_app_theme,
set_dock_visibility,
bundle_type,
supports_multiple_windows,
])
.setup(|_app, _api| {
#[cfg(target_os = "android")]

View File

@@ -274,6 +274,10 @@ async function onBackButtonPress(
)
}
async function supportsMultipleWindows(): Promise<boolean> {
return invoke('plugin:app|supports_multiple_windows')
}
export {
getName,
getVersion,
@@ -288,5 +292,6 @@ export {
setDockVisibility,
getBundleType,
type OnBackButtonPressPayload,
onBackButtonPress
onBackButtonPress,
supportsMultipleWindows
}