Skip to content

Commit 9c20ce2

Browse files
committed
Added preferences.
1 parent f0b97a7 commit 9c20ce2

File tree

6 files changed

+249
-28
lines changed

6 files changed

+249
-28
lines changed

Hot.xcodeproj/project.pbxproj

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
052FBC34251ECA8600C4322E /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 052FBC33251ECA8600C4322E /* IOKit.framework */; };
1111
052FBC38251ECB8B00C4322E /* SMC.c in Sources */ = {isa = PBXBuildFile; fileRef = 052FBC37251ECB8B00C4322E /* SMC.c */; };
12+
052FBCA3251EE43B00C4322E /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 052FBCA2251EE43B00C4322E /* PreferencesWindowController.swift */; };
13+
052FBCA7251EE46700C4322E /* PreferencesWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 052FBCA5251EE46700C4322E /* PreferencesWindowController.xib */; };
1214
057F8B00251D22360048F1E1 /* StatusIconTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 057F8AFF251D22360048F1E1 /* StatusIconTemplate.pdf */; };
1315
057F8B0C251D273E0048F1E1 /* AboutWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 057F8B0B251D273E0048F1E1 /* AboutWindowController.swift */; };
1416
057F8B11251D274C0048F1E1 /* NSApplication+LaunchServices.m in Sources */ = {isa = PBXBuildFile; fileRef = 057F8B10251D274C0048F1E1 /* NSApplication+LaunchServices.m */; };
@@ -62,6 +64,8 @@
6264
052FBC32251EC69B00C4322E /* SMC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SMC.h; sourceTree = "<group>"; };
6365
052FBC33251ECA8600C4322E /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
6466
052FBC37251ECB8B00C4322E /* SMC.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = SMC.c; sourceTree = "<group>"; };
67+
052FBCA2251EE43B00C4322E /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
68+
052FBCA6251EE46700C4322E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PreferencesWindowController.xib; sourceTree = "<group>"; };
6569
057F8AFF251D22360048F1E1 /* StatusIconTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = StatusIconTemplate.pdf; sourceTree = "<group>"; };
6670
057F8B0B251D273E0048F1E1 /* AboutWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutWindowController.swift; sourceTree = "<group>"; };
6771
057F8B0E251D274C0048F1E1 /* Hot-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Hot-Bridging-Header.h"; sourceTree = "<group>"; };
@@ -314,24 +318,26 @@
314318
05AA4088251CF3F400106CEA /* Classes */ = {
315319
isa = PBXGroup;
316320
children = (
317-
057F8B0F251D274C0048F1E1 /* NSApplication+LaunchServices.h */,
318-
057F8B10251D274C0048F1E1 /* NSApplication+LaunchServices.m */,
319321
057F8B0B251D273E0048F1E1 /* AboutWindowController.swift */,
320322
05AA4079251CF3D200106CEA /* ApplicationDelegate.swift */,
321-
05AA408C251CFA0600106CEA /* ThermalLog.swift */,
322-
052FBC32251EC69B00C4322E /* SMC.h */,
323-
052FBC37251ECB8B00C4322E /* SMC.c */,
324323
057F8B0E251D274C0048F1E1 /* Hot-Bridging-Header.h */,
324+
057F8B0F251D274C0048F1E1 /* NSApplication+LaunchServices.h */,
325+
057F8B10251D274C0048F1E1 /* NSApplication+LaunchServices.m */,
326+
052FBCA2251EE43B00C4322E /* PreferencesWindowController.swift */,
327+
052FBC37251ECB8B00C4322E /* SMC.c */,
328+
052FBC32251EC69B00C4322E /* SMC.h */,
329+
05AA408C251CFA0600106CEA /* ThermalLog.swift */,
325330
);
326331
path = Classes;
327332
sourceTree = "<group>";
328333
};
329334
05AA4089251CF3FC00106CEA /* UI */ = {
330335
isa = PBXGroup;
331336
children = (
337+
057F8B13251D27650048F1E1 /* AboutWindowController.xib */,
332338
057F8AFE251D22360048F1E1 /* Images */,
333339
05AA407D251CF3D600106CEA /* MainMenu.xib */,
334-
057F8B13251D27650048F1E1 /* AboutWindowController.xib */,
340+
052FBCA5251EE46700C4322E /* PreferencesWindowController.xib */,
335341
);
336342
path = UI;
337343
sourceTree = "<group>";
@@ -423,6 +429,7 @@
423429
057F8B00251D22360048F1E1 /* StatusIconTemplate.pdf in Resources */,
424430
057F8B1B251D2A970048F1E1 /* Icon.icns in Resources */,
425431
057F8B15251D27650048F1E1 /* AboutWindowController.xib in Resources */,
432+
052FBCA7251EE46700C4322E /* PreferencesWindowController.xib in Resources */,
426433
05AA407F251CF3D600106CEA /* MainMenu.xib in Resources */,
427434
);
428435
runOnlyForDeploymentPostprocessing = 0;
@@ -454,6 +461,7 @@
454461
isa = PBXSourcesBuildPhase;
455462
buildActionMask = 2147483647;
456463
files = (
464+
052FBCA3251EE43B00C4322E /* PreferencesWindowController.swift in Sources */,
457465
057F8B11251D274C0048F1E1 /* NSApplication+LaunchServices.m in Sources */,
458466
057F8B0C251D273E0048F1E1 /* AboutWindowController.swift in Sources */,
459467
05AA408D251CFA0600106CEA /* ThermalLog.swift in Sources */,
@@ -473,6 +481,14 @@
473481
/* End PBXTargetDependency section */
474482

475483
/* Begin PBXVariantGroup section */
484+
052FBCA5251EE46700C4322E /* PreferencesWindowController.xib */ = {
485+
isa = PBXVariantGroup;
486+
children = (
487+
052FBCA6251EE46700C4322E /* Base */,
488+
);
489+
name = PreferencesWindowController.xib;
490+
sourceTree = "<group>";
491+
};
476492
057F8B13251D27650048F1E1 /* AboutWindowController.xib */ = {
477493
isa = PBXVariantGroup;
478494
children = (

Hot/Classes/ApplicationDelegate.swift

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,30 @@ import GitHubUpdates
2828
@NSApplicationMain
2929
class ApplicationDelegate: NSObject, NSApplicationDelegate
3030
{
31-
private var timer: Timer?
32-
private var statusItem: NSStatusItem?
33-
private var observations: [ NSKeyValueObservation ] = []
34-
private var aboutWindowController: AboutWindowController?
31+
private var timer: Timer?
32+
private var statusItem: NSStatusItem?
33+
private var observations: [ NSKeyValueObservation ] = []
34+
private var aboutWindowController: AboutWindowController?
35+
private var preferencesWindowController: PreferencesWindowController?
36+
3537

3638
@IBOutlet private var menu: NSMenu!
3739
@IBOutlet private var updater: GitHubUpdater!
3840

39-
@objc public dynamic var log = ThermalLog()
40-
@objc public dynamic var startAtLogin = false
41-
{
42-
didSet
43-
{
44-
NSApp.setLoginItemEnabled( self.startAtLogin )
45-
}
46-
}
41+
@objc public dynamic var log = ThermalLog()
4742

4843
func applicationDidFinishLaunching( _ notification: Notification )
4944
{
50-
self.startAtLogin = NSApp.isLoginItemEnabled()
45+
if UserDefaults.standard.object( forKey: "LastLaunch" ) == nil
46+
{
47+
UserDefaults.standard.setValue( true, forKey: "automaticallyCheckForUpdates" )
48+
UserDefaults.standard.setValue( true, forKey: "displayCPUTemperature" )
49+
UserDefaults.standard.setValue( true, forKey: "colorizeStatusItemText" )
50+
UserDefaults.standard.setValue( NSDate(), forKey: "LastLaunch" )
51+
}
52+
5153
self.aboutWindowController = AboutWindowController()
54+
self.preferencesWindowController = PreferencesWindowController()
5255
self.statusItem = NSStatusBar.system.statusItem( withLength: NSStatusItem.variableLength )
5356
self.statusItem?.button?.image = NSImage( named: "StatusIconTemplate" )
5457
self.statusItem?.button?.imagePosition = .imageLeading
@@ -68,9 +71,22 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate
6871

6972
self.log.refresh()
7073

71-
DispatchQueue.main.asyncAfter( deadline: .now() + .seconds( 10 ) )
74+
if UserDefaults.standard.bool( forKey: "automaticallyCheckForUpdates" )
7275
{
73-
self.updater.checkForUpdatesInBackground()
76+
DispatchQueue.main.asyncAfter( deadline: .now() + .seconds( 2 ) )
77+
{
78+
self.updater.checkForUpdatesInBackground()
79+
}
80+
}
81+
82+
Timer.scheduledTimer( withTimeInterval: 3600, repeats: true )
83+
{
84+
_ in
85+
86+
if UserDefaults.standard.bool( forKey: "automaticallyCheckForUpdates" )
87+
{
88+
self.updater.checkForUpdatesInBackground()
89+
}
7490
}
7591
}
7692

@@ -98,6 +114,25 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate
98114
window.makeKeyAndOrderFront( nil )
99115
}
100116

117+
@IBAction public func showPreferencesWindow( _ sender: Any? )
118+
{
119+
guard let window = self.preferencesWindowController?.window else
120+
{
121+
NSSound.beep()
122+
123+
return
124+
}
125+
126+
if window.isVisible == false
127+
{
128+
window.layoutIfNeeded()
129+
window.center()
130+
}
131+
132+
NSApp.activate( ignoringOtherApps: true )
133+
window.makeKeyAndOrderFront( nil )
134+
}
135+
101136
@IBAction public func checkForUpdates( _ sender: Any? )
102137
{
103138
self.updater.checkForUpdates( sender )
@@ -156,7 +191,9 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate
156191

157192
var title = ""
158193

159-
if let n1 = self.log.speedLimit?.intValue, let n2 = self.log.cpuTemperature?.intValue
194+
if let n1 = self.log.speedLimit?.intValue,
195+
let n2 = self.log.cpuTemperature?.intValue,
196+
UserDefaults.standard.bool( forKey: "displayCPUTemperature" )
160197
{
161198
title = "\( n1 )% \( n2 )°"
162199
}
@@ -171,7 +208,7 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate
171208
}
172209
else
173210
{
174-
let color = self.log.speedLimit?.intValue ?? 100 < 60 ? NSColor.orange : NSColor.white
211+
let color = self.log.speedLimit?.intValue ?? 100 < 60 && UserDefaults.standard.bool( forKey: "colorizeStatusItemText" ) ? NSColor.orange : NSColor.white
175212

176213
self.statusItem?.button?.attributedTitle = NSAttributedString( string: title, attributes: [ .foregroundColor : color ] )
177214
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2020 Jean-David Gadina - www.xs-labs.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
******************************************************************************/
24+
25+
import Cocoa
26+
27+
public class PreferencesWindowController: NSWindowController
28+
{
29+
@objc public dynamic var displayCPUTemperature = UserDefaults.standard.bool( forKey: "displayCPUTemperature" )
30+
{
31+
didSet
32+
{
33+
UserDefaults.standard.setValue( self.displayCPUTemperature, forKey: "displayCPUTemperature" )
34+
}
35+
}
36+
37+
@objc public dynamic var colorizeStatusItemText = UserDefaults.standard.bool( forKey: "colorizeStatusItemText" )
38+
{
39+
didSet
40+
{
41+
UserDefaults.standard.setValue( self.colorizeStatusItemText, forKey: "colorizeStatusItemText" )
42+
}
43+
}
44+
45+
@objc public dynamic var automaticallyCheckForUpdates = UserDefaults.standard.bool( forKey: "automaticallyCheckForUpdates" )
46+
{
47+
didSet
48+
{
49+
UserDefaults.standard.setValue( self.automaticallyCheckForUpdates, forKey: "automaticallyCheckForUpdates" )
50+
}
51+
}
52+
53+
@objc public dynamic var startAtLogin = NSApp.isLoginItemEnabled()
54+
{
55+
didSet
56+
{
57+
NSApp.setLoginItemEnabled( self.startAtLogin )
58+
}
59+
}
60+
61+
public override var windowNibName: NSNib.Name?
62+
{
63+
return "PreferencesWindowController"
64+
}
65+
}

Hot/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundlePackageType</key>
1818
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.0.0</string>
20+
<string>1.1.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>13</string>
22+
<string>18</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

Hot/UI/Base.lproj/MainMenu.xib

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,9 @@
703703
<modifierMask key="keyEquivalentModifierMask"/>
704704
</menuItem>
705705
<menuItem isSeparatorItem="YES" id="XCF-fq-sNA"/>
706-
<menuItem title="Start at Login" id="JFH-mp-6PU">
707-
<modifierMask key="keyEquivalentModifierMask"/>
706+
<menuItem title="Preferences..." keyEquivalent="," id="JFH-mp-6PU">
708707
<connections>
709-
<binding destination="Voe-Tx-rLC" name="value" keyPath="self.startAtLogin" id="DEd-fD-Au5"/>
708+
<action selector="showPreferencesWindow:" target="Voe-Tx-rLC" id="E99-rm-GGi"/>
710709
</connections>
711710
</menuItem>
712711
<menuItem title="Check for Updates..." id="HLn-la-Ngo">

0 commit comments

Comments
 (0)