-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSiteEntity.swift
More file actions
49 lines (43 loc) · 1.85 KB
/
Copy pathSiteEntity.swift
File metadata and controls
49 lines (43 loc) · 1.85 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
47
48
49
import AppIntents
import Foundation
/// A WordPress.com (or Jetpack-connected) site, as exposed to the system via App Intents.
///
/// The identifier is the site's WP.com ID encoded as a decimal string. It deliberately matches
/// the `identifier` of the legacy SiriKit `Site` object so that widget configurations created
/// before the App Intents migration keep resolving to the same site.
///
/// The "ios-widget.ILcGmf" localization key resolves against the app bundle on iOS 18 and
/// later; see `SelectSiteIntent` for the details.
public struct SiteEntity: AppEntity {
public static let typeDisplayRepresentation = TypeDisplayRepresentation(
name: LocalizedStringResource(
"ios-widget.ILcGmf",
defaultValue: "Site",
comment:
"This text is used when the user is configuring the iOS widget, as a label for the dropdown to select the site to configure it for"
)
)
public static var defaultQuery: SiteEntityQuery { SiteEntityQuery() }
public let id: String
public let name: String
public let domain: String?
public var displayRepresentation: DisplayRepresentation {
if let domain {
return DisplayRepresentation(title: "\(name)", subtitle: "\(domain)")
}
return DisplayRepresentation(title: "\(name)")
}
init(siteID: Int, data: HomeWidgetTodayData) {
self.id = String(siteID)
self.name = data.siteName
self.domain = URLComponents(string: data.url)?.host
}
/// A placeholder for a configured site that cannot currently be resolved from the
/// widget cache. Preserving the identifier keeps the user's widget configuration
/// intact until the cache becomes readable again.
init(unresolvedID: String) {
self.id = unresolvedID
self.name = unresolvedID
self.domain = nil
}
}