[Widgets]: Use AppIntentConfiguration instead of StaticConfiguration and cleanup

This commit is contained in:
Magesh K
2025-01-10 08:11:35 +05:30
parent 4e10527f03
commit f69b293004
9 changed files with 340 additions and 178 deletions

View File

@@ -7,7 +7,6 @@
//
import AppIntents
import WidgetKit
public enum Direction: String, Sendable{
case up = "up"
@@ -15,43 +14,42 @@ public enum Direction: String, Sendable{
}
@available(iOS 17, *)
class PaginationIntent: AppIntent, @unchecked Sendable {
static var title: LocalizedStringResource { "Scroll up or down in Active Apps Widget" }
final class PaginationIntent: AppIntent, @unchecked Sendable {
static var title: LocalizedStringResource { "Page Navigation Intent" }
static var isDiscoverable: Bool { false }
@Parameter(title: "Direction")
var direction: String
@Parameter(title: "Widget Identifier")
@Parameter(title: "WidgetID")
var widgetID: String
private lazy var widgetHolderQ = {
DispatchQueue(label: widgetID)
}()
required init(){}
var uuid: String = UUID().uuidString
required init(){
print()
}
init(_ direction: Direction, _ widgetID: String){
self.direction = direction.rawValue
self.widgetID = widgetID
}
func perform() async throws -> some IntentResult {
guard let direction = Direction(rawValue: self.direction) else {
return .result()
}
widgetHolderQ.sync {
// update direction for this widgetID
let dataholder = PaginationDataHolder.holder(for: self.widgetID)
dataholder?.updateDirection(direction)
// if let widgetID = self.widgetID
// {
// WidgetCenter.shared.reloadTimelines(ofKind: widgetID)
// }
// return .result()
// ask widget views to be re-drawn by triggering timeline update
// for the widget uniquely identified by the 'kind: widgetID'
WidgetCenter.shared.reloadTimelines(ofKind: self.widgetID)
}
let result = try await WidgetUpdateIntent(
Direction(rawValue: self.direction),
self.widgetID
).perform()
return .result()
return result
}
}