mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltWidget] Adds “icon” style lock screen widget
This commit is contained in:
committed by
Joseph Mattello
parent
d7d0a83550
commit
699eda5d1b
@@ -189,9 +189,9 @@ struct HomeScreenWidget: Widget
|
||||
}
|
||||
}
|
||||
|
||||
struct LockScreenWidget: Widget
|
||||
struct TextLockScreenWidget: Widget
|
||||
{
|
||||
private let kind: String = "LockAppDetail"
|
||||
private let kind: String = "TextLockAppDetail"
|
||||
|
||||
public var body: some WidgetConfiguration {
|
||||
if #available(iOSApplicationExtension 16, *)
|
||||
@@ -199,10 +199,10 @@ struct LockScreenWidget: Widget
|
||||
return IntentConfiguration(kind: kind,
|
||||
intent: ViewAppIntent.self,
|
||||
provider: Provider()) { (entry) in
|
||||
ComplicationView(entry: entry)
|
||||
ComplicationView(entry: entry, style: .text)
|
||||
}
|
||||
.supportedFamilies([.accessoryCircular])
|
||||
.configurationDisplayName("AltWidget")
|
||||
.configurationDisplayName("AltWidget (Text)")
|
||||
.description("View remaining days until SideStore expires.")
|
||||
}
|
||||
else
|
||||
@@ -212,11 +212,58 @@ struct LockScreenWidget: Widget
|
||||
}
|
||||
}
|
||||
|
||||
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 SideStore expires.")
|
||||
}
|
||||
else
|
||||
{
|
||||
return EmptyWidgetConfiguration()
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//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, style: .icon)
|
||||
// }
|
||||
// .supportedFamilies([.accessoryCircular])
|
||||
// .configurationDisplayName("AltWidget")
|
||||
// .description("View remaining days until SideStore expires.")
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return EmptyWidgetConfiguration()
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@main
|
||||
struct AltWidgets: WidgetBundle
|
||||
{
|
||||
var body: some Widget {
|
||||
HomeScreenWidget()
|
||||
LockScreenWidget()
|
||||
IconLockScreenWidget()
|
||||
TextLockScreenWidget()
|
||||
}
|
||||
}
|
||||
|
||||
16
AltWidget/Assets.xcassets/SmallIcon.imageset/Contents.json
vendored
Normal file
16
AltWidget/Assets.xcassets/SmallIcon.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "altminicon.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
BIN
AltWidget/Assets.xcassets/SmallIcon.imageset/altminicon.pdf
vendored
Normal file
BIN
AltWidget/Assets.xcassets/SmallIcon.imageset/altminicon.pdf
vendored
Normal file
Binary file not shown.
@@ -9,10 +9,21 @@
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
@available(iOS 16, *)
|
||||
extension ComplicationView
|
||||
{
|
||||
enum Style
|
||||
{
|
||||
case text
|
||||
case icon
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 16, *)
|
||||
struct ComplicationView: View
|
||||
{
|
||||
let entry: AppEntry
|
||||
let style: Style
|
||||
|
||||
var body: some View {
|
||||
let refreshedDate = self.entry.app?.refreshedDate ?? .now
|
||||
@@ -31,6 +42,9 @@ struct ComplicationView: View
|
||||
}
|
||||
else
|
||||
{
|
||||
switch self.style
|
||||
{
|
||||
case .text:
|
||||
VStack(spacing: -1) {
|
||||
let fontSize = daysRemaining > 99 ? 18.0 : 20.0
|
||||
Text("\(daysRemaining)")
|
||||
@@ -41,6 +55,29 @@ struct ComplicationView: View
|
||||
}
|
||||
.fixedSize()
|
||||
.offset(y: -1)
|
||||
|
||||
case .icon:
|
||||
ZStack {
|
||||
// Destination
|
||||
Image("SmallIcon")
|
||||
.resizable()
|
||||
.aspectRatio(1.0, contentMode: .fill)
|
||||
.scaleEffect(x: 0.8, y: 0.8)
|
||||
|
||||
// Source
|
||||
(
|
||||
daysRemaining > 7 ?
|
||||
Text("7+")
|
||||
.font(.system(size: 18, weight: .bold, design: .rounded))
|
||||
.kerning(-2) :
|
||||
|
||||
Text("\(daysRemaining)")
|
||||
.font(.system(size: 20, weight: .bold, design: .rounded))
|
||||
)
|
||||
.foregroundColor(Color.black)
|
||||
.blendMode(.destinationOut) // Clip text out of image.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.gaugeStyle(.accessoryCircularCapacity)
|
||||
@@ -74,13 +111,22 @@ struct ComplicationView_Previews: PreviewProvider {
|
||||
icon: UIImage(named: "AltStore"))
|
||||
|
||||
return Group {
|
||||
ComplicationView(entry: AppEntry(date: Date(), app: weekAltstore))
|
||||
ComplicationView(entry: AppEntry(date: Date(), app: weekAltstore), style: .icon)
|
||||
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
||||
|
||||
ComplicationView(entry: AppEntry(date: expiredDate, app: weekAltstore))
|
||||
ComplicationView(entry: AppEntry(date: expiredDate, app: weekAltstore), style: .icon)
|
||||
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
||||
|
||||
ComplicationView(entry: AppEntry(date: longRefreshedDate, app: yearAltstore))
|
||||
ComplicationView(entry: AppEntry(date: longRefreshedDate, app: yearAltstore), style: .icon)
|
||||
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
||||
|
||||
ComplicationView(entry: AppEntry(date: Date(), app: weekAltstore), style: .text)
|
||||
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
||||
|
||||
ComplicationView(entry: AppEntry(date: expiredDate, app: weekAltstore), style: .text)
|
||||
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
||||
|
||||
ComplicationView(entry: AppEntry(date: longRefreshedDate, app: yearAltstore), style: .text)
|
||||
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user