Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Move stuff from SceneDelegate to App
Browse files Browse the repository at this point in the history
  • Loading branch information
IngmarStein committed Jul 23, 2020
1 parent 21e4390 commit a1f5e3b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 55 deletions.
25 changes: 25 additions & 0 deletions Classes/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,34 @@ import SwiftUI
struct KraftstoffApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

@Environment(\.scenePhase) private var scenePhase

var body: some Scene {
WindowGroup {
MainView()
.environment(\.managedObjectContext, DataManager.managedObjectContext)
}
.onChange(of: scenePhase) { phase in
switch phase {
case .background:
DataManager.saveContext()
case .active:
if ProcessInfo.processInfo.arguments.firstIndex(of: "-UNITTEST") != nil {
//TODO
//self.window?.layer.speed = 100
}

#if targetEnvironment(macCatalyst)
if ProcessInfo.processInfo.arguments.firstIndex(of: "-SCREENSHOT") != nil {
if let windowScene = scene as? UIWindowScene {
let size = CGSize(width: 1440.0, height: 900.0)
windowScene.sizeRestrictions?.minimumSize = size
windowScene.sizeRestrictions?.maximumSize = size
}
}
#endif
default: break
}
}
}
}
6 changes: 0 additions & 6 deletions Classes/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,3 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, NSFetchedResultsCon
}

}

struct AppDelegate_Previews: PreviewProvider {
static var previews: some View {
/*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/
}
}
30 changes: 1 addition & 29 deletions Classes/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// WindowSceneDelegate.swift
// SceneDelegate.swift
// Kraftstoff
//
// Created by Ingmar Stein on 05.06.19.
Expand All @@ -18,35 +18,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
let contentView = MainView().environment(\.managedObjectContext, DataManager.managedObjectContext)

UITableView.appearance().backgroundColor = UIColor.clear
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}

func sceneDidEnterBackground(_ scene: UIScene) {
DataManager.saveContext()
}

func sceneDidBecomeActive(_ scene: UIScene) {
if ProcessInfo.processInfo.arguments.firstIndex(of: "-UNITTEST") != nil {
self.window?.layer.speed = 100
}

#if targetEnvironment(macCatalyst)
if ProcessInfo.processInfo.arguments.firstIndex(of: "-SCREENSHOT") != nil {
if let windowScene = scene as? UIWindowScene {
let size = CGSize(width: 1440.0, height: 900.0)
windowScene.sizeRestrictions?.minimumSize = size
windowScene.sizeRestrictions?.maximumSize = size
}
}
#endif
}

func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
Expand Down
22 changes: 2 additions & 20 deletions kraftstoff-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,16 @@
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UISceneConfigurationName</key>
<string>Default</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>MainStoryboard</string>
</dict>
</array>
</dict>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>MainStoryboard</string>
<key>UIPrerenderedIcon</key>
<true/>
<key>UIStatusBarStyle</key>
Expand Down

0 comments on commit a1f5e3b

Please sign in to comment.