mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: add option to disable system-widget updates for users experiencing ongoing chronod issues (#2733)
This commit is contained in:
@@ -114,6 +114,10 @@ public class CPU: Module {
|
|||||||
return color.additional as! NSColor
|
return color.additional as! NSColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var systemWidgetsUpdatesState: Bool {
|
||||||
|
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||||
|
}
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
self.settingsView = Settings(.CPU)
|
self.settingsView = Settings(.CPU)
|
||||||
self.popupView = Popup(.CPU)
|
self.popupView = Popup(.CPU)
|
||||||
@@ -233,12 +237,14 @@ public class CPU: Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(macOS 11.0, *) {
|
if self.systemWidgetsUpdatesState {
|
||||||
if isWidgetActive(self.userDefaults, [CPU_entry.kind, "UnitedWidget"]), let blobData = try? JSONEncoder().encode(value) {
|
if #available(macOS 11.0, *) {
|
||||||
self.userDefaults?.set(blobData, forKey: "CPU@LoadReader")
|
if isWidgetActive(self.userDefaults, [CPU_entry.kind, "UnitedWidget"]), let blobData = try? JSONEncoder().encode(value) {
|
||||||
|
self.userDefaults?.set(blobData, forKey: "CPU@LoadReader")
|
||||||
|
}
|
||||||
|
WidgetCenter.shared.reloadTimelines(ofKind: CPU_entry.kind)
|
||||||
|
WidgetCenter.shared.reloadTimelines(ofKind: "UnitedWidget")
|
||||||
}
|
}
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: CPU_entry.kind)
|
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: "UnitedWidget")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,6 +221,10 @@ public class Disk: Module {
|
|||||||
Store.shared.string(key: "\(self.name)_textWidgetValue", defaultValue: "$capacity.free/$capacity.total")
|
Store.shared.string(key: "\(self.name)_textWidgetValue", defaultValue: "$capacity.free/$capacity.total")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var systemWidgetsUpdatesState: Bool {
|
||||||
|
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||||
|
}
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
super.init(
|
super.init(
|
||||||
moduleType: .disk,
|
moduleType: .disk,
|
||||||
@@ -329,12 +333,14 @@ public class Disk: Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(macOS 11.0, *) {
|
if self.systemWidgetsUpdatesState {
|
||||||
if isWidgetActive(self.userDefaults, [Disk_entry.kind, "UnitedWidget"]), let blobData = try? JSONEncoder().encode(d) {
|
if #available(macOS 11.0, *) {
|
||||||
self.userDefaults?.set(blobData, forKey: "Disk@CapacityReader")
|
if isWidgetActive(self.userDefaults, [Disk_entry.kind, "UnitedWidget"]), let blobData = try? JSONEncoder().encode(d) {
|
||||||
|
self.userDefaults?.set(blobData, forKey: "Disk@CapacityReader")
|
||||||
|
}
|
||||||
|
WidgetCenter.shared.reloadTimelines(ofKind: Disk_entry.kind)
|
||||||
|
WidgetCenter.shared.reloadTimelines(ofKind: "UnitedWidget")
|
||||||
}
|
}
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: Disk_entry.kind)
|
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: "UnitedWidget")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,9 +117,11 @@ public class GPU: Module {
|
|||||||
private var notificationID: String? = nil
|
private var notificationID: String? = nil
|
||||||
|
|
||||||
private var showType: Bool {
|
private var showType: Bool {
|
||||||
get {
|
Store.shared.bool(key: "\(self.config.name)_showType", defaultValue: false)
|
||||||
return Store.shared.bool(key: "\(self.config.name)_showType", defaultValue: false)
|
}
|
||||||
}
|
|
||||||
|
private var systemWidgetsUpdatesState: Bool {
|
||||||
|
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
@@ -191,12 +193,14 @@ public class GPU: Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(macOS 11.0, *) {
|
if self.systemWidgetsUpdatesState {
|
||||||
if isWidgetActive(self.userDefaults, [GPU_entry.kind, "UnitedWidget"]), let blobData = try? JSONEncoder().encode(selectedGPU) {
|
if #available(macOS 11.0, *) {
|
||||||
self.userDefaults?.set(blobData, forKey: "GPU@InfoReader")
|
if isWidgetActive(self.userDefaults, [GPU_entry.kind, "UnitedWidget"]), let blobData = try? JSONEncoder().encode(selectedGPU) {
|
||||||
|
self.userDefaults?.set(blobData, forKey: "GPU@InfoReader")
|
||||||
|
}
|
||||||
|
WidgetCenter.shared.reloadTimelines(ofKind: GPU_entry.kind)
|
||||||
|
WidgetCenter.shared.reloadTimelines(ofKind: "UnitedWidget")
|
||||||
}
|
}
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: GPU_entry.kind)
|
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: "UnitedWidget")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,6 +158,10 @@ public class Network: Module {
|
|||||||
Store.shared.string(key: "\(self.name)_textWidgetValue", defaultValue: "$addr.public - $status")
|
Store.shared.string(key: "\(self.name)_textWidgetValue", defaultValue: "$addr.public - $status")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var systemWidgetsUpdatesState: Bool {
|
||||||
|
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||||
|
}
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
self.settingsView = Settings(.network)
|
self.settingsView = Settings(.network)
|
||||||
self.popupView = Popup(.network)
|
self.popupView = Popup(.network)
|
||||||
@@ -325,11 +329,13 @@ public class Network: Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(macOS 11.0, *) {
|
if self.systemWidgetsUpdatesState {
|
||||||
if isWidgetActive(self.userDefaults, [Network_entry.kind]), let blobData = try? JSONEncoder().encode(raw) {
|
if #available(macOS 11.0, *) {
|
||||||
self.userDefaults?.set(blobData, forKey: "Network@UsageReader")
|
if isWidgetActive(self.userDefaults, [Network_entry.kind]), let blobData = try? JSONEncoder().encode(raw) {
|
||||||
|
self.userDefaults?.set(blobData, forKey: "Network@UsageReader")
|
||||||
|
}
|
||||||
|
WidgetCenter.shared.reloadTimelines(ofKind: Network_entry.kind)
|
||||||
}
|
}
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: Network_entry.kind)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ public class RAM: Module {
|
|||||||
Store.shared.string(key: "\(self.name)_textWidgetValue", defaultValue: "$mem.used/$mem.total ($pressure.value)")
|
Store.shared.string(key: "\(self.name)_textWidgetValue", defaultValue: "$mem.used/$mem.total ($pressure.value)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var systemWidgetsUpdatesState: Bool {
|
||||||
|
Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true)
|
||||||
|
}
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
self.settingsView = Settings(.RAM)
|
self.settingsView = Settings(.RAM)
|
||||||
self.popupView = Popup(.RAM)
|
self.popupView = Popup(.RAM)
|
||||||
@@ -232,12 +236,14 @@ public class RAM: Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(macOS 11.0, *) {
|
if self.systemWidgetsUpdatesState {
|
||||||
if isWidgetActive(self.userDefaults, [RAM_entry.kind, "UnitedWidget"]), let blobData = try? JSONEncoder().encode(value) {
|
if #available(macOS 11.0, *) {
|
||||||
self.userDefaults?.set(blobData, forKey: "RAM@UsageReader")
|
if isWidgetActive(self.userDefaults, [RAM_entry.kind, "UnitedWidget"]), let blobData = try? JSONEncoder().encode(value) {
|
||||||
|
self.userDefaults?.set(blobData, forKey: "RAM@UsageReader")
|
||||||
|
}
|
||||||
|
WidgetCenter.shared.reloadTimelines(ofKind: RAM_entry.kind)
|
||||||
|
WidgetCenter.shared.reloadTimelines(ofKind: "UnitedWidget")
|
||||||
}
|
}
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: RAM_entry.kind)
|
|
||||||
WidgetCenter.shared.reloadTimelines(ofKind: "UnitedWidget")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ class ApplicationSettings: NSStackView {
|
|||||||
set { Store.shared.set(key: "CombinedModules_popup", value: newValue) }
|
set { Store.shared.set(key: "CombinedModules_popup", value: newValue) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var systemWidgetsUpdatesState: Bool {
|
||||||
|
get { Store.shared.bool(key: "systemWidgetsUpdates_state", defaultValue: true) }
|
||||||
|
set { Store.shared.set(key: "systemWidgetsUpdates_state", value: newValue) }
|
||||||
|
}
|
||||||
|
|
||||||
private var updateSelector: NSPopUpButton?
|
private var updateSelector: NSPopUpButton?
|
||||||
private var startAtLoginBtn: NSSwitch?
|
private var startAtLoginBtn: NSSwitch?
|
||||||
private var remoteControlBtn: NSSwitch?
|
private var remoteControlBtn: NSSwitch?
|
||||||
@@ -97,6 +102,13 @@ class ApplicationSettings: NSStackView {
|
|||||||
PreferencesRow(localizedString("Start at login"), component: self.startAtLoginBtn!)
|
PreferencesRow(localizedString("Start at login"), component: self.startAtLoginBtn!)
|
||||||
]))
|
]))
|
||||||
|
|
||||||
|
scrollView.stackView.addArrangedSubview(PreferencesSection([
|
||||||
|
PreferencesRow(localizedString("System widgets updates"), component: switchView(
|
||||||
|
action: #selector(self.toggleSystemWidgetsUpdatesState),
|
||||||
|
state: self.systemWidgetsUpdatesState
|
||||||
|
))
|
||||||
|
]))
|
||||||
|
|
||||||
self.combinedModulesView = PreferencesSection([
|
self.combinedModulesView = PreferencesSection([
|
||||||
PreferencesRow(localizedString("Combined modules"), component: switchView(
|
PreferencesRow(localizedString("Combined modules"), component: switchView(
|
||||||
action: #selector(self.toggleCombinedModules),
|
action: #selector(self.toggleCombinedModules),
|
||||||
@@ -470,6 +482,10 @@ class ApplicationSettings: NSStackView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func toggleSystemWidgetsUpdatesState(_ sender: NSButton) {
|
||||||
|
self.systemWidgetsUpdatesState = sender.state == NSControl.StateValue.on
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ModuleSelectorView: NSStackView {
|
private class ModuleSelectorView: NSStackView {
|
||||||
|
|||||||
Reference in New Issue
Block a user