11// Copyright 2021-2025 Tauri Programme within The Commons Conservancy
22// SPDX-License-Identifier: Apache-2.0
33
4- use objc2:: { define_class, rc:: Retained , MainThreadOnly } ;
4+ use objc2:: { define_class, rc:: Retained , MainThreadMarker , MainThreadOnly } ;
55use objc2_foundation:: {
66 NSBundle , NSDictionary , NSError , NSNumber , NSObject , NSObjectProtocol , NSSet , NSString ,
77 NSUserActivity ,
88} ;
99use objc2_ui_kit:: {
10- UIOpenURLContext , UIScene , UISceneConnectionOptions , UISceneDelegate , UISceneSession ,
11- UIWindowScene ,
10+ UIApplication , UIOpenURLContext , UIScene , UISceneConnectionOptions , UISceneDelegate ,
11+ UISceneSession , UIWindowScene ,
1212} ;
1313
1414use crate :: {
1515 event:: { Event , WindowEvent } ,
16- platform_impl:: platform:: { app_state, event_loop:: EventWrapper , ffi :: id } ,
16+ platform_impl:: platform:: { app_state, event_loop:: EventWrapper } ,
1717 window:: WindowId as RootWindowId ,
1818} ;
1919
20+ // true when the system allows the app to display multiple scenes and multiple_scenes_enabled() returns true
21+ // https://developer.apple.com/documentation/uikit/uiapplication/supportsmultiplescenes?language=objc
2022pub unsafe fn app_supports_multiple_scenes ( ) -> bool {
21- let application: id = msg_send ! [ class!( UIApplication ) , sharedApplication] ;
22- // this function can be called before the UIApplication is set up (class delegate registration)
23- if application == std:: ptr:: null_mut ( ) {
24- let bundle = NSBundle :: mainBundle ( ) ;
25- let Some ( info) = bundle. infoDictionary ( ) else {
26- return false ;
27- } ;
28-
29- let key = NSString :: from_str ( "UIApplicationSceneManifest" ) ;
30- let Some ( manifest) = ( * info) . objectForKey ( & key) else {
31- return false ;
32- } ;
33-
34- let manifest_dict = Retained :: cast_unchecked :: < NSDictionary < NSString , NSObject > > ( manifest) ;
35- let supports_key = NSString :: from_str ( "UIApplicationSupportsMultipleScenes" ) ;
36- let Some ( value) = ( * manifest_dict) . objectForKey ( & supports_key) else {
37- return false ;
38- } ;
39-
40- let num = Retained :: cast_unchecked :: < NSNumber > ( value) ;
41- ( * num) . as_bool ( )
42- } else {
43- msg_send ! [ application, supportsMultipleScenes]
44- }
23+ let mtm = MainThreadMarker :: new ( ) . unwrap ( ) ;
24+ let application = UIApplication :: sharedApplication ( mtm) ;
25+ application. supportsMultipleScenes ( )
26+ }
27+
28+ // check whether the app's Info.plist enabled multiple scenes
29+ pub unsafe fn multiple_scenes_enabled ( ) -> bool {
30+ let bundle = NSBundle :: mainBundle ( ) ;
31+ let Some ( info) = bundle. infoDictionary ( ) else {
32+ return false ;
33+ } ;
34+
35+ let key = NSString :: from_str ( "UIApplicationSceneManifest" ) ;
36+ let Some ( manifest) = ( * info) . objectForKey ( & key) else {
37+ return false ;
38+ } ;
39+
40+ let manifest_dict = Retained :: cast_unchecked :: < NSDictionary < NSString , NSObject > > ( manifest) ;
41+ let supports_key = NSString :: from_str ( "UIApplicationSupportsMultipleScenes" ) ;
42+ let Some ( value) = ( * manifest_dict) . objectForKey ( & supports_key) else {
43+ return false ;
44+ } ;
45+
46+ let num = Retained :: cast_unchecked :: < NSNumber > ( value) ;
47+ ( * num) . as_bool ( )
4548}
4649
4750define_class ! (
@@ -131,7 +134,6 @@ define_class!(
131134 & self ,
132135 _scene: & UIScene ,
133136 ) -> Option <std:: ptr:: NonNull <NSUserActivity >> {
134- log:: info!( "scene erstore" ) ;
135137 None
136138 }
137139
@@ -141,7 +143,6 @@ define_class!(
141143 _scene: & UIScene ,
142144 _state_restoration_activity: & NSUserActivity ,
143145 ) {
144- log:: info!( "scene erstorasdasdsade" ) ;
145146 }
146147
147148 #[ unsafe ( method( scene: willContinueUserActivityWithType: ) ) ]
@@ -150,13 +151,10 @@ define_class!(
150151 _scene: & UIScene ,
151152 _user_activity_type: & NSString ,
152153 ) {
153- log:: info!( "scene erstore ytype" ) ;
154154 }
155155
156156 #[ unsafe ( method( scene: continueUserActivity: ) ) ]
157- fn scene_continueUserActivity( & self , _scene: & UIScene , _user_activity: & NSUserActivity ) {
158- log:: info!( "scene continue" ) ;
159- }
157+ fn scene_continueUserActivity( & self , _scene: & UIScene , _user_activity: & NSUserActivity ) { }
160158
161159 #[ unsafe ( method( scene: didFailToContinueUserActivityWithType: error: ) ) ]
162160 fn scene_didFailToContinueUserActivityWithType_error(
@@ -165,12 +163,9 @@ define_class!(
165163 _user_activity_type: & NSString ,
166164 _error: & NSError ,
167165 ) {
168- log:: info!( "scene fail" ) ;
169166 }
170167
171168 #[ unsafe ( method( scene: didUpdateUserActivity: ) ) ]
172- fn scene_didUpdateUserActivity( & self , _scene: & UIScene , _user_activity: & NSUserActivity ) {
173- log:: info!( "scene updated" ) ;
174- }
169+ fn scene_didUpdateUserActivity( & self , _scene: & UIScene , _user_activity: & NSUserActivity ) { }
175170 }
176171) ;
0 commit comments