mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Adds iOS 16 Lock Screen widget
This commit is contained in:
@@ -173,8 +173,7 @@ struct Provider: IntentTimelineProvider
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct AltWidget: Widget
|
||||
struct HomeScreenWidget: Widget
|
||||
{
|
||||
private let kind: String = "AppDetail"
|
||||
|
||||
@@ -189,3 +188,35 @@ struct AltWidget: Widget
|
||||
.description("View remaining days until your sideloaded apps expire.")
|
||||
}
|
||||
}
|
||||
|
||||
struct LockScreenWidget: Widget
|
||||
{
|
||||
private let kind: String = "LockAppDetail"
|
||||
|
||||
public var body: some WidgetConfiguration {
|
||||
if #available(iOSApplicationExtension 16, *)
|
||||
{
|
||||
return IntentConfiguration(kind: kind,
|
||||
intent: ViewAppIntent.self,
|
||||
provider: Provider()) { (entry) in
|
||||
ComplicationView(entry: entry)
|
||||
}
|
||||
.supportedFamilies([.accessoryCircular])
|
||||
.configurationDisplayName("AltWidget")
|
||||
.description("View remaining days until AltStore expires.")
|
||||
}
|
||||
else
|
||||
{
|
||||
return EmptyWidgetConfiguration()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct AltWidgets: WidgetBundle
|
||||
{
|
||||
var body: some Widget {
|
||||
HomeScreenWidget()
|
||||
LockScreenWidget()
|
||||
}
|
||||
}
|
||||
|
||||
86
AltWidget/ComplicationView.swift
Normal file
86
AltWidget/ComplicationView.swift
Normal file
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// ComplicationView.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 7/7/22.
|
||||
// Copyright © 2022 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
@available(iOS 16, *)
|
||||
struct ComplicationView: View
|
||||
{
|
||||
let entry: AppEntry
|
||||
|
||||
var body: some View {
|
||||
let refreshedDate = self.entry.app?.refreshedDate ?? .now
|
||||
let expirationDate = self.entry.app?.expirationDate ?? .now
|
||||
|
||||
let totalDays = expirationDate.numberOfCalendarDays(since: refreshedDate)
|
||||
let daysRemaining = expirationDate.numberOfCalendarDays(since: self.entry.date)
|
||||
|
||||
let progress = Double(daysRemaining) / Double(totalDays)
|
||||
|
||||
ZStack(alignment: .center) {
|
||||
ProgressRing(progress: progress) {
|
||||
if daysRemaining < 0
|
||||
{
|
||||
Text("Expired")
|
||||
.font(.system(size: 10, weight: .bold))
|
||||
}
|
||||
else
|
||||
{
|
||||
VStack(spacing: -1) {
|
||||
Text("\(daysRemaining)")
|
||||
.font(.system(size: 20, weight: .bold, design: .rounded))
|
||||
|
||||
Text(daysRemaining == 1 ? "DAY" : "DAYS")
|
||||
.font(.caption)
|
||||
}
|
||||
.offset(y: -1)
|
||||
}
|
||||
}
|
||||
}
|
||||
.unredacted()
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 16, *)
|
||||
struct ComplicationView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let shortRefreshedDate = Calendar.current.date(byAdding: .day, value: -2, to: Date()) ?? Date()
|
||||
let shortExpirationDate = Calendar.current.date(byAdding: .day, value: 7, to: shortRefreshedDate) ?? Date()
|
||||
|
||||
let longRefreshedDate = Calendar.current.date(byAdding: .day, value: -100, to: Date()) ?? Date()
|
||||
let longExpirationDate = Calendar.current.date(byAdding: .day, value: 365, to: longRefreshedDate) ?? Date()
|
||||
|
||||
let expiredDate = shortExpirationDate.addingTimeInterval(1 * 60 * 60 * 24)
|
||||
|
||||
let weekAltstore = AppSnapshot(name: "AltStore",
|
||||
bundleIdentifier: "com.rileytestut.AltStore",
|
||||
expirationDate: shortExpirationDate,
|
||||
refreshedDate: shortRefreshedDate,
|
||||
tintColor: .altPrimary,
|
||||
icon: UIImage(named: "AltStore"))
|
||||
|
||||
let yearAltstore = AppSnapshot(name: "AltStore",
|
||||
bundleIdentifier: "com.rileytestut.AltStore",
|
||||
expirationDate: longExpirationDate,
|
||||
refreshedDate: longRefreshedDate,
|
||||
tintColor: .altPrimary,
|
||||
icon: UIImage(named: "AltStore"))
|
||||
|
||||
return Group {
|
||||
ComplicationView(entry: AppEntry(date: Date(), app: weekAltstore))
|
||||
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
||||
|
||||
ComplicationView(entry: AppEntry(date: expiredDate, app: weekAltstore))
|
||||
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
||||
|
||||
ComplicationView(entry: AppEntry(date: longRefreshedDate, app: yearAltstore))
|
||||
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
||||
}
|
||||
}
|
||||
}
|
||||
54
AltWidget/ProgressRing.swift
Normal file
54
AltWidget/ProgressRing.swift
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// ProgressRing.swift
|
||||
// AltWidgetExtension
|
||||
//
|
||||
// Created by Riley Testut on 8/17/22.
|
||||
// Copyright © 2022 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
struct ProgressRing<Content: View>: View
|
||||
{
|
||||
let progress: Double
|
||||
|
||||
private let content: Content
|
||||
|
||||
init(progress: Double, @ViewBuilder content: () -> Content)
|
||||
{
|
||||
self.progress = progress
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .center) {
|
||||
ring(progress: 1.0)
|
||||
.opacity(0.3)
|
||||
|
||||
ring(progress: self.progress)
|
||||
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func ring(progress: Double) -> some View {
|
||||
let strokeStyle = StrokeStyle(lineWidth: 4.0, lineCap: .round, lineJoin: .round)
|
||||
|
||||
Circle()
|
||||
.inset(by: 2.0)
|
||||
.trim(from: 0.0, to: progress)
|
||||
.rotation(Angle(degrees: -90), anchor: .center)
|
||||
.stroke(style: strokeStyle)
|
||||
}
|
||||
}
|
||||
|
||||
struct ProgressRing_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ProgressRing(progress: 0.5) {
|
||||
EmptyView()
|
||||
}
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user