@@ -8,15 +8,16 @@ public protocol ApplicationShortcutsProvider {
88
99extension UIApplication : ApplicationShortcutsProvider {
1010 @objc public var is3DTouchAvailable : Bool {
11- return mainWindow? . traitCollection. forceTouchCapability == . available
11+ connectedScenes. compactMap { ( $0 as? UIWindowScene ) ? . keyWindow } . first? . traitCollection. forceTouchCapability
12+ == . available
1213 }
1314}
1415
1516open class WP3DTouchShortcutCreator : NSObject {
1617 enum LoggedIn3DTouchShortcutIndex : Int {
1718 case notifications = 0 ,
18- stats,
19- newPost
19+ stats,
20+ newPost
2021 }
2122
2223 var shortcutsProvider : ApplicationShortcutsProvider
@@ -50,18 +51,43 @@ open class WP3DTouchShortcutCreator: NSObject {
5051
5152 fileprivate func registerForNotifications( ) {
5253 let notificationCenter = NotificationCenter . default
53- notificationCenter. addObserver ( self , selector: #selector( WP3DTouchShortcutCreator . createLoggedInShortcuts) , name: NSNotification . Name ( rawValue: WordPressAuthenticationManager . WPSigninDidFinishNotification) , object: nil )
54- notificationCenter. addObserver ( self , selector: #selector( WP3DTouchShortcutCreator . createLoggedInShortcuts) , name: . WPRecentSitesChanged, object: nil )
55- notificationCenter. addObserver ( self , selector: #selector( WP3DTouchShortcutCreator . createLoggedInShortcuts) , name: . WPBlogUpdated, object: nil )
56- notificationCenter. addObserver ( self , selector: #selector( WP3DTouchShortcutCreator . createLoggedInShortcuts) , name: . wpAccountDefaultWordPressComAccountChanged, object: nil )
54+ notificationCenter. addObserver (
55+ self ,
56+ selector: #selector( WP3DTouchShortcutCreator . createLoggedInShortcuts) ,
57+ name: NSNotification . Name ( rawValue: WordPressAuthenticationManager . WPSigninDidFinishNotification) ,
58+ object: nil
59+ )
60+ notificationCenter. addObserver (
61+ self ,
62+ selector: #selector( WP3DTouchShortcutCreator . createLoggedInShortcuts) ,
63+ name: . WPRecentSitesChanged,
64+ object: nil
65+ )
66+ notificationCenter. addObserver (
67+ self ,
68+ selector: #selector( WP3DTouchShortcutCreator . createLoggedInShortcuts) ,
69+ name: . WPBlogUpdated,
70+ object: nil
71+ )
72+ notificationCenter. addObserver (
73+ self ,
74+ selector: #selector( WP3DTouchShortcutCreator . createLoggedInShortcuts) ,
75+ name: . wpAccountDefaultWordPressComAccountChanged,
76+ object: nil
77+ )
5778 }
5879
5980 fileprivate func loggedOutShortcutArray( ) -> [ UIApplicationShortcutItem ] {
60- let logInShortcut = UIMutableApplicationShortcutItem ( type: WP3DTouchShortcutHandler . ShortcutIdentifier. LogIn. type,
61- localizedTitle: NSLocalizedString ( " Log In " , comment: " Log In 3D Touch Shortcut " ) ,
62- localizedSubtitle: nil ,
63- icon: UIApplicationShortcutIcon ( systemImageName: " arrow.right.square " ) ,
64- userInfo: [ WP3DTouchShortcutHandler . applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler . ShortcutIdentifier. LogIn. rawValue as NSSecureCoding ] )
81+ let logInShortcut = UIMutableApplicationShortcutItem (
82+ type: WP3DTouchShortcutHandler . ShortcutIdentifier. LogIn. type,
83+ localizedTitle: NSLocalizedString ( " Log In " , comment: " Log In 3D Touch Shortcut " ) ,
84+ localizedSubtitle: nil ,
85+ icon: UIApplicationShortcutIcon ( systemImageName: " arrow.right.square " ) ,
86+ userInfo: [
87+ WP3DTouchShortcutHandler . applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler . ShortcutIdentifier
88+ . LogIn. rawValue as NSSecureCoding
89+ ]
90+ )
6591
6692 return [ logInShortcut]
6793 }
@@ -72,30 +98,45 @@ open class WP3DTouchShortcutCreator: NSObject {
7298 defaultBlogName = Blog . lastUsedOrFirst ( in: mainContext) ? . settings? . name
7399 }
74100
75- let notificationsShortcut = UIMutableApplicationShortcutItem ( type: WP3DTouchShortcutHandler . ShortcutIdentifier. Notifications. type,
76- localizedTitle: NSLocalizedString ( " Notifications " , comment: " Notifications 3D Touch Shortcut " ) ,
77- localizedSubtitle: nil ,
78- icon: UIApplicationShortcutIcon ( systemImageName: " bell " ) ,
79- userInfo: [ WP3DTouchShortcutHandler . applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler . ShortcutIdentifier. Notifications. rawValue as NSSecureCoding ] )
80-
81- let statsShortcut = UIMutableApplicationShortcutItem ( type: WP3DTouchShortcutHandler . ShortcutIdentifier. Stats. type,
82- localizedTitle: NSLocalizedString ( " Stats " , comment: " Stats 3D Touch Shortcut " ) ,
83- localizedSubtitle: defaultBlogName,
84- icon: UIApplicationShortcutIcon ( systemImageName: " chart.bar " ) ,
85- userInfo: [ WP3DTouchShortcutHandler . applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler . ShortcutIdentifier. Stats. rawValue as NSSecureCoding ] )
86-
87- let newPostShortcut = UIMutableApplicationShortcutItem ( type: WP3DTouchShortcutHandler . ShortcutIdentifier. NewPost. type,
88- localizedTitle: NSLocalizedString ( " New Post " , comment: " New Post 3D Touch Shortcut " ) ,
89- localizedSubtitle: defaultBlogName,
90- icon: UIApplicationShortcutIcon ( systemImageName: " square.and.pencil " ) ,
91- userInfo: [ WP3DTouchShortcutHandler . applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler . ShortcutIdentifier. NewPost. rawValue as NSSecureCoding ] )
101+ let notificationsShortcut = UIMutableApplicationShortcutItem (
102+ type: WP3DTouchShortcutHandler . ShortcutIdentifier. Notifications. type,
103+ localizedTitle: NSLocalizedString ( " Notifications " , comment: " Notifications 3D Touch Shortcut " ) ,
104+ localizedSubtitle: nil ,
105+ icon: UIApplicationShortcutIcon ( systemImageName: " bell " ) ,
106+ userInfo: [
107+ WP3DTouchShortcutHandler . applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler . ShortcutIdentifier
108+ . Notifications. rawValue as NSSecureCoding
109+ ]
110+ )
111+
112+ let statsShortcut = UIMutableApplicationShortcutItem (
113+ type: WP3DTouchShortcutHandler . ShortcutIdentifier. Stats. type,
114+ localizedTitle: NSLocalizedString ( " Stats " , comment: " Stats 3D Touch Shortcut " ) ,
115+ localizedSubtitle: defaultBlogName,
116+ icon: UIApplicationShortcutIcon ( systemImageName: " chart.bar " ) ,
117+ userInfo: [
118+ WP3DTouchShortcutHandler . applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler . ShortcutIdentifier
119+ . Stats. rawValue as NSSecureCoding
120+ ]
121+ )
122+
123+ let newPostShortcut = UIMutableApplicationShortcutItem (
124+ type: WP3DTouchShortcutHandler . ShortcutIdentifier. NewPost. type,
125+ localizedTitle: NSLocalizedString ( " New Post " , comment: " New Post 3D Touch Shortcut " ) ,
126+ localizedSubtitle: defaultBlogName,
127+ icon: UIApplicationShortcutIcon ( systemImageName: " square.and.pencil " ) ,
128+ userInfo: [
129+ WP3DTouchShortcutHandler . applicationShortcutUserInfoIconKey: WP3DTouchShortcutHandler . ShortcutIdentifier
130+ . NewPost. rawValue as NSSecureCoding
131+ ]
132+ )
92133
93134 return [ notificationsShortcut, statsShortcut, newPostShortcut]
94135 }
95136
96137 @objc fileprivate func createLoggedInShortcuts( ) {
97138
98- DispatchQueue . main. async { [ weak self] ( ) in
139+ DispatchQueue . main. async { [ weak self] ( ) in
99140 guard let strongSelf = self else {
100141 return
101142 }
@@ -125,14 +166,8 @@ open class WP3DTouchShortcutCreator: NSObject {
125166 shortcutsProvider. shortcutItems = loggedOutShortcutArray ( )
126167 }
127168
128- fileprivate func is3DTouchAvailable( ) -> Bool {
129- let window = UIApplication . shared. mainWindow
130-
131- return window? . traitCollection. forceTouchCapability == . available
132- }
133-
134169 fileprivate func hasWordPressComAccount( ) -> Bool {
135- return AccountHelper . isDotcomAvailable ( )
170+ AccountHelper . isDotcomAvailable ( )
136171 }
137172
138173 fileprivate func doesCurrentBlogSupportStats( ) -> Bool {
@@ -144,6 +179,6 @@ open class WP3DTouchShortcutCreator: NSObject {
144179 }
145180
146181 fileprivate func hasBlog( ) -> Bool {
147- return Blog . count ( in: mainContext) > 0
182+ Blog . count ( in: mainContext) > 0
148183 }
149184}
0 commit comments