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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import AppIntents
import Foundation
// MARK: - Shortcut action routing
extension Notification.Name {
static let grainShortcutAction = Notification.Name("GrainShortcutAction")
}
enum GrainShortcutAction: String {
case feed, search, notifications, profile, createGallery, createStory
}
// MARK: - Intents
struct OpenFeedIntent: AppIntent {
static let title: LocalizedStringResource = "Open Feed"
static let description = IntentDescription("Browse your photo feed in Grain.")
static let openAppWhenRun = true
@MainActor
func perform() async throws -> some IntentResult {
NotificationCenter.default.post(name: .grainShortcutAction, object: GrainShortcutAction.feed.rawValue)
return .result()
}
}
struct OpenSearchIntent: AppIntent {
static let title: LocalizedStringResource = "Search"
static let description = IntentDescription("Search for photos, profiles, and hashtags in Grain.")
static let openAppWhenRun = true
@MainActor
func perform() async throws -> some IntentResult {
NotificationCenter.default.post(name: .grainShortcutAction, object: GrainShortcutAction.search.rawValue)
return .result()
}
}
struct OpenNotificationsIntent: AppIntent {
static let title: LocalizedStringResource = "Open Notifications"
static let description = IntentDescription("Check your latest activity in Grain.")
static let openAppWhenRun = true
@MainActor
func perform() async throws -> some IntentResult {
NotificationCenter.default.post(name: .grainShortcutAction, object: GrainShortcutAction.notifications.rawValue)
return .result()
}
}
struct OpenProfileIntent: AppIntent {
static let title: LocalizedStringResource = "Open My Profile"
static let description = IntentDescription("View your profile and galleries in Grain.")
static let openAppWhenRun = true
@MainActor
func perform() async throws -> some IntentResult {
NotificationCenter.default.post(name: .grainShortcutAction, object: GrainShortcutAction.profile.rawValue)
return .result()
}
}
struct CreateStoryIntent: AppIntent {
static let title: LocalizedStringResource = "Create Story"
static let description = IntentDescription("Start posting a new story in Grain.")
static let openAppWhenRun = true
@MainActor
func perform() async throws -> some IntentResult {
NotificationCenter.default.post(name: .grainShortcutAction, object: GrainShortcutAction.createStory.rawValue)
return .result()
}
}
struct CreateGalleryIntent: AppIntent {
static let title: LocalizedStringResource = "Create Gallery"
static let description = IntentDescription("Start posting a new photo gallery in Grain.")
static let openAppWhenRun = true
@MainActor
func perform() async throws -> some IntentResult {
NotificationCenter.default.post(name: .grainShortcutAction, object: GrainShortcutAction.createGallery.rawValue)
return .result()
}
}
// MARK: - Shortcuts provider
struct GrainShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: CreateStoryIntent(),
phrases: [
"Create a story in \(.applicationName)",
"New \(.applicationName) story",
"Post a \(.applicationName) story",
],
shortTitle: "Create Story",
systemImageName: "plus.circle"
)
AppShortcut(
intent: CreateGalleryIntent(),
phrases: [
"Create a gallery in \(.applicationName)",
"New \(.applicationName) gallery",
"Post to \(.applicationName)",
],
shortTitle: "Create Gallery",
systemImageName: "plus.square.on.square"
)
AppShortcut(
intent: OpenFeedIntent(),
phrases: [
"Open feed in \(.applicationName)",
"Show \(.applicationName) feed",
],
shortTitle: "Open Feed",
systemImageName: "photo.on.rectangle"
)
AppShortcut(
intent: OpenSearchIntent(),
phrases: [
"Search in \(.applicationName)",
"Open \(.applicationName) search",
],
shortTitle: "Search",
systemImageName: "magnifyingglass"
)
AppShortcut(
intent: OpenNotificationsIntent(),
phrases: [
"Open \(.applicationName) notifications",
"Show \(.applicationName) notifications",
],
shortTitle: "Notifications",
systemImageName: "bell"
)
AppShortcut(
intent: OpenProfileIntent(),
phrases: [
"Open my \(.applicationName) profile",
"Show my \(.applicationName) profile",
],
shortTitle: "My Profile",
systemImageName: "person"
)
}
}