@@ -17,18 +17,29 @@ import SDWebImagePDFCoder
1717class AppDelegate : UIResponder , UIApplicationDelegate {
1818
1919 var window : UIWindow ?
20-
20+ var settings = UserSettings ( )
2121
2222 func application( _ application: UIApplication , didFinishLaunchingWithOptions launchOptions: [ UIApplication . LaunchOptionsKey : Any ] ? ) -> Bool {
2323
2424 // Create the SwiftUI view that provides the window contents.
25- let contentView = ContentView ( )
25+ let contentView = ContentView ( ) . environmentObject ( settings )
2626
2727 // Use a UIHostingController as window root view controller.
2828 let window = UIWindow ( frame: UIScreen . main. bounds)
29- window. rootViewController = UIHostingController ( rootView: contentView)
29+ let hostingController = UIHostingController ( rootView: contentView)
30+ window. rootViewController = hostingController
3031 self . window = window
3132 window. makeKeyAndVisible ( )
33+
34+ // Hack here because of SwiftUI's bug, when using `NavigationLink`, the focusable no longer works, so the `onExitCommand` does not get called
35+ let menuGesture = UITapGestureRecognizer ( target: self , action: #selector( handleMenuGesture ( _: ) ) )
36+ menuGesture. allowedPressTypes = [ NSNumber ( value: UIPress . PressType. menu. rawValue) ]
37+ hostingController. view. addGestureRecognizer ( menuGesture)
38+
39+ let playPauseGesture = UITapGestureRecognizer ( target: self , action: #selector( handlePlayPauseGesture ( _: ) ) )
40+ playPauseGesture. allowedPressTypes = [ NSNumber ( value: UIPress . PressType. playPause. rawValue) ]
41+ hostingController. view. addGestureRecognizer ( playPauseGesture)
42+
3243 // Add WebP/SVG/PDF support
3344 SDImageCodersManager . shared. addCoder ( SDImageWebPCoder . shared)
3445 SDImageCodersManager . shared. addCoder ( SDImageSVGCoder . shared)
@@ -50,6 +61,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5061
5162 return true
5263 }
64+
65+ @objc func handleMenuGesture( _ gesture: UITapGestureRecognizer ) {
66+ switch settings. editMode {
67+ case . inactive:
68+ settings. editMode = . active
69+ case . active:
70+ settings. editMode = . inactive
71+ case . transient:
72+ break
73+ @unknown default :
74+ break
75+ }
76+ }
77+
78+ @objc func handlePlayPauseGesture( _ gesture: UITapGestureRecognizer ) {
79+ settings. zoomed. toggle ( )
80+ }
5381
5482 func applicationWillResignActive( _ application: UIApplication ) {
5583 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
0 commit comments