mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[Widgets]: Bug-Fix: always use widgetKind for requesting timeline reload request
This commit is contained in:
@@ -55,9 +55,9 @@ extension View
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func pageUpButton(_ widgetID: Int?) -> some View {
|
func pageUpButton(_ widgetID: Int?, _ widgetKind: String) -> some View {
|
||||||
if #available(iOSApplicationExtension 17, *) {
|
if #available(iOSApplicationExtension 17, *) {
|
||||||
Button(intent: PaginationIntent(widgetID, .up)){
|
Button(intent: PaginationIntent(widgetID, .up, widgetKind)){
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
@@ -67,9 +67,9 @@ extension View
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func pageDownButton(_ widgetID: Int?) -> some View {
|
func pageDownButton(_ widgetID: Int?, _ widgetKind: String) -> some View {
|
||||||
if #available(iOSApplicationExtension 17, *) {
|
if #available(iOSApplicationExtension 17, *) {
|
||||||
Button(intent: PaginationIntent(widgetID, .down)){
|
Button(intent: PaginationIntent(widgetID, .down, widgetKind)){
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
|
|||||||
@@ -34,22 +34,27 @@ class PaginationIntent: AppIntent, @unchecked Sendable {
|
|||||||
@Parameter(title: "Direction")
|
@Parameter(title: "Direction")
|
||||||
var direction: String
|
var direction: String
|
||||||
|
|
||||||
|
@Parameter(title: "widgetKind")
|
||||||
|
var widgetKind: String
|
||||||
|
|
||||||
required init(){}
|
required init(){}
|
||||||
|
|
||||||
init(_ widgetID: Int?, _ direction: Direction){
|
// NOTE: widgetID here means the configurable value using edit widget button
|
||||||
|
// but widgetKind is the kind set in when instantiating the widget configuration
|
||||||
|
init(_ widgetID: Int?, _ direction: Direction, _ widgetKind: String){
|
||||||
// if id was not passed in, then we assume the widget isn't customized yet
|
// if id was not passed in, then we assume the widget isn't customized yet
|
||||||
// hence we use the common ID, if this is not present in registry of PageInfoManager
|
// hence we use the common ID, if this is not present in registry of PageInfoManager
|
||||||
// then it will return nil, triggering to show first page in the provider
|
// then it will return nil, triggering to show first page in the provider
|
||||||
self.widgetID = widgetID ?? COMMON_WIDGET_ID
|
self.widgetID = widgetID ?? COMMON_WIDGET_ID
|
||||||
self.direction = direction.rawValue
|
self.direction = direction.rawValue
|
||||||
|
self.widgetKind = widgetKind
|
||||||
}
|
}
|
||||||
|
|
||||||
func perform() async throws -> some IntentResult {
|
func perform() async throws -> some IntentResult {
|
||||||
let widgetIdString = String(widgetID)
|
DispatchQueue(label: String(widgetID)).sync {
|
||||||
DispatchQueue(label: widgetIdString).sync {
|
|
||||||
let navigationEvent = NavigationEvent(direction: Direction(rawValue: direction))
|
let navigationEvent = NavigationEvent(direction: Direction(rawValue: direction))
|
||||||
PageInfoManager.shared.setPageInfo(for: widgetID, value: navigationEvent)
|
PageInfoManager.shared.setPageInfo(for: widgetID, value: navigationEvent)
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: widgetIdString)
|
WidgetCenter.shared.reloadTimelines(ofKind: widgetKind)
|
||||||
}
|
}
|
||||||
return .result()
|
return .result()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,15 +18,9 @@ class ActiveAppsTimelineProvider<T: WidgetInfo>: AppsTimelineProviderBase<Widge
|
|||||||
let ID: Int?
|
let ID: Int?
|
||||||
}
|
}
|
||||||
|
|
||||||
private let dataHolder: PaginationDataHolder
|
private let dataHolder = PaginationDataHolder(
|
||||||
private let widgetID: String
|
itemsPerPage: ActiveAppsWidget.Constants.MAX_ROWS_PER_PAGE
|
||||||
|
)
|
||||||
init(kind: String){
|
|
||||||
|
|
||||||
let itemsPerPage = ActiveAppsWidget.Constants.MAX_ROWS_PER_PAGE
|
|
||||||
self.dataHolder = PaginationDataHolder(itemsPerPage: itemsPerPage)
|
|
||||||
self.widgetID = kind
|
|
||||||
}
|
|
||||||
|
|
||||||
deinit{
|
deinit{
|
||||||
// if this provider goes out of scope, clear all entries
|
// if this provider goes out of scope, clear all entries
|
||||||
|
|||||||
@@ -32,17 +32,18 @@ struct ActiveAppsWidget: Widget
|
|||||||
static let MAX_ROWS_PER_PAGE: UInt = 3
|
static let MAX_ROWS_PER_PAGE: UInt = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let widgetKind = "ActiveApps - \(UUID().uuidString)"
|
||||||
|
|
||||||
public var body: some WidgetConfiguration {
|
public var body: some WidgetConfiguration {
|
||||||
if #available(iOS 17, *)
|
if #available(iOS 17, *)
|
||||||
{
|
{
|
||||||
let widgetID = "ActiveApps - \(UUID().uuidString)"
|
|
||||||
|
|
||||||
let widgetConfig = AppIntentConfiguration(
|
let widgetConfig = AppIntentConfiguration(
|
||||||
kind: widgetID,
|
kind: widgetKind,
|
||||||
intent: WidgetUpdateIntent.self,
|
intent: WidgetUpdateIntent.self,
|
||||||
provider: ActiveAppsTimelineProvider<WidgetTag>(kind: widgetID)
|
provider: ActiveAppsTimelineProvider<WidgetTag>()
|
||||||
) { entry in
|
) { entry in
|
||||||
ActiveAppsWidgetView(entry: entry)
|
ActiveAppsWidgetView(entry: entry, widgetKind: widgetKind)
|
||||||
}
|
}
|
||||||
.supportedFamilies([.systemMedium])
|
.supportedFamilies([.systemMedium])
|
||||||
.configurationDisplayName("Active Apps")
|
.configurationDisplayName("Active Apps")
|
||||||
@@ -63,6 +64,7 @@ struct ActiveAppsWidget: Widget
|
|||||||
private struct ActiveAppsWidgetView: View
|
private struct ActiveAppsWidgetView: View
|
||||||
{
|
{
|
||||||
var entry: AppsEntry<WidgetInfo>
|
var entry: AppsEntry<WidgetInfo>
|
||||||
|
var widgetKind: String
|
||||||
|
|
||||||
@Environment(\.colorScheme)
|
@Environment(\.colorScheme)
|
||||||
private var colorScheme
|
private var colorScheme
|
||||||
@@ -204,7 +206,7 @@ private struct ActiveAppsWidgetView: View
|
|||||||
.frame(width: buttonWidth, height: buttonWidth)
|
.frame(width: buttonWidth, height: buttonWidth)
|
||||||
.opacity(0.3)
|
.opacity(0.3)
|
||||||
// .mask(Capsule())
|
// .mask(Capsule())
|
||||||
.pageUpButton(widgetID)
|
.pageUpButton(widgetID, widgetKind)
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
@@ -213,7 +215,7 @@ private struct ActiveAppsWidgetView: View
|
|||||||
.frame(width: buttonWidth, height: buttonWidth)
|
.frame(width: buttonWidth, height: buttonWidth)
|
||||||
.opacity(0.3)
|
.opacity(0.3)
|
||||||
// .mask(Capsule())
|
// .mask(Capsule())
|
||||||
.pageDownButton(widgetID)
|
.pageDownButton(widgetID, widgetKind)
|
||||||
}
|
}
|
||||||
.padding(.vertical)
|
.padding(.vertical)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user