@@ -17,18 +17,29 @@ import SDWebImagePDFCoder
17
17
class AppDelegate : UIResponder , UIApplicationDelegate {
18
18
19
19
var window : UIWindow ?
20
-
20
+ var settings = UserSettings ( )
21
21
22
22
func application( _ application: UIApplication , didFinishLaunchingWithOptions launchOptions: [ UIApplication . LaunchOptionsKey : Any ] ? ) -> Bool {
23
23
24
24
// Create the SwiftUI view that provides the window contents.
25
- let contentView = ContentView ( )
25
+ let contentView = ContentView ( ) . environmentObject ( settings )
26
26
27
27
// Use a UIHostingController as window root view controller.
28
28
let window = UIWindow ( frame: UIScreen . main. bounds)
29
- window. rootViewController = UIHostingController ( rootView: contentView)
29
+ let hostingController = UIHostingController ( rootView: contentView)
30
+ window. rootViewController = hostingController
30
31
self . window = window
31
32
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
+
32
43
// Add WebP/SVG/PDF support
33
44
SDImageCodersManager . shared. addCoder ( SDImageWebPCoder . shared)
34
45
SDImageCodersManager . shared. addCoder ( SDImageSVGCoder . shared)
@@ -50,6 +61,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
50
61
51
62
return true
52
63
}
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
+ }
53
81
54
82
func applicationWillResignActive( _ application: UIApplication ) {
55
83
// 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