mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: changed the default value of macOS widgets to disabled to prevent heavy load on some systems, and added information text to the widgets (#2733)
This commit is contained in:
@@ -115,7 +115,7 @@ public class CPU: Module {
|
||||
}
|
||||
|
||||
private var systemWidgetsUpdatesState: Bool {
|
||||
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||
self.userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
|
||||
}
|
||||
|
||||
public init() {
|
||||
|
||||
@@ -30,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) -> CPU_entry {
|
||||
CPU_entry()
|
||||
}
|
||||
@@ -60,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 let value = entry.value {
|
||||
if Provider().systemWidgetsUpdatesState, let value = entry.value {
|
||||
HStack {
|
||||
Chart {
|
||||
SectorMark(angle: .value(localizedString("System"), value.systemLoad), innerRadius: .ratio(0.8)).foregroundStyle(self.systemColor)
|
||||
@@ -97,6 +101,10 @@ public struct CPUWidget: Widget {
|
||||
Text("\(Int(value.userLoad*100))%")
|
||||
}
|
||||
}
|
||||
} else if !Provider().systemWidgetsUpdatesState {
|
||||
Text("Enable in Settings")
|
||||
.font(.system(size: 12, weight: .regular))
|
||||
.foregroundColor(.secondary)
|
||||
} else {
|
||||
Text("No data")
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ public class Disk: Module {
|
||||
}
|
||||
|
||||
private var systemWidgetsUpdatesState: Bool {
|
||||
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||
self.userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
|
||||
}
|
||||
|
||||
public init() {
|
||||
|
||||
@@ -121,7 +121,7 @@ public class GPU: Module {
|
||||
}
|
||||
|
||||
private var systemWidgetsUpdatesState: Bool {
|
||||
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||
self.userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
|
||||
}
|
||||
|
||||
public init() {
|
||||
|
||||
@@ -164,7 +164,7 @@ public class Network: Module {
|
||||
}
|
||||
|
||||
private var systemWidgetsUpdatesState: Bool {
|
||||
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||
self.userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
|
||||
}
|
||||
|
||||
public init() {
|
||||
|
||||
@@ -95,7 +95,7 @@ public class RAM: Module {
|
||||
}
|
||||
|
||||
private var systemWidgetsUpdatesState: Bool {
|
||||
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||
self.userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
|
||||
}
|
||||
|
||||
public init() {
|
||||
|
||||
@@ -40,8 +40,14 @@ class ApplicationSettings: NSStackView {
|
||||
}
|
||||
|
||||
private var systemWidgetsUpdatesState: Bool {
|
||||
get { Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true) }
|
||||
set { Store.shared.set(key: "systemWidgetsUpdates_state", value: newValue) }
|
||||
get {
|
||||
let userDefaults = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets")
|
||||
return userDefaults?.bool(forKey: "systemWidgetsUpdates_state") ?? false
|
||||
}
|
||||
set {
|
||||
let userDefaults = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets")
|
||||
userDefaults?.set(newValue, forKey: "systemWidgetsUpdates_state")
|
||||
}
|
||||
}
|
||||
|
||||
private var updateSelector: NSPopUpButton?
|
||||
@@ -103,7 +109,7 @@ class ApplicationSettings: NSStackView {
|
||||
]))
|
||||
|
||||
scrollView.stackView.addArrangedSubview(PreferencesSection([
|
||||
PreferencesRow(localizedString("System widgets updates"), component: switchView(
|
||||
PreferencesRow(localizedString("macOS widgets"), component: switchView(
|
||||
action: #selector(self.toggleSystemWidgetsUpdatesState),
|
||||
state: self.systemWidgetsUpdatesState
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user