feat: added a check if the macOS widget is active before updating the read value in the user defaults. It will prevent unnecessary writes when the widget is not enabled (#2733)

This commit is contained in:
Serhiy Mytrovtsiy
2025-12-02 21:00:52 +01:00
parent a96232b0c1
commit 3cad4f49dd
13 changed files with 43 additions and 33 deletions

View File

@@ -1820,3 +1820,14 @@ public class GPUStressTest {
}
}
}
public func isWidgetActive(_ defaults: UserDefaults?, _ widgets: [String]) -> Bool {
for name in widgets {
guard let lastUpdate = defaults?.double(forKey: name) else { return false }
let timeSinceUpdate = Date().timeIntervalSince1970 - lastUpdate
if timeSinceUpdate < 60 {
return true
}
}
return false
}

View File

@@ -73,18 +73,14 @@ open class Module {
public var settings: Settings_p? = nil
public let portal: Portal_p?
public var name: String {
config.name
}
public var name: String { config.name }
public var combinedPosition: Int {
get { Store.shared.int(key: "\(self.name)_position", defaultValue: 0) }
set { Store.shared.set(key: "\(self.name)_position", value: newValue) }
}
public var userDefaults: UserDefaults? = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets")
public var popupKeyboardShortcut: [UInt16] {
return self.popupView?.keyboardShortcut ?? []
}
public var popupKeyboardShortcut: [UInt16] { self.popupView?.keyboardShortcut ?? [] }
private var moduleType: ModuleType
@@ -97,12 +93,8 @@ open class Module {
private var readers: [Reader_p] = []
private var pauseState: Bool {
get {
Store.shared.bool(key: "pause", defaultValue: false)
}
set {
Store.shared.set(key: "pause", value: newValue)
}
get { Store.shared.bool(key: "pause", defaultValue: false) }
set { Store.shared.set(key: "pause", value: newValue) }
}
public init(moduleType: ModuleType, popup: Popup_p? = nil, settings: Settings_v? = nil, portal: Portal_p? = nil, notifications: NotificationsWrapper? = nil) {