@@ -46,8 +46,7 @@ public struct UIKitPlatform: PlatformProtocol, InternalPlatformProtocol {
4646 if path. hasPrefix ( " / " ) , await fileSystem. itemExists ( at: path) {
4747 return path
4848 }
49- let searchPaths =
50- Game . shared. delegate. resolvedCustomResourceLocations ( ) + staticResourceLocations
49+ let searchPaths = Game . unsafeShared. delegate. resolvedCustomResourceLocations ( ) + staticResourceLocations
5150 for searchPath in searchPaths {
5251 let file = searchPath. appendingPathComponent ( path)
5352 if await fileSystem. itemExists ( at: file. path) {
@@ -105,7 +104,7 @@ public struct UIKitPlatform: PlatformProtocol, InternalPlatformProtocol {
105104internal final class UIKitApplicationDelegate : NSObject , UIApplicationDelegate {
106105 func applicationDidFinishLaunching( _ application: UIApplication ) {
107106 Task ( priority: . high) {
108- await Game . shared . didFinishLaunching ( )
107+ await Game . unsafeShared . didFinishLaunching ( )
109108 }
110109
111110 do { // The following will silence music if a user is already playing their own music
@@ -119,11 +118,11 @@ internal final class UIKitApplicationDelegate: NSObject, UIApplicationDelegate {
119118 }
120119
121120 if session. secondaryAudioShouldBeSilencedHint {
122- if let mixer = Game . shared . audio. musicMixers [ . soundTrack] {
121+ if let mixer = Game . unsafeShared . audio. musicMixers [ . soundTrack] {
123122 mixer. volume = 0
124123 }
125124 } else {
126- if let mixer = Game . shared . audio. musicMixers [ . soundTrack] {
125+ if let mixer = Game . unsafeShared . audio. musicMixers [ . soundTrack] {
127126 mixer. volume = 1
128127 }
129128 }
@@ -136,11 +135,11 @@ internal final class UIKitApplicationDelegate: NSObject, UIApplicationDelegate {
136135 let userInfo = notification. userInfo
137136 let silenceSecondary = userInfo ? [ AVAudioSessionSilenceSecondaryAudioHintTypeKey] as? Int
138137 if silenceSecondary == 1 {
139- if let mixer = Game . shared . audio. musicMixers [ . soundTrack] {
138+ if let mixer = Game . unsafeShared . audio. musicMixers [ . soundTrack] {
140139 mixer. volume = 0
141140 }
142141 } else {
143- if let mixer = Game . shared . audio. musicMixers [ . soundTrack] {
142+ if let mixer = Game . unsafeShared . audio. musicMixers [ . soundTrack] {
144143 mixer. volume = 1
145144 }
146145 }
@@ -169,7 +168,7 @@ internal final class UIKitApplicationDelegate: NSObject, UIApplicationDelegate {
169168 }
170169
171170 func applicationWillTerminate( _ application: UIApplication ) {
172- Game . shared . willTerminate ( )
171+ Game . unsafeShared . willTerminate ( )
173172 for session in application. openSessions {
174173 application. requestSceneSessionDestruction ( session, options: nil )
175174 }
@@ -181,19 +180,11 @@ internal final class UIKitWindowSceneDelegate: NSObject, UIWindowSceneDelegate {
181180 forSession session: UISceneSession ,
182181 options connectionOptions: UIScene . ConnectionOptions
183182 ) -> UIKitWindow ? {
184- if let userActivity =
185- ( connectionOptions. userActivities. first ( where: { $0. activityType == " GateEngineWindow " }
186- ) ?? session. stateRestorationActivity)
187- {
188- if let requestedWindowIdentifier = userActivity. userInfo ? [ " WindowIdentifier " ] as? String
189- {
190- if let createdWindow = Game . shared. windowManager. window (
191- withIdentifier: requestedWindowIdentifier
192- ) {
183+ if let userActivity = ( connectionOptions. userActivities. first ( where: { $0. activityType == " GateEngineWindow " } ) ?? session. stateRestorationActivity) {
184+ if let requestedWindowIdentifier = userActivity. userInfo ? [ " WindowIdentifier " ] as? String {
185+ if let createdWindow = Game . unsafeShared. windowManager. window ( withIdentifier: requestedWindowIdentifier) {
193186 let uiKitWindow = createdWindow. windowBacking as? UIKitWindow
194- if let title = UserDefaults . standard. string (
195- forKey: " Windows/ \( createdWindow. identifier) /title "
196- ) {
187+ if let title = UserDefaults . standard. string ( forKey: " Windows/ \( createdWindow. identifier) /title " ) {
197188 createdWindow. title = title
198189 }
199190 return uiKitWindow
@@ -215,69 +206,58 @@ internal final class UIKitWindowSceneDelegate: NSObject, UIWindowSceneDelegate {
215206 ) {
216207 guard let windowScene = ( scene as? UIWindowScene ) else { return }
217208 do {
218- Game . shared. attributes. insert ( . renderingIsPermitted)
219- if let restoredWindow = attachExistingWindow (
220- forSession: session,
221- options: connectionOptions
222- ) {
209+ Game . unsafeShared. attributes. insert ( . renderingIsPermitted)
210+ if let restoredWindow = attachExistingWindow ( forSession: session, options: connectionOptions) {
223211 assert ( restoredWindow. window. isMainWindow == false )
224212 restoredWindow. uiWindow. windowScene = windowScene
225213 windowScene. title = restoredWindow. title
226214 } else if session. stateRestorationActivity != nil {
227215 UIApplication . shared. requestSceneSessionDestruction ( session, options: nil )
228- } else if Game . shared. windowManager. mainWindow == nil
229- && session. role == . windowApplication
230- {
231- let window = try Game . shared. delegate. createMainWindow (
232- using: Game . shared. windowManager,
216+ } else if Game . unsafeShared. windowManager. mainWindow == nil && session. role == . windowApplication {
217+ let window = try Game . unsafeShared. delegate. createMainWindow (
218+ using: Game . unsafeShared. windowManager,
233219 with: WindowManager . mainWindowIdentifier
234220 )
235221 let uiWindow = ( window. windowBacking as! UIKitWindow ) . uiWindow
236222 uiWindow. windowScene = windowScene
237223 windowScene. title = window. title
238224 persistSessionIdentifier ( session, forWindow: window)
239225 } else { // Platform requested a window, probably from a user action
240- Platform . current. applicationRequestedWindow = true
241- if session. role == . windowExternalDisplay {
242- Platform . current. overrideSupportsMultipleWindows = true
243- if let window = try Game . shared. delegate. createWindowForExternalScreen (
244- using: Game . shared. windowManager
245- ) {
226+ Game . unsafeShared. unsafePlatform. applicationRequestedWindow = true
227+ if session. role == . windowExternalDisplayNonInteractive {
228+ Game . unsafeShared. unsafePlatform. overrideSupportsMultipleWindows = true
229+ if let window = try Game . unsafeShared. delegate. createWindowForExternalScreen ( using: Game . unsafeShared. windowManager) {
246230 let uiKitWindow = ( window. windowBacking as! UIKitWindow )
247231 uiKitWindow. uiWindow. windowScene = windowScene
248232 windowScene. title = window. title
249233 persistSessionIdentifier ( session, forWindow: window)
250234 }
251- Platform . current . overrideSupportsMultipleWindows = nil
235+ Game . unsafeShared . unsafePlatform . overrideSupportsMultipleWindows = nil
252236 } else {
253- Platform . current. overrideSupportsMultipleWindows = true
254- if let window = try Game . shared. delegate. createUserRequestedWindow (
255- using: Game . shared. windowManager
256- ) {
237+ Game . unsafeShared. unsafePlatform. overrideSupportsMultipleWindows = true
238+ if let window = try Game . unsafeShared. delegate. createUserRequestedWindow ( using: Game . unsafeShared. windowManager) {
257239 let uiWindow = ( window. windowBacking as! UIKitWindow ) . uiWindow
258240 uiWindow. windowScene = windowScene
259241 windowScene. title = window. title
260242 persistSessionIdentifier ( session, forWindow: window)
261243 } else {
262244 UIApplication . shared. requestSceneSessionDestruction ( session, options: nil )
263245 }
264- Platform . current . overrideSupportsMultipleWindows = nil
246+ Game . unsafeShared . unsafePlatform . overrideSupportsMultipleWindows = nil
265247 }
266248 }
267- Game . shared . attributes. remove ( . renderingIsPermitted)
249+ Game . unsafeShared . attributes. remove ( . renderingIsPermitted)
268250 } catch {
269251 Log . error ( error)
270252 }
271253 }
272254
273255 func sceneDidDisconnect( _ scene: UIScene ) {
274256 Log . info ( " Scene Disconnect: " , scene. title ?? " [NoTitle] " )
275- for window in Game . shared . windowManager. windows {
257+ for window in Game . unsafeShared . windowManager. windows {
276258 let uiWindow = ( window. windowBacking as! UIKitWindow ) . uiWindow
277- if uiWindow. windowScene? . session. persistentIdentifier
278- == scene. session. persistentIdentifier
279- {
280- Game . shared. windowManager. removeWindow ( window. identifier)
259+ if uiWindow. windowScene? . session. persistentIdentifier == scene. session. persistentIdentifier {
260+ Game . unsafeShared. windowManager. removeWindow ( window. identifier)
281261 UserDefaults . standard. removeObject ( forKey: " Windows/ \( window. identifier) /title " )
282262 break
283263 }
0 commit comments