Skip to content

Commit 0e3b873

Browse files
committed
Added temperature display mode: highest/average.
1 parent 5902e86 commit 0e3b873

File tree

3 files changed

+97
-26
lines changed

3 files changed

+97
-26
lines changed

Hot/Classes/PreferencesWindowController.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public class PreferencesWindowController: NSWindowController
7474
}
7575
}
7676

77+
@objc public dynamic var temperatureDisplayMode = UserDefaults.standard.integer( forKey: "temperatureDisplayMode" )
78+
{
79+
didSet
80+
{
81+
UserDefaults.standard.setValue( self.temperatureDisplayMode, forKey: "temperatureDisplayMode" )
82+
}
83+
}
84+
7785
@objc public dynamic var fontName = UserDefaults.standard.string( forKey: "fontName" ) ?? "Default"
7886
{
7987
didSet

Hot/Classes/ThermalLog.swift

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,30 +104,42 @@ public class ThermalLog: NSObject
104104
let sensors = self.readSensors()
105105
let cpu = sensors.filter { $0.value.isCPU }.mapValues { $0.temperature }
106106
let all = sensors.mapValues { $0.temperature }
107-
var temp = 0.0
108107
self.sensors = all
109108
let names = UserDefaults.standard.object( forKey: "selectedSensors" ) as? [ String ] ?? []
110109
let selected = sensors.filter { names.contains( $0.key ) }.mapValues { $0.temperature }
111110

112-
if selected.count > 0
111+
let temperatures: [ Double ] =
113112
{
114-
temp = selected.reduce( 0.0 ) { r, v in v.value > r ? v.value : r }
115-
}
116-
else if cpu.count > 0
117-
{
118-
temp = cpu.reduce( 0.0 ) { r, v in v.value > r ? v.value : r }
119-
}
120-
else
113+
if selected.count > 0
114+
{
115+
return selected.values.map { $0 }
116+
}
117+
else if cpu.count > 0
118+
{
119+
return cpu.values.map { $0 }
120+
}
121+
else
122+
{
123+
return all.filter
124+
{
125+
$0.key.lowercased().hasSuffix( "tcal" ) == false
126+
}
127+
.values.map { $0 }
128+
}
129+
}()
130+
131+
let temp: Double =
121132
{
122-
temp = all.filter
133+
if UserDefaults.standard.integer( forKey: "temperatureDisplayMode" ) == 1
123134
{
124-
$0.key.lowercased().hasSuffix( "tcal" ) == false
135+
return temperatures.count == 0 ? 0 : temperatures.reduce( 0, + ) / Double( temperatures.count )
125136
}
126-
.reduce( 0.0 )
137+
138+
return temperatures.reduce( 0.0 )
127139
{
128-
r, v in v.value > r ? v.value : r
140+
r, v in max( r, v )
129141
}
130-
}
142+
}()
131143

132144
if temp > 1
133145
{

Hot/UI/Base.lproj/PreferencesWindowController.xib

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
<rect key="contentRect" x="196" y="240" width="700" height="297"/>
2020
<rect key="screenRect" x="0.0" y="0.0" width="1710" height="1069"/>
2121
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
22-
<rect key="frame" x="0.0" y="0.0" width="700" height="332"/>
22+
<rect key="frame" x="0.0" y="0.0" width="734" height="367"/>
2323
<autoresizingMask key="autoresizingMask"/>
2424
<subviews>
2525
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="15" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BG6-RK-yaR">
26-
<rect key="frame" x="20" y="20" width="340" height="292"/>
26+
<rect key="frame" x="20" y="20" width="339" height="327"/>
2727
<subviews>
2828
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="aiX-U8-MD5">
29-
<rect key="frame" x="-2" y="275" width="300" height="18"/>
29+
<rect key="frame" x="-2" y="310" width="300" height="18"/>
3030
<buttonCell key="cell" type="check" title="Display the CPU temperature in the menu bar" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="g0X-sq-6lh">
3131
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
3232
<font key="font" metaFont="system"/>
@@ -36,7 +36,7 @@
3636
</connections>
3737
</button>
3838
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Rog-WF-H8d">
39-
<rect key="frame" x="-2" y="244" width="59" height="18"/>
39+
<rect key="frame" x="-2" y="279" width="59" height="18"/>
4040
<buttonCell key="cell" type="check" title="Label" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="YMx-Az-Ken">
4141
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
4242
<font key="font" metaFont="system"/>
@@ -47,7 +47,7 @@
4747
</connections>
4848
</button>
4949
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="HBx-Rv-VgA">
50-
<rect key="frame" x="-2" y="213" width="341" height="18"/>
50+
<rect key="frame" x="-2" y="248" width="341" height="18"/>
5151
<buttonCell key="cell" type="check" title="Display temperature in Fahrenheit instead of Celsius" bezelStyle="regularSquare" imagePosition="left" inset="2" id="mpF-Ss-xf7">
5252
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
5353
<font key="font" metaFont="system"/>
@@ -57,7 +57,7 @@
5757
</connections>
5858
</button>
5959
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="cY4-xR-ECB">
60-
<rect key="frame" x="-2" y="182" width="233" height="18"/>
60+
<rect key="frame" x="-2" y="217" width="233" height="18"/>
6161
<buttonCell key="cell" type="check" title="Hide the Menu Bar icon if possible" bezelStyle="regularSquare" imagePosition="left" inset="2" id="J5N-yj-bbh">
6262
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
6363
<font key="font" metaFont="system"/>
@@ -67,7 +67,7 @@
6767
</connections>
6868
</button>
6969
<customView translatesAutoresizingMaskIntoConstraints="NO" id="EAB-dh-Hso">
70-
<rect key="frame" x="0.0" y="148" width="208" height="20"/>
70+
<rect key="frame" x="0.0" y="183" width="339" height="20"/>
7171
<subviews>
7272
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="PE9-ov-GuC">
7373
<rect key="frame" x="-2" y="2" width="103" height="16"/>
@@ -99,7 +99,7 @@
9999
</popUpButton>
100100
</subviews>
101101
<constraints>
102-
<constraint firstAttribute="trailing" secondItem="zSb-Uw-GGz" secondAttribute="trailing" id="IP7-vE-mw4"/>
102+
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="zSb-Uw-GGz" secondAttribute="trailing" id="IP7-vE-mw4"/>
103103
<constraint firstItem="PE9-ov-GuC" firstAttribute="centerY" secondItem="zSb-Uw-GGz" secondAttribute="centerY" id="LHg-EA-GbT"/>
104104
<constraint firstItem="zSb-Uw-GGz" firstAttribute="leading" secondItem="PE9-ov-GuC" secondAttribute="trailing" constant="8" symbolic="YES" id="OFY-vz-fp6"/>
105105
<constraint firstAttribute="bottom" secondItem="zSb-Uw-GGz" secondAttribute="bottom" id="qDh-a7-ITs"/>
@@ -108,7 +108,7 @@
108108
</constraints>
109109
</customView>
110110
<customView translatesAutoresizingMaskIntoConstraints="NO" id="9tp-fh-UvQ">
111-
<rect key="frame" x="0.0" y="113" width="263" height="20"/>
111+
<rect key="frame" x="0.0" y="148" width="339" height="20"/>
112112
<subviews>
113113
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="BeJ-a6-VLL">
114114
<rect key="frame" x="-2" y="2" width="73" height="16"/>
@@ -151,7 +151,7 @@
151151
</button>
152152
</subviews>
153153
<constraints>
154-
<constraint firstAttribute="trailing" secondItem="nY9-x0-twp" secondAttribute="trailing" id="4xs-uG-dsF"/>
154+
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="nY9-x0-twp" secondAttribute="trailing" id="4xs-uG-dsF"/>
155155
<constraint firstItem="nY9-x0-twp" firstAttribute="leading" secondItem="T2v-zD-kcg" secondAttribute="trailing" constant="12" symbolic="YES" id="5CH-zt-SUV"/>
156156
<constraint firstItem="T2v-zD-kcg" firstAttribute="leading" secondItem="9qW-vg-sZL" secondAttribute="trailing" constant="8" symbolic="YES" id="7tH-ff-VOI"/>
157157
<constraint firstItem="9qW-vg-sZL" firstAttribute="leading" secondItem="BeJ-a6-VLL" secondAttribute="trailing" constant="8" symbolic="YES" id="Fch-IB-Y24"/>
@@ -164,7 +164,7 @@
164164
</constraints>
165165
</customView>
166166
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="LZ9-Qg-JiC">
167-
<rect key="frame" x="-7" y="71" width="144" height="32"/>
167+
<rect key="frame" x="-7" y="106" width="144" height="32"/>
168168
<buttonCell key="cell" type="push" title="Choose Sensors..." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Z8r-qN-bMV">
169169
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
170170
<font key="font" metaFont="system"/>
@@ -178,6 +178,50 @@
178178
</binding>
179179
</connections>
180180
</button>
181+
<customView translatesAutoresizingMaskIntoConstraints="NO" id="dxG-rH-6k1">
182+
<rect key="frame" x="0.0" y="78" width="339" height="20"/>
183+
<subviews>
184+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Wmy-ty-OoB">
185+
<rect key="frame" x="-2" y="2" width="90" height="16"/>
186+
<textFieldCell key="cell" lineBreakMode="clipping" title="Display Mode:" id="hOI-r9-En3">
187+
<font key="font" metaFont="system"/>
188+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
189+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
190+
</textFieldCell>
191+
</textField>
192+
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="qTC-Gr-NIW">
193+
<rect key="frame" x="91" y="-4" width="89" height="25"/>
194+
<popUpButtonCell key="cell" type="push" title="Highest" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="U4K-aP-QjX" id="z7d-0t-1Xu">
195+
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
196+
<font key="font" metaFont="menu"/>
197+
<menu key="menu" id="JRc-s1-p7Z">
198+
<items>
199+
<menuItem title="Highest" state="on" id="U4K-aP-QjX"/>
200+
<menuItem title="Average" tag="1" id="pH3-eu-kox"/>
201+
</items>
202+
</menu>
203+
</popUpButtonCell>
204+
<connections>
205+
<binding destination="-2" name="selectedTag" keyPath="self.temperatureDisplayMode" id="NVU-P3-s6D"/>
206+
</connections>
207+
</popUpButton>
208+
</subviews>
209+
<constraints>
210+
<constraint firstAttribute="bottom" secondItem="qTC-Gr-NIW" secondAttribute="bottom" id="2Iq-LR-hiU"/>
211+
<constraint firstItem="Wmy-ty-OoB" firstAttribute="leading" secondItem="dxG-rH-6k1" secondAttribute="leading" id="9cr-9v-hql"/>
212+
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="qTC-Gr-NIW" secondAttribute="trailing" id="cXe-v6-vkd"/>
213+
<constraint firstItem="qTC-Gr-NIW" firstAttribute="leading" secondItem="Wmy-ty-OoB" secondAttribute="trailing" constant="8" symbolic="YES" id="egF-Rn-igw"/>
214+
<constraint firstItem="Wmy-ty-OoB" firstAttribute="centerY" secondItem="qTC-Gr-NIW" secondAttribute="centerY" id="iSK-TY-aO8"/>
215+
<constraint firstItem="qTC-Gr-NIW" firstAttribute="top" secondItem="dxG-rH-6k1" secondAttribute="top" id="lYu-Nb-orn"/>
216+
</constraints>
217+
<connections>
218+
<binding destination="-2" name="hidden" keyPath="self.isAppleSilicon" id="D74-wa-bHF">
219+
<dictionary key="options">
220+
<string key="NSValueTransformerName">NSNegateBoolean</string>
221+
</dictionary>
222+
</binding>
223+
</connections>
224+
</customView>
181225
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="O2I-yB-Cqr">
182226
<rect key="frame" x="0.0" y="60" width="317" height="5"/>
183227
</box>
@@ -202,6 +246,11 @@
202246
</connections>
203247
</button>
204248
</subviews>
249+
<constraints>
250+
<constraint firstAttribute="trailing" secondItem="9tp-fh-UvQ" secondAttribute="trailing" id="8SV-tp-Ri0"/>
251+
<constraint firstAttribute="trailing" secondItem="dxG-rH-6k1" secondAttribute="trailing" id="aDm-WO-P3a"/>
252+
<constraint firstAttribute="trailing" secondItem="EAB-dh-Hso" secondAttribute="trailing" id="fLN-Ft-mf7"/>
253+
</constraints>
205254
<visibilityPriorities>
206255
<integer value="1000"/>
207256
<integer value="1000"/>
@@ -213,6 +262,7 @@
213262
<integer value="1000"/>
214263
<integer value="1000"/>
215264
<integer value="1000"/>
265+
<integer value="1000"/>
216266
</visibilityPriorities>
217267
<customSpacing>
218268
<real value="3.4028234663852886e+38"/>
@@ -225,10 +275,11 @@
225275
<real value="3.4028234663852886e+38"/>
226276
<real value="3.4028234663852886e+38"/>
227277
<real value="3.4028234663852886e+38"/>
278+
<real value="3.4028234663852886e+38"/>
228279
</customSpacing>
229280
</stackView>
230281
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="mxk-B1-lA8">
231-
<rect key="frame" x="368" y="20" width="312" height="312"/>
282+
<rect key="frame" x="367" y="20" width="347" height="347"/>
232283
<constraints>
233284
<constraint firstAttribute="width" secondItem="mxk-B1-lA8" secondAttribute="height" multiplier="1:1" id="1gH-bx-NiI"/>
234285
</constraints>

0 commit comments

Comments
 (0)