feat: added Enable in Settings text to all macOS widgets

This commit is contained in:
Serhiy Mytrovtsiy
2026-03-21 16:48:28 +01:00
parent cbad11061b
commit 4511a96c3a
5 changed files with 48 additions and 10 deletions

View File

@@ -16,12 +16,13 @@ import Kit
public struct CPU_entry: TimelineEntry {
public static let kind = "CPUWidget"
public static var snapshot: CPU_entry = CPU_entry(value: CPU_Load(totalUsage: 0.34, systemLoad: 0.11, userLoad: 0.23, idleLoad: 0.66))
public static var snapshot: CPU_entry = CPU_entry(value: CPU_Load(totalUsage: 0.34, systemLoad: 0.11, userLoad: 0.23, idleLoad: 0.66), isPreview: true)
public var date: Date {
Calendar.current.date(byAdding: .second, value: 5, to: Date())!
}
public var value: CPU_Load? = nil
public var isPreview: Bool = false
}
public struct Provider: TimelineProvider {
@@ -63,7 +64,7 @@ public struct CPUWidget: Widget {
public var body: some WidgetConfiguration {
StaticConfiguration(kind: CPU_entry.kind, provider: Provider()) { entry in
VStack(spacing: 10) {
if Provider().systemWidgetsUpdatesState, let value = entry.value {
if Provider().systemWidgetsUpdatesState || entry.isPreview, let value = entry.value {
HStack {
Chart {
SectorMark(angle: .value(localizedString("System"), value.systemLoad), innerRadius: .ratio(0.8)).foregroundStyle(self.systemColor)

View File

@@ -16,12 +16,13 @@ import Kit
public struct Disk_entry: TimelineEntry {
public static let kind = "DiskWidget"
public static var snapshot: Disk_entry = Disk_entry(value: drive(size: 494384795648, free: 251460125440))
public static var snapshot: Disk_entry = Disk_entry(value: drive(size: 494384795648, free: 251460125440), isPreview: true)
public var date: Date {
Calendar.current.date(byAdding: .second, value: 5, to: Date())!
}
public var value: drive? = nil
public var isPreview: Bool = false
}
public struct Provider: TimelineProvider {
@@ -29,6 +30,10 @@ public struct Provider: TimelineProvider {
private let userDefaults: UserDefaults? = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets")
public var systemWidgetsUpdatesState: Bool {
self.userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
}
public func placeholder(in context: Context) -> Disk_entry {
Disk_entry()
}
@@ -58,7 +63,7 @@ public struct DiskWidget: Widget {
public var body: some WidgetConfiguration {
StaticConfiguration(kind: Disk_entry.kind, provider: Provider()) { entry in
VStack(spacing: 10) {
if let value = entry.value {
if Provider().systemWidgetsUpdatesState || entry.isPreview, let value = entry.value {
HStack {
Chart {
SectorMark(angle: .value(localizedString("Used"), (100*(value.size-value.free))/value.size), innerRadius: .ratio(0.8)).foregroundStyle(self.usedColor)
@@ -94,6 +99,10 @@ public struct DiskWidget: Widget {
Text(DiskSize(value.free).getReadableMemory())
}
}
} else if !Provider().systemWidgetsUpdatesState {
Text("Enable in Settings")
.font(.system(size: 12, weight: .regular))
.foregroundColor(.secondary)
} else {
Text("No data")
}

View File

@@ -16,12 +16,13 @@ import Kit
public struct GPU_entry: TimelineEntry {
public static let kind = "GPUWidget"
public static var snapshot: GPU_entry = GPU_entry(value: GPU_Info(id: "", type: "", IOClass: "", model: "", cores: nil, utilization: 0.11, render: 0.11, tiler: 0.11))
public static var snapshot: GPU_entry = GPU_entry(value: GPU_Info(id: "", type: "", IOClass: "", model: "", cores: nil, utilization: 0.11, render: 0.11, tiler: 0.11), isPreview: true)
public var date: Date {
Calendar.current.date(byAdding: .second, value: 5, to: Date())!
}
public var value: GPU_Info? = nil
public var isPreview: Bool = false
}
public struct Provider: TimelineProvider {
@@ -29,6 +30,10 @@ public struct Provider: TimelineProvider {
private let userDefaults: UserDefaults? = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets")
public var systemWidgetsUpdatesState: Bool {
self.userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
}
public func placeholder(in context: Context) -> GPU_entry {
GPU_entry()
}
@@ -58,7 +63,7 @@ public struct GPUWidget: Widget {
public var body: some WidgetConfiguration {
StaticConfiguration(kind: GPU_entry.kind, provider: Provider()) { entry in
VStack(spacing: 10) {
if let value = entry.value {
if Provider().systemWidgetsUpdatesState || entry.isPreview, let value = entry.value {
HStack {
Chart {
SectorMark(angle: .value(localizedString("Used"), value.utilization ?? 0), innerRadius: .ratio(0.8)).foregroundStyle(self.usedColor)
@@ -97,6 +102,10 @@ public struct GPUWidget: Widget {
Text("\(Int((value.tilerUtilization ?? 0)*100))%")
}
}
} else if !Provider().systemWidgetsUpdatesState {
Text("Enable in Settings")
.font(.system(size: 12, weight: .regular))
.foregroundColor(.secondary)
} else {
Text("No data")
}

View File

@@ -21,12 +21,13 @@ public struct Network_entry: TimelineEntry {
raddr: Network_addr(v4: "192.168.0.1"),
interface: Network_interface(displayName: "Stats"),
status: true
))
), isPreview: true)
public var date: Date {
Calendar.current.date(byAdding: .second, value: 5, to: Date())!
}
public var value: Network_Usage? = nil
public var isPreview: Bool = false
}
public struct Provider: TimelineProvider {
@@ -34,6 +35,10 @@ public struct Provider: TimelineProvider {
private let userDefaults: UserDefaults? = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets")
public var systemWidgetsUpdatesState: Bool {
self.userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
}
public func placeholder(in context: Context) -> Network_entry {
Network_entry()
}
@@ -63,7 +68,7 @@ public struct NetworkWidget: Widget {
public var body: some WidgetConfiguration {
StaticConfiguration(kind: Network_entry.kind, provider: Provider()) { entry in
VStack(spacing: 10) {
if let value = entry.value {
if Provider().systemWidgetsUpdatesState || entry.isPreview, let value = entry.value {
VStack {
HStack {
VStack {
@@ -111,6 +116,10 @@ public struct NetworkWidget: Widget {
}
}
}
} else if !Provider().systemWidgetsUpdatesState {
Text("Enable in Settings")
.font(.system(size: 12, weight: .regular))
.foregroundColor(.secondary)
} else {
Text("No data")
}

View File

@@ -31,13 +31,15 @@ public struct RAM_entry: TimelineEntry {
pressure: Pressure(level: 1, value: .normal),
swapins: 14,
swapouts: 16
)
),
isPreview: true
)
public var date: Date {
Calendar.current.date(byAdding: .second, value: 5, to: Date())!
}
public var value: RAM_Usage? = nil
public var isPreview: Bool = false
}
public struct Provider: TimelineProvider {
@@ -45,6 +47,10 @@ public struct Provider: TimelineProvider {
private let userDefaults: UserDefaults? = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets")
public var systemWidgetsUpdatesState: Bool {
self.userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
}
public func placeholder(in context: Context) -> RAM_entry {
RAM_entry()
}
@@ -74,7 +80,7 @@ public struct RAMWidget: Widget {
public var body: some WidgetConfiguration {
StaticConfiguration(kind: RAM_entry.kind, provider: Provider()) { entry in
VStack(spacing: 10) {
if let value = entry.value {
if Provider().systemWidgetsUpdatesState || entry.isPreview, let value = entry.value {
HStack {
Chart {
SectorMark(angle: .value(localizedString("Used"), value.used/value.total), innerRadius: .ratio(0.8)).foregroundStyle(self.usedColor)
@@ -115,6 +121,10 @@ public struct RAMWidget: Widget {
Text("\(value.pressure.level)")
}
}
} else if !Provider().systemWidgetsUpdatesState {
Text("Enable in Settings")
.font(.system(size: 12, weight: .regular))
.foregroundColor(.secondary)
} else {
Text("No data")
}