mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltWidget] Refactors widgets into separate files
This commit is contained in:
21
AltWidget/AltWidgetBundle.swift
Normal file
21
AltWidget/AltWidgetBundle.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// AltWidgetBundle.swift
|
||||
// AltWidgetExtension
|
||||
//
|
||||
// Created by Riley Testut on 8/22/23.
|
||||
// Copyright © 2023 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
@main
|
||||
struct AltWidgetBundle: WidgetBundle
|
||||
{
|
||||
var body: some Widget {
|
||||
AppDetailWidget()
|
||||
|
||||
IconLockScreenWidget()
|
||||
TextLockScreenWidget()
|
||||
}
|
||||
}
|
||||
41
AltWidget/Model/AppSnapshot.swift
Normal file
41
AltWidget/Model/AppSnapshot.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// AppsEntry.swift
|
||||
// AltWidgetExtension
|
||||
//
|
||||
// Created by Riley Testut on 8/22/23.
|
||||
// Copyright © 2023 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import WidgetKit
|
||||
|
||||
import AltStoreCore
|
||||
import AltSign
|
||||
|
||||
struct AppSnapshot
|
||||
{
|
||||
var name: String
|
||||
var bundleIdentifier: String
|
||||
var expirationDate: Date
|
||||
var refreshedDate: Date
|
||||
|
||||
var tintColor: UIColor?
|
||||
var icon: UIImage?
|
||||
}
|
||||
|
||||
extension AppSnapshot
|
||||
{
|
||||
// Declared in extension so we retain synthesized initializer.
|
||||
init(installedApp: InstalledApp)
|
||||
{
|
||||
self.name = installedApp.name
|
||||
self.bundleIdentifier = installedApp.bundleIdentifier
|
||||
self.expirationDate = installedApp.expirationDate
|
||||
self.refreshedDate = installedApp.refreshedDate
|
||||
|
||||
self.tintColor = installedApp.storeApp?.tintColor
|
||||
|
||||
let application = ALTApplication(fileURL: installedApp.fileURL)
|
||||
self.icon = application?.icon?.resizing(toFill: CGSize(width: 180, height: 180))
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
//
|
||||
// AltWidget.swift
|
||||
// AltWidget
|
||||
// Provider.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 6/26/20.
|
||||
// Copyright © 2020 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
import UIKit
|
||||
import CoreData
|
||||
|
||||
import AltStoreCore
|
||||
@@ -23,34 +21,6 @@ struct AppEntry: TimelineEntry
|
||||
var isPlaceholder: Bool = false
|
||||
}
|
||||
|
||||
struct AppSnapshot
|
||||
{
|
||||
var name: String
|
||||
var bundleIdentifier: String
|
||||
var expirationDate: Date
|
||||
var refreshedDate: Date
|
||||
|
||||
var tintColor: UIColor?
|
||||
var icon: UIImage?
|
||||
}
|
||||
|
||||
extension AppSnapshot
|
||||
{
|
||||
// Declared in extension so we retain synthesized initializer.
|
||||
init(installedApp: InstalledApp)
|
||||
{
|
||||
self.name = installedApp.name
|
||||
self.bundleIdentifier = installedApp.bundleIdentifier
|
||||
self.expirationDate = installedApp.expirationDate
|
||||
self.refreshedDate = installedApp.refreshedDate
|
||||
|
||||
self.tintColor = installedApp.storeApp?.tintColor
|
||||
|
||||
let application = ALTApplication(fileURL: installedApp.fileURL)
|
||||
self.icon = application?.icon?.resizing(toFill: CGSize(width: 180, height: 180))
|
||||
}
|
||||
}
|
||||
|
||||
struct Provider: IntentTimelineProvider
|
||||
{
|
||||
typealias Intent = ViewAppIntent
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// WidgetView.swift
|
||||
// AltStore
|
||||
// AppDetailWidget.swift
|
||||
// AltWidgetExtension
|
||||
//
|
||||
// Created by Riley Testut on 9/14/20.
|
||||
// Copyright © 2020 Riley Testut. All rights reserved.
|
||||
@@ -10,10 +10,34 @@ import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
import AltStoreCore
|
||||
import AltSign
|
||||
import CoreData
|
||||
|
||||
struct WidgetView : View
|
||||
struct AppDetailWidget: Widget
|
||||
{
|
||||
private let kind: String = "AppDetail"
|
||||
|
||||
public var body: some WidgetConfiguration {
|
||||
let configuration = IntentConfiguration(kind: kind,
|
||||
intent: ViewAppIntent.self,
|
||||
provider: Provider()) { (entry) in
|
||||
AppDetailWidgetView(entry: entry)
|
||||
}
|
||||
.supportedFamilies([.systemSmall])
|
||||
.configurationDisplayName("AltWidget")
|
||||
.description("View remaining days until your sideloaded apps expire.")
|
||||
|
||||
if #available(iOS 17, *)
|
||||
{
|
||||
return configuration
|
||||
.contentMarginsDisabled()
|
||||
}
|
||||
else
|
||||
{
|
||||
return configuration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct AppDetailWidgetView: View
|
||||
{
|
||||
var entry: AppEntry
|
||||
|
||||
@@ -110,7 +134,7 @@ struct WidgetView : View
|
||||
}
|
||||
}
|
||||
|
||||
private extension WidgetView
|
||||
private extension AppDetailWidgetView
|
||||
{
|
||||
func backgroundView(icon: UIImage? = nil, tintColor: UIColor? = nil) -> some View
|
||||
{
|
||||
@@ -178,19 +202,19 @@ struct WidgetView_Previews: PreviewProvider {
|
||||
icon: UIImage(named: "Delta"))
|
||||
|
||||
return Group {
|
||||
WidgetView(entry: AppEntry(date: Date(), app: altstore))
|
||||
AppDetailWidgetView(entry: AppEntry(date: Date(), app: altstore))
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
|
||||
WidgetView(entry: AppEntry(date: Date(), app: delta))
|
||||
AppDetailWidgetView(entry: AppEntry(date: Date(), app: delta))
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
|
||||
WidgetView(entry: AppEntry(date: Date(), app: expiredDelta))
|
||||
AppDetailWidgetView(entry: AppEntry(date: Date(), app: expiredDelta))
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
|
||||
WidgetView(entry: AppEntry(date: Date(), app: nil))
|
||||
AppDetailWidgetView(entry: AppEntry(date: Date(), app: nil))
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
|
||||
WidgetView(entry: AppEntry(date: Date(), app: nil, isPlaceholder: true))
|
||||
AppDetailWidgetView(entry: AppEntry(date: Date(), app: nil, isPlaceholder: true))
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// ComplicationView.swift
|
||||
// AltStore
|
||||
// LockScreenWidget.swift
|
||||
// AltWidget
|
||||
//
|
||||
// Created by Riley Testut on 7/7/22.
|
||||
// Copyright © 2022 Riley Testut. All rights reserved.
|
||||
@@ -9,10 +9,58 @@
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
import AltStoreCore
|
||||
|
||||
struct TextLockScreenWidget: Widget
|
||||
{
|
||||
private let kind: String = "TextLockAppDetail"
|
||||
|
||||
public var body: some WidgetConfiguration {
|
||||
if #available(iOSApplicationExtension 16, *)
|
||||
{
|
||||
return IntentConfiguration(kind: kind,
|
||||
intent: ViewAppIntent.self,
|
||||
provider: Provider()) { (entry) in
|
||||
ComplicationView(entry: entry, style: .text)
|
||||
}
|
||||
.supportedFamilies([.accessoryCircular])
|
||||
.configurationDisplayName("AltWidget (Text)")
|
||||
.description("View remaining days until AltStore expires.")
|
||||
}
|
||||
else
|
||||
{
|
||||
return EmptyWidgetConfiguration()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct IconLockScreenWidget: Widget
|
||||
{
|
||||
private let kind: String = "IconLockAppDetail"
|
||||
|
||||
public var body: some WidgetConfiguration {
|
||||
if #available(iOSApplicationExtension 16, *)
|
||||
{
|
||||
return IntentConfiguration(kind: kind,
|
||||
intent: ViewAppIntent.self,
|
||||
provider: Provider()) { (entry) in
|
||||
ComplicationView(entry: entry, style: .icon)
|
||||
}
|
||||
.supportedFamilies([.accessoryCircular])
|
||||
.configurationDisplayName("AltWidget (Icon)")
|
||||
.description("View remaining days until AltStore expires.")
|
||||
}
|
||||
else
|
||||
{
|
||||
return EmptyWidgetConfiguration()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 16, *)
|
||||
extension ComplicationView
|
||||
{
|
||||
enum Style
|
||||
fileprivate enum Style
|
||||
{
|
||||
case text
|
||||
case icon
|
||||
@@ -20,7 +68,7 @@ extension ComplicationView
|
||||
}
|
||||
|
||||
@available(iOS 16, *)
|
||||
struct ComplicationView: View
|
||||
private struct ComplicationView: View
|
||||
{
|
||||
let entry: AppEntry
|
||||
let style: Style
|
||||
Reference in New Issue
Block a user