Skip to content

Commit

Permalink
Sensors window - Remembering the checkboxes statuses.
Browse files Browse the repository at this point in the history
  • Loading branch information
macmade committed Nov 3, 2021
1 parent 827b755 commit d2184f7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
15 changes: 15 additions & 0 deletions Hot/Classes/ApplicationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate
UserDefaults.standard.setValue( 2, forKey: "refreshInterval" )
}

if UserDefaults.standard.object( forKey: "sensorsWindowShowTemperature" ) == nil
{
UserDefaults.standard.setValue( true, forKey: "sensorsWindowShowTemperature" )
}

if UserDefaults.standard.object( forKey: "sensorsWindowShowVoltage" ) == nil
{
UserDefaults.standard.setValue( true, forKey: "sensorsWindowShowVoltage" )
}

if UserDefaults.standard.object( forKey: "sensorsWindowShowCurrent" ) == nil
{
UserDefaults.standard.setValue( true, forKey: "sensorsWindowShowCurrent" )
}

self.aboutWindowController = AboutWindowController()
self.preferencesWindowController = PreferencesWindowController()
self.statusItem = NSStatusBar.system.statusItem( withLength: NSStatusItem.variableLength )
Expand Down
25 changes: 19 additions & 6 deletions Hot/Classes/Sensors/SensorsWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,31 @@ public class SensorsWindowController: NSWindowController
{
@objc private dynamic var sensors: Sensors? = Sensors()

@objc private dynamic var showTemperature = true
@objc private dynamic var showTemperature = UserDefaults.standard.bool( forKey: "sensorsWindowShowTemperature" )
{
didSet { self.updateFilters() }
didSet
{
self.updateFilters()
UserDefaults.standard.set( self.showTemperature, forKey: "sensorsWindowShowTemperature" )
}
}

@objc private dynamic var showVoltage = true
@objc private dynamic var showVoltage = UserDefaults.standard.bool( forKey: "sensorsWindowShowVoltage" )
{
didSet { self.updateFilters() }
didSet
{
self.updateFilters()
UserDefaults.standard.set( self.showVoltage, forKey: "sensorsWindowShowVoltage" )
}
}

@objc private dynamic var showCurrent = true
@objc private dynamic var showCurrent = UserDefaults.standard.bool( forKey: "sensorsWindowShowCurrent" )
{
didSet { self.updateFilters() }
didSet
{
self.updateFilters()
UserDefaults.standard.set( self.showCurrent, forKey: "sensorsWindowShowCurrent" )
}
}

@objc private dynamic var searchText: String?
Expand All @@ -67,6 +79,7 @@ public class SensorsWindowController: NSWindowController
public override func windowDidLoad()
{
super.windowDidLoad()
self.updateFilters()

self.arrayController.sortDescriptors = [ NSSortDescriptor( key: "name", ascending: true, selector: #selector( NSString.localizedCaseInsensitiveCompare( _: ) ) ) ]
}
Expand Down

0 comments on commit d2184f7

Please sign in to comment.