diff --git a/Modules/CPU/widget.swift b/Modules/CPU/widget.swift index 338f37f5..84c8dfea 100644 --- a/Modules/CPU/widget.swift +++ b/Modules/CPU/widget.swift @@ -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) diff --git a/Modules/Disk/widget.swift b/Modules/Disk/widget.swift index c149a7de..304e53c2 100644 --- a/Modules/Disk/widget.swift +++ b/Modules/Disk/widget.swift @@ -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") } diff --git a/Modules/GPU/widget.swift b/Modules/GPU/widget.swift index b33760b7..b60f011e 100644 --- a/Modules/GPU/widget.swift +++ b/Modules/GPU/widget.swift @@ -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") } diff --git a/Modules/Net/widget.swift b/Modules/Net/widget.swift index d7e02e61..7ad7addb 100644 --- a/Modules/Net/widget.swift +++ b/Modules/Net/widget.swift @@ -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") } diff --git a/Modules/RAM/widget.swift b/Modules/RAM/widget.swift index 0708acce..d2aebf5f 100644 --- a/Modules/RAM/widget.swift +++ b/Modules/RAM/widget.swift @@ -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") }