Add configurable iPhone widgets
This commit is contained in:
52
ios/Sources/WidgetIntents.swift
Normal file
52
ios/Sources/WidgetIntents.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
import AppIntents
|
||||
import Foundation
|
||||
|
||||
enum WidgetEnvironment {
|
||||
static let appGroup = "group.de.rfc1437.gotcha"
|
||||
|
||||
static func core() -> GotchaCore {
|
||||
GotchaCore(
|
||||
storageDirectory: FileManager.default.containerURL(
|
||||
forSecurityApplicationGroupIdentifier: appGroup
|
||||
)?.path
|
||||
)
|
||||
}
|
||||
|
||||
static func servers() -> [ServerRow] {
|
||||
core().servers()
|
||||
}
|
||||
|
||||
static func selection(for server: ServerRow) -> String {
|
||||
"\(server.name) · \(server.url)"
|
||||
}
|
||||
|
||||
static func server(for selection: String) -> ServerRow? {
|
||||
servers().first { self.selection(for: $0) == selection }
|
||||
}
|
||||
}
|
||||
|
||||
struct WidgetServerOptionsProvider: DynamicOptionsProvider {
|
||||
func results() async throws -> [String] {
|
||||
WidgetEnvironment.servers().map(WidgetEnvironment.selection)
|
||||
}
|
||||
|
||||
func defaultResult() async -> String? {
|
||||
WidgetEnvironment.servers().first.map(WidgetEnvironment.selection)
|
||||
}
|
||||
}
|
||||
|
||||
struct ActivityWidgetIntent: WidgetConfigurationIntent {
|
||||
static let title: LocalizedStringResource = "Activity Server"
|
||||
static let description = IntentDescription("Choose the server whose recent activity appears.")
|
||||
|
||||
@Parameter(title: "Server", optionsProvider: WidgetServerOptionsProvider())
|
||||
var server: String?
|
||||
}
|
||||
|
||||
struct PullsWidgetIntent: WidgetConfigurationIntent {
|
||||
static let title: LocalizedStringResource = "Pull Request Server"
|
||||
static let description = IntentDescription("Choose the server whose open pull requests appear.")
|
||||
|
||||
@Parameter(title: "Server", optionsProvider: WidgetServerOptionsProvider())
|
||||
var server: String?
|
||||
}
|
||||
Reference in New Issue
Block a user