1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import UIKit
@MainActor
class GrainSceneDelegate: NSObject, UIWindowSceneDelegate {
var window: UIWindow?
func scene(
_: UIScene,
willConnectTo _: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
if let item = connectionOptions.shortcutItem {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
Self.dispatch(type: item.type)
}
}
}
func windowScene(
_: UIWindowScene,
performActionFor shortcutItem: UIApplicationShortcutItem,
completionHandler: @escaping (Bool) -> Void
) {
Self.dispatch(type: shortcutItem.type)
completionHandler(true)
}
private static func dispatch(type: String) {
let action: GrainShortcutAction? = switch type {
case "social.grain.shortcut.createStory": .createStory
case "social.grain.shortcut.createGallery": .createGallery
default: nil
}
if let action {
NotificationCenter.default.post(name: .grainShortcutAction, object: action.rawValue)
}
}
}