mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[Widgets]: Enhanced to isolate operations from multiple views of same widget type
This commit is contained in:
@@ -63,9 +63,11 @@
|
|||||||
A82067C42D03E0DE00645C0D /* SemanticVersion in Frameworks */ = {isa = PBXBuildFile; productRef = A82067C32D03E0DE00645C0D /* SemanticVersion */; };
|
A82067C42D03E0DE00645C0D /* SemanticVersion in Frameworks */ = {isa = PBXBuildFile; productRef = A82067C32D03E0DE00645C0D /* SemanticVersion */; };
|
||||||
A859ED5C2D1EE827003DCC58 /* OpenSSL.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = A859ED5B2D1EE80D003DCC58 /* OpenSSL.xcframework */; };
|
A859ED5C2D1EE827003DCC58 /* OpenSSL.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = A859ED5B2D1EE80D003DCC58 /* OpenSSL.xcframework */; };
|
||||||
A859ED5D2D1EE827003DCC58 /* OpenSSL.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A859ED5B2D1EE80D003DCC58 /* OpenSSL.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
A859ED5D2D1EE827003DCC58 /* OpenSSL.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A859ED5B2D1EE80D003DCC58 /* OpenSSL.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||||
|
A868CFE42D31999A002F1201 /* SingletonGenericMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = A868CFE32D319988002F1201 /* SingletonGenericMap.swift */; };
|
||||||
A8945AA62D059B6100D86CBE /* Roxas.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A8945AA52D059B6100D86CBE /* Roxas.framework */; };
|
A8945AA62D059B6100D86CBE /* Roxas.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A8945AA52D059B6100D86CBE /* Roxas.framework */; };
|
||||||
A8A543302D04F14400D72399 /* libfragmentzip.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A8A5432F2D04F0C100D72399 /* libfragmentzip.a */; };
|
A8A543302D04F14400D72399 /* libfragmentzip.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A8A5432F2D04F0C100D72399 /* libfragmentzip.a */; };
|
||||||
A8A853AF2D3065A300995795 /* ActiveAppsTimelineProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8A853AE2D3065A300995795 /* ActiveAppsTimelineProvider.swift */; };
|
A8A853AF2D3065A300995795 /* ActiveAppsTimelineProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8A853AE2D3065A300995795 /* ActiveAppsTimelineProvider.swift */; };
|
||||||
|
A8AD35592D31BF2C003A28B4 /* PageInfoManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8AD35582D31BF29003A28B4 /* PageInfoManager.swift */; };
|
||||||
A8B516E32D2666CA0047047C /* CoreDataHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B516E22D2666CA0047047C /* CoreDataHelper.swift */; };
|
A8B516E32D2666CA0047047C /* CoreDataHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B516E22D2666CA0047047C /* CoreDataHelper.swift */; };
|
||||||
A8B516E62D2668170047047C /* DateTimeUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B516E52D2668020047047C /* DateTimeUtil.swift */; };
|
A8B516E62D2668170047047C /* DateTimeUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B516E52D2668020047047C /* DateTimeUtil.swift */; };
|
||||||
A8BB34E52D04EC8E000A8B4D /* minimuxer-helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A809F6A52D04DA1900F0F0F3 /* minimuxer-helpers.swift */; };
|
A8BB34E52D04EC8E000A8B4D /* minimuxer-helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A809F6A52D04DA1900F0F0F3 /* minimuxer-helpers.swift */; };
|
||||||
@@ -642,8 +644,10 @@
|
|||||||
A85ACB932D1F31C400AA3DE7 /* AltWidgetExtension.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AltWidgetExtension.xcconfig; sourceTree = "<group>"; };
|
A85ACB932D1F31C400AA3DE7 /* AltWidgetExtension.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AltWidgetExtension.xcconfig; sourceTree = "<group>"; };
|
||||||
A86202322D1F35640091187B /* AltStore.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AltStore.xcconfig; sourceTree = "<group>"; };
|
A86202322D1F35640091187B /* AltStore.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AltStore.xcconfig; sourceTree = "<group>"; };
|
||||||
A86202332D1F35640091187B /* AltStoreCore.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AltStoreCore.xcconfig; sourceTree = "<group>"; };
|
A86202332D1F35640091187B /* AltStoreCore.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AltStoreCore.xcconfig; sourceTree = "<group>"; };
|
||||||
|
A868CFE32D319988002F1201 /* SingletonGenericMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingletonGenericMap.swift; sourceTree = "<group>"; };
|
||||||
A8945AA52D059B6100D86CBE /* Roxas.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Roxas.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
A8945AA52D059B6100D86CBE /* Roxas.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Roxas.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
A8A853AE2D3065A300995795 /* ActiveAppsTimelineProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveAppsTimelineProvider.swift; sourceTree = "<group>"; };
|
A8A853AE2D3065A300995795 /* ActiveAppsTimelineProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveAppsTimelineProvider.swift; sourceTree = "<group>"; };
|
||||||
|
A8AD35582D31BF29003A28B4 /* PageInfoManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageInfoManager.swift; sourceTree = "<group>"; };
|
||||||
A8B516E22D2666CA0047047C /* CoreDataHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataHelper.swift; sourceTree = "<group>"; };
|
A8B516E22D2666CA0047047C /* CoreDataHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataHelper.swift; sourceTree = "<group>"; };
|
||||||
A8B516E52D2668020047047C /* DateTimeUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTimeUtil.swift; sourceTree = "<group>"; };
|
A8B516E52D2668020047047C /* DateTimeUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTimeUtil.swift; sourceTree = "<group>"; };
|
||||||
A8C38C1D2D206A3A00E83DBD /* ConsoleLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleLogger.swift; sourceTree = "<group>"; };
|
A8C38C1D2D206A3A00E83DBD /* ConsoleLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleLogger.swift; sourceTree = "<group>"; };
|
||||||
@@ -1184,8 +1188,8 @@
|
|||||||
A80D790B2D2F209700A40F40 /* Intents */ = {
|
A80D790B2D2F209700A40F40 /* Intents */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
A8096D172D30AD4F000C39C6 /* WidgetUpdateIntent.swift */,
|
|
||||||
A80D790C2D2F20AF00A40F40 /* PaginationIntent.swift */,
|
A80D790C2D2F20AF00A40F40 /* PaginationIntent.swift */,
|
||||||
|
A8096D172D30AD4F000C39C6 /* WidgetUpdateIntent.swift */,
|
||||||
);
|
);
|
||||||
path = Intents;
|
path = Intents;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -1224,6 +1228,22 @@
|
|||||||
path = pagination;
|
path = pagination;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
A8AD35562D31BE8F003A28B4 /* Manager */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
A8AD35582D31BF29003A28B4 /* PageInfoManager.swift */,
|
||||||
|
);
|
||||||
|
path = Manager;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
A8AD35572D31BEB2003A28B4 /* datastructures */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
A868CFE32D319988002F1201 /* SingletonGenericMap.swift */,
|
||||||
|
);
|
||||||
|
path = datastructures;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
A8B516DE2D2666900047047C /* dignostics */ = {
|
A8B516DE2D2666900047047C /* dignostics */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@@ -1243,6 +1263,7 @@
|
|||||||
A8C38C1C2D2068D100E83DBD /* Utils */ = {
|
A8C38C1C2D2068D100E83DBD /* Utils */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
A8AD35572D31BEB2003A28B4 /* datastructures */,
|
||||||
A8A853AD2D3050CC00995795 /* pagination */,
|
A8A853AD2D3050CC00995795 /* pagination */,
|
||||||
A8087E712D2D291B002DB21B /* importexport */,
|
A8087E712D2D291B002DB21B /* importexport */,
|
||||||
A8B516DE2D2666900047047C /* dignostics */,
|
A8B516DE2D2666900047047C /* dignostics */,
|
||||||
@@ -1731,6 +1752,7 @@
|
|||||||
BF98916C250AABF3002ACF50 /* AltWidget */ = {
|
BF98916C250AABF3002ACF50 /* AltWidget */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
A8AD35562D31BE8F003A28B4 /* Manager */,
|
||||||
A80D790B2D2F209700A40F40 /* Intents */,
|
A80D790B2D2F209700A40F40 /* Intents */,
|
||||||
A8096D1D2D30ADD5000C39C6 /* Providers */,
|
A8096D1D2D30ADD5000C39C6 /* Providers */,
|
||||||
A800F6FE2CE28DE300208744 /* Extensions */,
|
A800F6FE2CE28DE300208744 /* Extensions */,
|
||||||
@@ -2940,7 +2962,9 @@
|
|||||||
A8096D1C2D30ADA9000C39C6 /* ActiveAppsTimelineProvider+Simulator.swift in Sources */,
|
A8096D1C2D30ADA9000C39C6 /* ActiveAppsTimelineProvider+Simulator.swift in Sources */,
|
||||||
A80D790D2D2F20AF00A40F40 /* PaginationIntent.swift in Sources */,
|
A80D790D2D2F20AF00A40F40 /* PaginationIntent.swift in Sources */,
|
||||||
D5FD4EC92A9530C00097BEE8 /* AppSnapshot.swift in Sources */,
|
D5FD4EC92A9530C00097BEE8 /* AppSnapshot.swift in Sources */,
|
||||||
|
A8AD35592D31BF2C003A28B4 /* PageInfoManager.swift in Sources */,
|
||||||
D5151BE72A90395400C96F28 /* View+AltWidget.swift in Sources */,
|
D5151BE72A90395400C96F28 /* View+AltWidget.swift in Sources */,
|
||||||
|
A868CFE42D31999A002F1201 /* SingletonGenericMap.swift in Sources */,
|
||||||
A8A853AF2D3065A300995795 /* ActiveAppsTimelineProvider.swift in Sources */,
|
A8A853AF2D3065A300995795 /* ActiveAppsTimelineProvider.swift in Sources */,
|
||||||
BF98917F250AAC4F002ACF50 /* LockScreenWidget.swift in Sources */,
|
BF98917F250AAC4F002ACF50 /* LockScreenWidget.swift in Sources */,
|
||||||
A800F7042CE28E3800208744 /* View+AltWidget.swift in Sources */,
|
A800F7042CE28E3800208744 /* View+AltWidget.swift in Sources */,
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ extension View
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func pageUpButton(_ widgetID: String) -> some View {
|
func pageUpButton(_ widgetID: Int?) -> some View {
|
||||||
if #available(iOSApplicationExtension 17, *) {
|
if #available(iOSApplicationExtension 17, *) {
|
||||||
Button(intent: PaginationIntent(.up, widgetID)){
|
Button(intent: PaginationIntent(widgetID, .up)){
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
@@ -67,9 +67,9 @@ extension View
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func pageDownButton(_ widgetID: String) -> some View {
|
func pageDownButton(_ widgetID: Int?) -> some View {
|
||||||
if #available(iOSApplicationExtension 17, *) {
|
if #available(iOSApplicationExtension 17, *) {
|
||||||
Button(intent: PaginationIntent(.down, widgetID)){
|
Button(intent: PaginationIntent(widgetID, .down)){
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
|
|||||||
@@ -7,49 +7,50 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import AppIntents
|
import AppIntents
|
||||||
|
import Intents
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
public enum Direction: String, Sendable{
|
public enum Direction: String, Sendable{
|
||||||
case up = "up"
|
case up
|
||||||
case down = "down"
|
case down
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct NavigationEvent {
|
||||||
|
let direction: Direction?
|
||||||
|
var consumed: Bool = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(iOS 17, *)
|
@available(iOS 17, *)
|
||||||
final class PaginationIntent: AppIntent, @unchecked Sendable {
|
class PaginationIntent: AppIntent, @unchecked Sendable {
|
||||||
|
|
||||||
static var title: LocalizedStringResource { "Page Navigation Intent" }
|
private let COMMON_WIDGET_ID = 1
|
||||||
static var isDiscoverable: Bool { false }
|
|
||||||
|
static var title: LocalizedStringResource = "Page Navigation Intent"
|
||||||
|
static var isDiscoverable: Bool = false
|
||||||
|
|
||||||
|
@Parameter(title: "widgetID")
|
||||||
|
var widgetID: Int
|
||||||
|
|
||||||
@Parameter(title: "Direction")
|
@Parameter(title: "Direction")
|
||||||
var direction: String
|
var direction: String
|
||||||
|
|
||||||
@Parameter(title: "WidgetID")
|
required init(){}
|
||||||
var widgetID: String
|
|
||||||
|
|
||||||
var uuid: String = UUID().uuidString
|
init(_ widgetID: Int?, _ direction: Direction){
|
||||||
|
// if id was not passed in, then we assume the widget isn't customized yet
|
||||||
required init(){
|
// hence we use the common ID, if this is not present in registry of PageInfoManager
|
||||||
print()
|
// then it will return nil, triggering to show first page in the provider
|
||||||
}
|
self.widgetID = widgetID ?? COMMON_WIDGET_ID
|
||||||
|
|
||||||
init(_ direction: Direction, _ widgetID: String){
|
|
||||||
self.direction = direction.rawValue
|
self.direction = direction.rawValue
|
||||||
self.widgetID = widgetID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func perform() async throws -> some IntentResult {
|
func perform() async throws -> some IntentResult {
|
||||||
// if let widgetID = self.widgetID
|
let widgetIdString = String(widgetID)
|
||||||
// {
|
DispatchQueue(label: widgetIdString).sync {
|
||||||
// WidgetCenter.shared.reloadTimelines(ofKind: widgetID)
|
let navigationEvent = NavigationEvent(direction: Direction(rawValue: direction))
|
||||||
// }
|
PageInfoManager.shared.setPageInfo(for: widgetID, value: navigationEvent)
|
||||||
// return .result()
|
WidgetCenter.shared.reloadTimelines(ofKind: widgetIdString)
|
||||||
|
}
|
||||||
let result = try await WidgetUpdateIntent(
|
return .result()
|
||||||
Direction(rawValue: self.direction),
|
|
||||||
self.widgetID
|
|
||||||
).perform()
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,32 +11,9 @@ import AppIntents
|
|||||||
@available(iOS 17, *)
|
@available(iOS 17, *)
|
||||||
final class WidgetUpdateIntent: WidgetConfigurationIntent, @unchecked Sendable {
|
final class WidgetUpdateIntent: WidgetConfigurationIntent, @unchecked Sendable {
|
||||||
|
|
||||||
static var title: LocalizedStringResource { "Intent for WidgetAppIntentConfiguration receiver type" }
|
static var title: LocalizedStringResource { "Widget ID update Intent" }
|
||||||
static var isDiscoverable: Bool { false }
|
static var isDiscoverable: Bool { false }
|
||||||
|
|
||||||
var uuid: String = UUID().uuidString
|
@Parameter(title: "ID", description: "Provide a numeric ID to identify the widget", default: 1)
|
||||||
private var widgetID: String?
|
var ID: Int?
|
||||||
|
|
||||||
@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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
31
AltWidget/Manager/PageInfoManager.swift
Normal file
31
AltWidget/Manager/PageInfoManager.swift
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// PageInfoManager.swift
|
||||||
|
// AltStore
|
||||||
|
//
|
||||||
|
// Created by Magesh K on 11/01/25.
|
||||||
|
// Copyright © 2025 SideStore. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
// This is a utility class
|
||||||
|
class PageInfoManager {
|
||||||
|
static var shared = PageInfoManager()
|
||||||
|
private var pageInfoMap: [Int: NavigationEvent] = [:]
|
||||||
|
|
||||||
|
private init() {}
|
||||||
|
|
||||||
|
func setPageInfo(for key: Int, value: NavigationEvent?) {
|
||||||
|
pageInfoMap[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPageInfo(for key: Int) -> NavigationEvent? {
|
||||||
|
return pageInfoMap[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
func popPageInfo(for key: Int) -> NavigationEvent? {
|
||||||
|
return pageInfoMap.removeValue(forKey: key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func clearAll() {
|
||||||
|
pageInfoMap.removeAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/// Simulator data generator
|
/// Simulator data generator
|
||||||
#if DEBUG
|
#if targetEnvironment(simulator)
|
||||||
@available(iOS 17, *)
|
@available(iOS 17, *)
|
||||||
extension ActiveAppsTimelineProvider {
|
extension ActiveAppsTimelineProvider {
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ extension ActiveAppsTimelineProvider {
|
|||||||
// this dummy data is for simulator (uncomment when testing ActiveAppsWidget pagination)
|
// this dummy data is for simulator (uncomment when testing ActiveAppsWidget pagination)
|
||||||
if (apps.count > 0){
|
if (apps.count > 0){
|
||||||
let app = apps[0]
|
let app = apps[0]
|
||||||
for i in 0..<10 {
|
for i in 1...10 {
|
||||||
let name = "\(app.name) - \(i)"
|
let name = "\(app.name) - \(i)"
|
||||||
let x = AppSnapshot(name: name,
|
let x = AppSnapshot(name: name,
|
||||||
bundleIdentifier: app.bundleIdentifier,
|
bundleIdentifier: app.bundleIdentifier,
|
||||||
|
|||||||
@@ -8,77 +8,88 @@
|
|||||||
|
|
||||||
import WidgetKit
|
import WidgetKit
|
||||||
|
|
||||||
protocol Navigation{
|
protocol WidgetInfo{
|
||||||
var direction: Direction? { get }
|
var ID: Int? { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(iOS 17, *)
|
@available(iOS 17, *)
|
||||||
class ActiveAppsTimelineProvider: AppsTimelineProviderBase<Navigation> {
|
class ActiveAppsTimelineProvider<T: WidgetInfo>: AppsTimelineProviderBase<WidgetInfo> {
|
||||||
|
public struct WidgetData: WidgetInfo {
|
||||||
let uuid = UUID().uuidString
|
let ID: Int?
|
||||||
|
}
|
||||||
|
|
||||||
private let dataHolder: PaginationDataHolder
|
private let dataHolder: PaginationDataHolder
|
||||||
private let widgetID: String
|
private let widgetID: String
|
||||||
|
|
||||||
init(kind: String){
|
init(kind: String){
|
||||||
print("Executing ActiveAppsTimelineProvider.init() for instance \(uuid)")
|
|
||||||
|
|
||||||
let itemsPerPage = ActiveAppsWidget.Constants.MAX_ROWS_PER_PAGE
|
let itemsPerPage = ActiveAppsWidget.Constants.MAX_ROWS_PER_PAGE
|
||||||
self.dataHolder = PaginationDataHolder(itemsPerPage: itemsPerPage)
|
self.dataHolder = PaginationDataHolder(itemsPerPage: itemsPerPage)
|
||||||
self.widgetID = kind
|
self.widgetID = kind
|
||||||
}
|
}
|
||||||
|
|
||||||
override func getUpdatedData(_ apps: [AppSnapshot], _ context: Navigation?) -> [AppSnapshot] {
|
deinit{
|
||||||
guard let context = context else { return apps }
|
// if this provider goes out of scope, clear all entries
|
||||||
|
PageInfoManager.shared.clearAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func getUpdatedData(_ apps: [AppSnapshot], _ context: WidgetInfo?) -> [AppSnapshot] {
|
||||||
var apps = apps
|
var apps = apps
|
||||||
|
|
||||||
// #if DEBUG
|
#if targetEnvironment(simulator)
|
||||||
// apps = getSimulatedData(apps: apps)
|
apps = getSimulatedData(apps: apps)
|
||||||
// #endif
|
#endif
|
||||||
|
|
||||||
if let direction = context.direction{
|
var currentPageApps = dataHolder.currentPage(inItems: apps)
|
||||||
// get paged data if available
|
if let widgetInfo = context,
|
||||||
switch (direction){
|
let widgetID = widgetInfo.ID {
|
||||||
case Direction.up:
|
|
||||||
apps = dataHolder.prevPage(inItems: apps, whenUnavailable: .current)!
|
var navEvent: NavigationEvent? = PageInfoManager.shared.getPageInfo(for: widgetID)
|
||||||
case Direction.down:
|
if let event = navEvent,
|
||||||
apps = dataHolder.nextPage(inItems: apps, whenUnavailable: .current)!
|
let direction = event.direction
|
||||||
|
{
|
||||||
|
// process navigation request only if event wasn't consumed yet
|
||||||
|
if !event.consumed {
|
||||||
|
switch (direction){
|
||||||
|
case Direction.up:
|
||||||
|
currentPageApps = dataHolder.prevPage(inItems: apps, whenUnavailable: .current)!
|
||||||
|
case Direction.down:
|
||||||
|
currentPageApps = dataHolder.nextPage(inItems: apps, whenUnavailable: .current)!
|
||||||
|
}
|
||||||
|
// mark the event as consumed
|
||||||
|
// this prevents duplicate getUpdatedData() requests for same navigation event
|
||||||
|
navEvent!.consumed = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
PageInfoManager.shared.setPageInfo(for: widgetID, value: navEvent)
|
||||||
// retain what ever page we were on as-is
|
|
||||||
apps = dataHolder.currentPage(inItems: apps)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return apps
|
return currentPageApps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// TimelineProvider for WidgetAppIntentConfiguration widget type
|
||||||
@available(iOS 17, *)
|
@available(iOS 17, *)
|
||||||
extension ActiveAppsTimelineProvider: AppIntentTimelineProvider {
|
extension ActiveAppsTimelineProvider: AppIntentTimelineProvider {
|
||||||
|
|
||||||
struct IntentData: Navigation{
|
|
||||||
let direction: Direction?
|
|
||||||
}
|
|
||||||
|
|
||||||
typealias Intent = WidgetUpdateIntent
|
typealias Intent = WidgetUpdateIntent
|
||||||
|
|
||||||
func snapshot(for intent: Intent, in context: Context) async -> AppsEntry {
|
func snapshot(for intent: Intent, in context: Context) async -> AppsEntry<WidgetInfo> {
|
||||||
let data = IntentData(direction: intent.getDirection(widgetID))
|
// system retains the previously configured ID value and posts the same here
|
||||||
|
let widgetData = WidgetData(ID: intent.ID)
|
||||||
|
|
||||||
let bundleIDs = await super.fetchActiveAppBundleIDs()
|
let bundleIDs = await super.fetchActiveAppBundleIDs()
|
||||||
|
let snapshot = await self.snapshot(for: bundleIDs, in: widgetData)
|
||||||
let snapshot = await self.snapshot(for: bundleIDs, in: data)
|
|
||||||
|
|
||||||
return snapshot
|
return snapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
func timeline(for intent: Intent, in context: Context) async -> Timeline<AppsEntry> {
|
func timeline(for intent: Intent, in context: Context) async -> Timeline<AppsEntry<WidgetInfo>> {
|
||||||
let data = IntentData(direction: intent.getDirection(widgetID))
|
// system retains the previously configured ID value and posts the same here
|
||||||
|
let widgetData = WidgetData(ID: intent.ID)
|
||||||
|
|
||||||
let bundleIDs = await self.fetchActiveAppBundleIDs()
|
let bundleIDs = await self.fetchActiveAppBundleIDs()
|
||||||
|
let timeline = await self.timeline(for: bundleIDs, in: widgetData)
|
||||||
let timeline = await self.timeline(for: bundleIDs, in: data)
|
|
||||||
|
|
||||||
return timeline
|
return timeline
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,25 +11,28 @@ import CoreData
|
|||||||
|
|
||||||
import AltStoreCore
|
import AltStoreCore
|
||||||
|
|
||||||
struct AppsEntry: TimelineEntry
|
struct AppsEntry<T>: TimelineEntry
|
||||||
{
|
{
|
||||||
var date: Date
|
var date: Date
|
||||||
var relevance: TimelineEntryRelevance?
|
var relevance: TimelineEntryRelevance?
|
||||||
|
|
||||||
var apps: [AppSnapshot]
|
var apps: [AppSnapshot]
|
||||||
var isPlaceholder: Bool = false
|
var isPlaceholder: Bool = false
|
||||||
|
|
||||||
|
var context: T?
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppsTimelineProviderBase<T>
|
class AppsTimelineProviderBase<T>
|
||||||
{
|
{
|
||||||
typealias Entry = AppsEntry
|
typealias Entry = AppsEntry
|
||||||
|
|
||||||
func placeholder(in context: TimelineProviderContext) -> AppsEntry
|
func placeholder(in context: TimelineProviderContext) -> AppsEntry<T>
|
||||||
{
|
{
|
||||||
return AppsEntry(date: Date(), apps: [], isPlaceholder: true)
|
return AppsEntry(date: Date(), apps: [], isPlaceholder: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func snapshot(for appBundleIDs: [String], in context: T? = nil) async -> AppsEntry
|
func snapshot(for appBundleIDs: [String], in context: T? = nil) async -> AppsEntry<T>
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -39,19 +42,19 @@ class AppsTimelineProviderBase<T>
|
|||||||
|
|
||||||
apps = getUpdatedData(apps, context)
|
apps = getUpdatedData(apps, context)
|
||||||
|
|
||||||
let entry = AppsEntry(date: Date(), apps: apps)
|
let entry = AppsEntry(date: Date(), apps: apps, context: context)
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
print("Failed to prepare widget snapshot:", error)
|
print("Failed to prepare widget snapshot:", error)
|
||||||
|
|
||||||
let entry = AppsEntry(date: Date(), apps: [])
|
let entry = AppsEntry(date: Date(), apps: [], context: context)
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func timeline(for appBundleIDs: [String], in context: T? = nil) async -> Timeline<AppsEntry>
|
func timeline(for appBundleIDs: [String], in context: T? = nil) async -> Timeline<AppsEntry<T>>
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -61,7 +64,14 @@ class AppsTimelineProviderBase<T>
|
|||||||
|
|
||||||
apps = getUpdatedData(apps, context)
|
apps = getUpdatedData(apps, context)
|
||||||
|
|
||||||
let entries = self.makeEntries(for: apps)
|
var entries = self.makeEntries(for: apps, in: context)
|
||||||
|
|
||||||
|
// #if targetEnvironment(simulator)
|
||||||
|
// if let first = entries.first{
|
||||||
|
// entries = [first]
|
||||||
|
// }
|
||||||
|
// #endif
|
||||||
|
|
||||||
let timeline = Timeline(entries: entries, policy: .atEnd)
|
let timeline = Timeline(entries: entries, policy: .atEnd)
|
||||||
return timeline
|
return timeline
|
||||||
}
|
}
|
||||||
@@ -69,7 +79,7 @@ class AppsTimelineProviderBase<T>
|
|||||||
{
|
{
|
||||||
print("Failed to prepare widget timeline:", error)
|
print("Failed to prepare widget timeline:", error)
|
||||||
|
|
||||||
let entry = AppsEntry(date: Date(), apps: [])
|
let entry = AppsEntry(date: Date(), apps: [], context: context)
|
||||||
let timeline = Timeline(entries: [entry], policy: .atEnd)
|
let timeline = Timeline(entries: [entry], policy: .atEnd)
|
||||||
return timeline
|
return timeline
|
||||||
}
|
}
|
||||||
@@ -109,7 +119,7 @@ extension AppsTimelineProviderBase
|
|||||||
return apps
|
return apps
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeEntries(for snapshots: [AppSnapshot]) -> [AppsEntry]
|
func makeEntries(for snapshots: [AppSnapshot], in context: T? = nil) -> [AppsEntry<T>]
|
||||||
{
|
{
|
||||||
let sortedAppsByExpirationDate = snapshots.sorted { $0.expirationDate < $1.expirationDate }
|
let sortedAppsByExpirationDate = snapshots.sorted { $0.expirationDate < $1.expirationDate }
|
||||||
guard let firstExpiringApp = sortedAppsByExpirationDate.first, let lastExpiringApp = sortedAppsByExpirationDate.last else { return [] }
|
guard let firstExpiringApp = sortedAppsByExpirationDate.first, let lastExpiringApp = sortedAppsByExpirationDate.last else { return [] }
|
||||||
@@ -118,16 +128,16 @@ extension AppsTimelineProviderBase
|
|||||||
let numberOfDays = lastExpiringApp.expirationDate.numberOfCalendarDays(since: currentDate)
|
let numberOfDays = lastExpiringApp.expirationDate.numberOfCalendarDays(since: currentDate)
|
||||||
|
|
||||||
// Generate a timeline consisting of one entry per day.
|
// Generate a timeline consisting of one entry per day.
|
||||||
var entries: [AppsEntry] = []
|
var entries: [AppsEntry<T>] = []
|
||||||
|
|
||||||
switch numberOfDays
|
switch numberOfDays
|
||||||
{
|
{
|
||||||
case ..<0:
|
case ..<0:
|
||||||
let entry = AppsEntry(date: currentDate, relevance: TimelineEntryRelevance(score: 0.0), apps: snapshots)
|
let entry = AppsEntry(date: currentDate, relevance: TimelineEntryRelevance(score: 0.0), apps: snapshots, context: context)
|
||||||
entries.append(entry)
|
entries.append(entry)
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
let entry = AppsEntry(date: currentDate, relevance: TimelineEntryRelevance(score: 1.0), apps: snapshots)
|
let entry = AppsEntry(date: currentDate, relevance: TimelineEntryRelevance(score: 1.0), apps: snapshots, context: context)
|
||||||
entries.append(entry)
|
entries.append(entry)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -151,7 +161,7 @@ extension AppsTimelineProviderBase
|
|||||||
score = 0
|
score = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
let entry = AppsEntry(date: entryDate, relevance: TimelineEntryRelevance(score: score), apps: snapshots)
|
let entry = AppsEntry(date: entryDate, relevance: TimelineEntryRelevance(score: score), apps: snapshots, context: context)
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,11 +198,11 @@ extension AppsTimelineProviderBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppsTimelineProvider: AppsTimelineProviderBase<ViewAppIntent>, IntentTimelineProvider
|
typealias Intent = ViewAppIntent
|
||||||
{
|
|
||||||
typealias Intent = ViewAppIntent
|
|
||||||
|
|
||||||
func getSnapshot(for intent: Intent, in context: Context, completion: @escaping (AppsEntry) -> Void)
|
class AppsTimelineProvider: AppsTimelineProviderBase<Intent>, IntentTimelineProvider
|
||||||
|
{
|
||||||
|
func getSnapshot(for intent: Intent, in context: Context, completion: @escaping (AppsEntry<Intent>) -> Void)
|
||||||
{
|
{
|
||||||
Task<Void, Never> {
|
Task<Void, Never> {
|
||||||
let bundleIDs = [intent.app?.identifier ?? StoreApp.altstoreAppID]
|
let bundleIDs = [intent.app?.identifier ?? StoreApp.altstoreAppID]
|
||||||
@@ -202,7 +212,7 @@ class AppsTimelineProvider: AppsTimelineProviderBase<ViewAppIntent>, IntentTimel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTimeline(for intent: Intent, in context: Context, completion: @escaping (Timeline<AppsEntry>) -> Void)
|
func getTimeline(for intent: Intent, in context: Context, completion: @escaping (Timeline<AppsEntry<Intent>>) -> Void)
|
||||||
{
|
{
|
||||||
Task<Void, Never> {
|
Task<Void, Never> {
|
||||||
let bundleIDs = [intent.app?.identifier ?? StoreApp.altstoreAppID]
|
let bundleIDs = [intent.app?.identifier ?? StoreApp.altstoreAppID]
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import WidgetKit
|
|||||||
|
|
||||||
import AltStoreCore
|
import AltStoreCore
|
||||||
|
|
||||||
|
import GameplayKit
|
||||||
|
|
||||||
private extension Color
|
private extension Color
|
||||||
{
|
{
|
||||||
static let altGradientLight = Color.init(.displayP3, red: 123.0/255.0, green: 200.0/255.0, blue: 176.0/255.0)
|
static let altGradientLight = Color.init(.displayP3, red: 123.0/255.0, green: 200.0/255.0, blue: 176.0/255.0)
|
||||||
@@ -19,6 +21,9 @@ private extension Color
|
|||||||
static let altGradientExtraDark = Color.init(.displayP3, red: 2.0/255.0, green: 82.0/255.0, blue: 103.0/255.0)
|
static let altGradientExtraDark = Color.init(.displayP3, red: 2.0/255.0, green: 82.0/255.0, blue: 103.0/255.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct WidgetTag: WidgetInfo{
|
||||||
|
let ID: Int?
|
||||||
|
}
|
||||||
|
|
||||||
//@available(iOS 17, *)
|
//@available(iOS 17, *)
|
||||||
struct ActiveAppsWidget: Widget
|
struct ActiveAppsWidget: Widget
|
||||||
@@ -27,22 +32,17 @@ struct ActiveAppsWidget: Widget
|
|||||||
static let MAX_ROWS_PER_PAGE: UInt = 3
|
static let MAX_ROWS_PER_PAGE: UInt = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
let ID = UUID().uuidString
|
|
||||||
|
|
||||||
public var body: some WidgetConfiguration {
|
public var body: some WidgetConfiguration {
|
||||||
print("Executing ActiveAppsWidget.body for instance \(ID)")
|
|
||||||
|
|
||||||
if #available(iOS 17, *)
|
if #available(iOS 17, *)
|
||||||
{
|
{
|
||||||
let widgetID = "ActiveApps - \(UUID().uuidString)"
|
let widgetID = "ActiveApps - \(UUID().uuidString)"
|
||||||
|
|
||||||
let widgetConfig = AppIntentConfiguration(
|
let widgetConfig = AppIntentConfiguration(
|
||||||
kind: widgetID,
|
kind: widgetID,
|
||||||
// intent: PaginationIntent.self, // Use the defined AppIntent
|
intent: WidgetUpdateIntent.self,
|
||||||
intent: WidgetUpdateIntent.self, // Use the defined AppIntent
|
provider: ActiveAppsTimelineProvider<WidgetTag>(kind: widgetID)
|
||||||
provider: ActiveAppsTimelineProvider(kind: widgetID)
|
|
||||||
) { entry in
|
) { entry in
|
||||||
ActiveAppsWidgetView(entry: entry, widgetID: widgetID)
|
ActiveAppsWidgetView(entry: entry)
|
||||||
}
|
}
|
||||||
.supportedFamilies([.systemMedium])
|
.supportedFamilies([.systemMedium])
|
||||||
.configurationDisplayName("Active Apps")
|
.configurationDisplayName("Active Apps")
|
||||||
@@ -62,17 +62,7 @@ struct ActiveAppsWidget: Widget
|
|||||||
@available(iOS 17, *)
|
@available(iOS 17, *)
|
||||||
private struct ActiveAppsWidgetView: View
|
private struct ActiveAppsWidgetView: View
|
||||||
{
|
{
|
||||||
var entry: AppsEntry
|
var entry: AppsEntry<WidgetInfo>
|
||||||
var widgetID: String
|
|
||||||
|
|
||||||
let ID = UUID().uuidString
|
|
||||||
|
|
||||||
init(entry: AppsEntry, widgetID: String) {
|
|
||||||
print("Executing ActiveAppsWidgetView.init() for instance \(ID)")
|
|
||||||
|
|
||||||
self.entry = entry
|
|
||||||
self.widgetID = widgetID
|
|
||||||
}
|
|
||||||
|
|
||||||
@Environment(\.colorScheme)
|
@Environment(\.colorScheme)
|
||||||
private var colorScheme
|
private var colorScheme
|
||||||
@@ -103,104 +93,131 @@ private struct ActiveAppsWidgetView: View
|
|||||||
|
|
||||||
private var content: some View {
|
private var content: some View {
|
||||||
GeometryReader { (geometry) in
|
GeometryReader { (geometry) in
|
||||||
|
|
||||||
let itemsPerPage = ActiveAppsWidget.Constants.MAX_ROWS_PER_PAGE
|
|
||||||
|
|
||||||
let preferredRowHeight = (geometry.size.height / Double(itemsPerPage)) - 8
|
|
||||||
let rowHeight = min(preferredRowHeight, geometry.size.height / 2)
|
|
||||||
|
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
LazyVStack(spacing: 12) {
|
|
||||||
ForEach(Array(entry.apps.enumerated()), id: \.offset) { index, app in
|
|
||||||
|
|
||||||
let icon: UIImage = app.icon ?? UIImage(named: "SideStore")!
|
appsListView(reader: geometry)
|
||||||
|
|
||||||
// 1024x1024 images are not supported by previews but supported by device
|
|
||||||
// so we scale the image to 97% so as to reduce its actual size but not too much
|
|
||||||
// to somewhere below value, acceptable by previews ie < 1042x948
|
|
||||||
let scalingFactor = 0.97
|
|
||||||
|
|
||||||
let resizedSize = CGSize(
|
|
||||||
width: icon.size.width * scalingFactor,
|
|
||||||
height: icon.size.height * scalingFactor
|
|
||||||
)
|
|
||||||
|
|
||||||
let resizedIcon = icon.resizing(to: resizedSize)!
|
|
||||||
|
|
||||||
let daysRemaining = app.expirationDate.numberOfCalendarDays(since: entry.date)
|
|
||||||
let cornerRadius = rowHeight / 5.0
|
|
||||||
|
|
||||||
HStack(spacing: 10) {
|
|
||||||
Image(uiImage: resizedIcon)
|
|
||||||
.resizable()
|
|
||||||
.aspectRatio(contentMode: .fit)
|
|
||||||
.cornerRadius(cornerRadius)
|
|
||||||
|
|
||||||
VStack(alignment: .leading, spacing: 1) {
|
|
||||||
Text(app.name)
|
|
||||||
.font(.system(size: 15, weight: .semibold, design: .rounded))
|
|
||||||
|
|
||||||
let text = if entry.date > app.expirationDate
|
|
||||||
{
|
|
||||||
Text("Expired")
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Text("Expires in \(daysRemaining) ") + (daysRemaining == 1 ? Text("day") : Text("days"))
|
|
||||||
}
|
|
||||||
|
|
||||||
text
|
|
||||||
.font(.system(size: 13, weight: .semibold, design: .rounded))
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Countdown(startDate: app.refreshedDate,
|
|
||||||
endDate: app.expirationDate,
|
|
||||||
currentDate: entry.date,
|
|
||||||
strokeWidth: 3.0) // Slightly thinner circle stroke width
|
|
||||||
.background {
|
|
||||||
Color.black.opacity(0.1)
|
|
||||||
.mask(Capsule())
|
|
||||||
.padding(.all, -5)
|
|
||||||
}
|
|
||||||
.font(.system(size: 16, weight: .semibold, design: .rounded))
|
|
||||||
// this modifier invalidates the view (disables userinteraction and shows a blinking effect)
|
|
||||||
// until new timeline events occur, unless a observable boolean state is presented as parameter
|
|
||||||
.invalidatableContent()
|
|
||||||
.activatesRefreshAllAppsIntent()
|
|
||||||
}
|
|
||||||
.frame(height: rowHeight)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(minLength: 16)
|
Spacer(minLength: 16)
|
||||||
|
|
||||||
let buttonWidth: CGFloat = 16
|
navigationBarView()
|
||||||
VStack {
|
|
||||||
Image(systemName: "arrow.up")
|
|
||||||
.resizable()
|
|
||||||
.frame(width: buttonWidth, height: buttonWidth)
|
|
||||||
.opacity(0.3)
|
|
||||||
// .mask(Capsule())
|
|
||||||
.pageUpButton(widgetID)
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Image(systemName: "arrow.down")
|
|
||||||
.resizable()
|
|
||||||
.frame(width: buttonWidth, height: buttonWidth)
|
|
||||||
.opacity(0.3)
|
|
||||||
// .mask(Capsule())
|
|
||||||
.pageDownButton(widgetID)
|
|
||||||
}
|
|
||||||
.padding(.vertical)
|
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func appsListView(reader: GeometryProxy) -> some View {
|
||||||
|
let itemsPerPage = ActiveAppsWidget.Constants.MAX_ROWS_PER_PAGE
|
||||||
|
|
||||||
|
let preferredRowHeight = (reader.size.height / Double(itemsPerPage)) - 8
|
||||||
|
let rowHeight = min(preferredRowHeight, reader.size.height / 2)
|
||||||
|
|
||||||
|
return LazyVStack(spacing: 12) {
|
||||||
|
ForEach(Array(entry.apps.enumerated()), id: \.offset) { index, app in
|
||||||
|
|
||||||
|
appEntryRowView(app: app, rowHeight: rowHeight)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private func appEntryRowView(app: AppSnapshot, rowHeight: Double) -> some View {
|
||||||
|
let icon: UIImage = app.icon ?? UIImage(named: "SideStore")!
|
||||||
|
|
||||||
|
// 1024x1024 images are not supported by previews but supported by device
|
||||||
|
// so we scale the image to 97% so as to reduce its actual size but not too much
|
||||||
|
// to somewhere below value, acceptable by previews ie < 1042x948
|
||||||
|
let scalingFactor = 0.97
|
||||||
|
|
||||||
|
let resizedSize = CGSize(
|
||||||
|
width: icon.size.width * scalingFactor,
|
||||||
|
height: icon.size.height * scalingFactor
|
||||||
|
)
|
||||||
|
|
||||||
|
let resizedIcon = icon.resizing(to: resizedSize)!
|
||||||
|
let cornerRadius = rowHeight / 5.0
|
||||||
|
|
||||||
|
return HStack(spacing: 10) {
|
||||||
|
Image(uiImage: resizedIcon)
|
||||||
|
.resizable()
|
||||||
|
.aspectRatio(contentMode: .fit)
|
||||||
|
.cornerRadius(cornerRadius)
|
||||||
|
|
||||||
|
appDetailsView(app)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
countDownView(app)
|
||||||
|
|
||||||
|
}
|
||||||
|
.frame(height: rowHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private func appDetailsView(_ app: AppSnapshot) -> some View {
|
||||||
|
let daysRemaining = app.expirationDate.numberOfCalendarDays(since: entry.date)
|
||||||
|
|
||||||
|
return VStack(alignment: .leading, spacing: 1) {
|
||||||
|
Text(app.name)
|
||||||
|
.font(.system(size: 15, weight: .semibold, design: .rounded))
|
||||||
|
|
||||||
|
let text = if entry.date > app.expirationDate
|
||||||
|
{
|
||||||
|
Text("Expired")
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Text("Expires in \(daysRemaining) ") + (daysRemaining == 1 ? Text("day") : Text("days"))
|
||||||
|
}
|
||||||
|
|
||||||
|
text
|
||||||
|
.font(.system(size: 13, weight: .semibold, design: .rounded))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func countDownView(_ app: AppSnapshot) -> some View {
|
||||||
|
Countdown(startDate: app.refreshedDate,
|
||||||
|
endDate: app.expirationDate,
|
||||||
|
currentDate: entry.date,
|
||||||
|
strokeWidth: 3.0) // Slightly thinner circle stroke width
|
||||||
|
.background {
|
||||||
|
Color.black.opacity(0.1)
|
||||||
|
.mask(Capsule())
|
||||||
|
.padding(.all, -5)
|
||||||
|
}
|
||||||
|
.font(.system(size: 16, weight: .semibold, design: .rounded))
|
||||||
|
// this modifier invalidates the view (disables user interaction and shows a blinking effect)
|
||||||
|
.invalidatableContent()
|
||||||
|
.activatesRefreshAllAppsIntent()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private func navigationBarView() -> some View {
|
||||||
|
let buttonWidth: CGFloat = 16
|
||||||
|
let widgetID = entry.context?.ID
|
||||||
|
|
||||||
|
return VStack {
|
||||||
|
Image(systemName: "arrow.up")
|
||||||
|
.resizable()
|
||||||
|
.frame(width: buttonWidth, height: buttonWidth)
|
||||||
|
.opacity(0.3)
|
||||||
|
// .mask(Capsule())
|
||||||
|
.pageUpButton(widgetID)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Image(systemName: "arrow.down")
|
||||||
|
.resizable()
|
||||||
|
.frame(width: buttonWidth, height: buttonWidth)
|
||||||
|
.opacity(0.3)
|
||||||
|
// .mask(Capsule())
|
||||||
|
.pageDownButton(widgetID)
|
||||||
|
}
|
||||||
|
.padding(.vertical)
|
||||||
|
}
|
||||||
|
|
||||||
private var placeholder: some View {
|
private var placeholder: some View {
|
||||||
Text("App Not Found")
|
Text("App Not Found")
|
||||||
.font(.system(.body, design: .rounded))
|
.font(.system(.body, design: .rounded))
|
||||||
@@ -216,14 +233,14 @@ private struct ActiveAppsWidgetView: View
|
|||||||
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
||||||
let (altstore, delta, clip, longAltStore, longDelta, longClip) = AppSnapshot.makePreviewSnapshots()
|
let (altstore, delta, clip, longAltStore, longDelta, longClip) = AppSnapshot.makePreviewSnapshots()
|
||||||
|
|
||||||
AppsEntry(date: Date(), apps: [altstore, delta, clip])
|
AppsEntry<Any>(date: Date(), apps: [altstore, delta, clip])
|
||||||
AppsEntry(date: Date(), apps: [longAltStore, longDelta, longClip])
|
AppsEntry<Any>(date: Date(), apps: [longAltStore, longDelta, longClip])
|
||||||
|
|
||||||
AppsEntry(date: expiredDate, apps: [altstore, delta, clip])
|
AppsEntry<Any>(date: expiredDate, apps: [altstore, delta, clip])
|
||||||
|
|
||||||
AppsEntry(date: Date(), apps: [altstore, delta])
|
AppsEntry<Any>(date: Date(), apps: [altstore, delta])
|
||||||
AppsEntry(date: Date(), apps: [altstore])
|
AppsEntry<Any>(date: Date(), apps: [altstore])
|
||||||
|
|
||||||
AppsEntry(date: Date(), apps: [])
|
AppsEntry<Any>(date: Date(), apps: [])
|
||||||
AppsEntry(date: Date(), apps: [], isPlaceholder: true)
|
AppsEntry<Any>(date: Date(), apps: [], isPlaceholder: true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ struct AppDetailWidget: Widget
|
|||||||
|
|
||||||
private struct AppDetailWidgetView: View
|
private struct AppDetailWidgetView: View
|
||||||
{
|
{
|
||||||
var entry: AppsEntry
|
var entry: AppsEntry<Intent>
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Group {
|
Group {
|
||||||
@@ -200,11 +200,11 @@ private extension AppDetailWidgetView
|
|||||||
} timeline: {
|
} timeline: {
|
||||||
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
||||||
let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots()
|
let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots()
|
||||||
AppsEntry(date: Date(), apps: [altstore])
|
AppsEntry<Any>(date: Date(), apps: [altstore])
|
||||||
AppsEntry(date: Date(), apps: [longAltStore])
|
AppsEntry<Any>(date: Date(), apps: [longAltStore])
|
||||||
|
|
||||||
AppsEntry(date: expiredDate, apps: [altstore])
|
AppsEntry<Any>(date: expiredDate, apps: [altstore])
|
||||||
|
|
||||||
AppsEntry(date: Date(), apps: [])
|
AppsEntry<Any>(date: Date(), apps: [])
|
||||||
AppsEntry(date: Date(), apps: [], isPlaceholder: true)
|
AppsEntry<Any>(date: Date(), apps: [], isPlaceholder: true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ extension ComplicationView
|
|||||||
@available(iOS 16, *)
|
@available(iOS 16, *)
|
||||||
private struct ComplicationView: View
|
private struct ComplicationView: View
|
||||||
{
|
{
|
||||||
let entry: AppsEntry
|
let entry: AppsEntry<Intent>
|
||||||
let style: Style
|
let style: Style
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -144,10 +144,10 @@ private let widgetFamily = if #available(iOS 16, *) { WidgetFamily.accessoryCirc
|
|||||||
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
||||||
let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots()
|
let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots()
|
||||||
|
|
||||||
AppsEntry(date: Date(), apps: [altstore])
|
AppsEntry<Any>(date: Date(), apps: [altstore])
|
||||||
AppsEntry(date: Date(), apps: [longAltStore])
|
AppsEntry<Any>(date: Date(), apps: [longAltStore])
|
||||||
|
|
||||||
AppsEntry(date: expiredDate, apps: [altstore])
|
AppsEntry<Any>(date: expiredDate, apps: [altstore])
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(iOS 17, *)
|
@available(iOS 17, *)
|
||||||
@@ -157,8 +157,8 @@ private let widgetFamily = if #available(iOS 16, *) { WidgetFamily.accessoryCirc
|
|||||||
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
||||||
let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots()
|
let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots()
|
||||||
|
|
||||||
AppsEntry(date: Date(), apps: [altstore])
|
AppsEntry<Any>(date: Date(), apps: [altstore])
|
||||||
AppsEntry(date: Date(), apps: [longAltStore])
|
AppsEntry<Any>(date: Date(), apps: [longAltStore])
|
||||||
|
|
||||||
AppsEntry(date: expiredDate, apps: [altstore])
|
AppsEntry<Any>(date: expiredDate, apps: [altstore])
|
||||||
}
|
}
|
||||||
|
|||||||
30
SideStore/Utils/datastructures/SingletonGenericMap.swift
Normal file
30
SideStore/Utils/datastructures/SingletonGenericMap.swift
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// SingletonGenericMap.swift
|
||||||
|
// SideStore
|
||||||
|
//
|
||||||
|
// Created by Magesh K on 10/01/25.
|
||||||
|
// Copyright © 2025 SideStore. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
class SingletonGenericMap{
|
||||||
|
static var shared = SingletonGenericMap()
|
||||||
|
private var pageInfoMap: [AnyHashable: Any] = [:]
|
||||||
|
|
||||||
|
private init() {}
|
||||||
|
|
||||||
|
func setPageInfo<T: Hashable, U>(for key: T, value: U?) {
|
||||||
|
pageInfoMap[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPageInfo<T: Hashable, U>(for key: T) -> U? {
|
||||||
|
return pageInfoMap[key] as? U
|
||||||
|
}
|
||||||
|
|
||||||
|
func popPageInfo<T: Hashable, U>(for key: T) -> U? {
|
||||||
|
return pageInfoMap.removeValue(forKey: key) as? U
|
||||||
|
}
|
||||||
|
|
||||||
|
func clearAll() {
|
||||||
|
pageInfoMap.removeAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user