mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-17 18:53:40 +01:00
[Widgets]: Use AppIntentConfiguration instead of StaticConfiguration and cleanup
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
42
AltWidget/Intents/WidgetUpdateIntent.swift
Normal file
42
AltWidget/Intents/WidgetUpdateIntent.swift
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// WidgetUpdateIntent.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Magesh K on 10/01/25.
|
||||
// Copyright © 2025 SideStore. All rights reserved.
|
||||
//
|
||||
|
||||
import AppIntents
|
||||
|
||||
@available(iOS 17, *)
|
||||
final class WidgetUpdateIntent: WidgetConfigurationIntent, @unchecked Sendable {
|
||||
|
||||
static var title: LocalizedStringResource { "Intent for WidgetAppIntentConfiguration receiver type" }
|
||||
static var isDiscoverable: Bool { false }
|
||||
|
||||
var uuid: String = UUID().uuidString
|
||||
private var widgetID: String?
|
||||
|
||||
@Parameter(title: "ID", description: "Change this to unique ID to keep changes isolated from other widgets", default: "1")
|
||||
var ID: String?
|
||||
|
||||
// this static hack is required, coz we are making these intents stateful
|
||||
private static var directionMap: [String: Direction] = [:]
|
||||
|
||||
init(){
|
||||
print()
|
||||
}
|
||||
|
||||
func getDirection( _ widgetID: String) -> Direction? {
|
||||
// remove it, since the event is processed. if needed it will be added again
|
||||
return Self.directionMap.removeValue(forKey: widgetID)
|
||||
}
|
||||
|
||||
init(_ direction: Direction?, _ widgetID: String){
|
||||
Self.directionMap[widgetID] = direction
|
||||
}
|
||||
|
||||
func perform() async throws -> some IntentResult {
|
||||
return .result()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user