-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathOpenStatsIntent.swift
More file actions
46 lines (43 loc) · 1.69 KB
/
Copy pathOpenStatsIntent.swift
File metadata and controls
46 lines (43 loc) · 1.69 KB
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
import AppIntents
import JetpackStatsWidgetsCore
import WordPressData
/// Opens Stats for a chosen site, or the last used site when none is picked.
struct OpenStatsIntent: AppIntent {
static let title = LocalizedStringResource(
"ios-appintents.openStats.title",
defaultValue: "Open Stats",
table: "AppIntents",
comment: "Title of the App Intent that opens Stats for a site. Shown in the Shortcuts app and Spotlight."
)
static let description = IntentDescription(
LocalizedStringResource(
"ios-appintents.openStats.description",
defaultValue: "Opens the stats for one of your sites.",
table: "AppIntents",
comment: "Description of the App Intent that opens Stats for a site. Shown in the Shortcuts app."
)
)
static let openAppWhenRun = true
@Parameter(
title: LocalizedStringResource(
"ios-widget.ILcGmf",
defaultValue: "Site",
table: "Localizable",
comment: "Label of the site parameter of the Open Stats App Intent. Shown in the Shortcuts app."
)
)
var site: SiteEntity?
@MainActor
func perform() async throws -> some IntentResult {
guard AccountHelper.isLoggedIn else {
throw AppIntentOpenError.notLoggedIn
}
guard let blog = Blog.forAppIntent(siteIdentifier: site?.id, in: ContextManager.shared.mainContext) else {
throw AppIntentOpenError.siteNotFound
}
let presenter = RootViewCoordinator.sharedPresenter
presenter.rootViewController.dismiss(animated: false)
presenter.showStats(for: blog, source: .shortcut)
return .result()
}
}