From 2c5f3d0bf0bb68cc51810031ae9c1c85e2598a5e Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 16 Jul 2022 21:37:36 +0200 Subject: [PATCH] Send app to background in OrganizerView handler Keep handler in a single place. --- Passepartout/App/PassepartoutApp.swift | 14 -------------- Passepartout/App/Views/OrganizerView+Scene.swift | 3 +++ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/Passepartout/App/PassepartoutApp.swift b/Passepartout/App/PassepartoutApp.swift index c3dcb27a..3c45fc6a 100644 --- a/Passepartout/App/PassepartoutApp.swift +++ b/Passepartout/App/PassepartoutApp.swift @@ -30,8 +30,6 @@ import PassepartoutLibrary struct PassepartoutApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate - @Environment(\.scenePhase) private var scenePhase - @SceneBuilder var body: some Scene { WindowGroup { MainView() @@ -44,18 +42,6 @@ struct PassepartoutApp: App { .onIntentActivity(IntentDispatcher.trustCurrentNetwork) .onIntentActivity(IntentDispatcher.untrustCellularNetwork) .onIntentActivity(IntentDispatcher.untrustCurrentNetwork) - }.onChange(of: scenePhase, perform: onScenePhase) - } - - private func onScenePhase(_ scenePhase: ScenePhase) { - switch scenePhase { - case .background: - #if targetEnvironment(macCatalyst) - MacBundle.shared.utils.sendAppToBackground() - #endif - - default: - break } } } diff --git a/Passepartout/App/Views/OrganizerView+Scene.swift b/Passepartout/App/Views/OrganizerView+Scene.swift index 392032f4..2cbb201a 100644 --- a/Passepartout/App/Views/OrganizerView+Scene.swift +++ b/Passepartout/App/Views/OrganizerView+Scene.swift @@ -94,6 +94,9 @@ extension OrganizerView { case .background: persist() + #if targetEnvironment(macCatalyst) + MacBundle.shared.utils.sendAppToBackground() + #endif default: break