mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user