Skip to content

Commit 149605f

Browse files
committed
Graph can now be detached as a floating panel.
1 parent 76c2b65 commit 149605f

File tree

10 files changed

+439
-17
lines changed

10 files changed

+439
-17
lines changed

Hot.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
05566A1A2990F85200E7A5F1 /* IOHID.m in Sources */ = {isa = PBXBuildFile; fileRef = 05566A022990F85200E7A5F1 /* IOHID.m */; };
3939
05566A1B2990F85200E7A5F1 /* SMC.m in Sources */ = {isa = PBXBuildFile; fileRef = 05566A042990F85200E7A5F1 /* SMC.m */; };
4040
05566A1C2990F85200E7A5F1 /* SMCData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05566A052990F85200E7A5F1 /* SMCData.swift */; };
41+
05566A75299195F400E7A5F1 /* GraphWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05566A74299195F400E7A5F1 /* GraphWindowController.swift */; };
42+
05566A782991963400E7A5F1 /* GraphWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 05566A772991963400E7A5F1 /* GraphWindowController.xib */; };
4143
055A9320252778C10070F771 /* InfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 055A931F252778C10070F771 /* InfoViewController.swift */; };
4244
055A9323252778D00070F771 /* InfoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 055A9321252778D00070F771 /* InfoViewController.xib */; };
4345
055A932525277E9E0070F771 /* IntegerToString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 055A932425277E9E0070F771 /* IntegerToString.swift */; };
@@ -139,6 +141,8 @@
139141
05566A052990F85200E7A5F1 /* SMCData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SMCData.swift; sourceTree = "<group>"; };
140142
05566A062990F85200E7A5F1 /* SMC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SMC.h; sourceTree = "<group>"; };
141143
05566A072990F85200E7A5F1 /* SMC-Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SMC-Internal.h"; sourceTree = "<group>"; };
144+
05566A74299195F400E7A5F1 /* GraphWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphWindowController.swift; sourceTree = "<group>"; };
145+
05566A772991963400E7A5F1 /* GraphWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GraphWindowController.xib; sourceTree = "<group>"; };
142146
055A931F252778C10070F771 /* InfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoViewController.swift; sourceTree = "<group>"; };
143147
055A9322252778D00070F771 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/InfoViewController.xib; sourceTree = "<group>"; };
144148
055A932425277E9E0070F771 /* IntegerToString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegerToString.swift; sourceTree = "<group>"; };
@@ -491,6 +495,7 @@
491495
05BA0BA926F342DA00AA7BFC /* PressureToString.swift */,
492496
05AA408C251CFA0600106CEA /* ThermalLog.swift */,
493497
05AD458729084FEF00A791C8 /* SelectSensorsWindowController.swift */,
498+
05566A74299195F400E7A5F1 /* GraphWindowController.swift */,
494499
);
495500
path = Classes;
496501
sourceTree = "<group>";
@@ -505,6 +510,7 @@
505510
052FBCA5251EE46700C4322E /* PreferencesWindowController.xib */,
506511
05221E8926700A57007246FF /* SensorViewController.xib */,
507512
05AD458E2908505900A791C8 /* SelectSensorsWindowController.xib */,
513+
05566A772991963400E7A5F1 /* GraphWindowController.xib */,
508514
);
509515
path = UI;
510516
sourceTree = "<group>";
@@ -613,6 +619,7 @@
613619
05AA407F251CF3D600106CEA /* MainMenu.xib in Resources */,
614620
052FBCD7251F842C00C4322E /* SchedulerTemplate.pdf in Resources */,
615621
05B0DFA626714A830068FF9B /* eAccTemplate.pdf in Resources */,
622+
05566A782991963400E7A5F1 /* GraphWindowController.xib in Resources */,
616623
05566A0A2990F85200E7A5F1 /* VoltageTemplate.pdf in Resources */,
617624
05566A122990F85200E7A5F1 /* SensorsWindowController.xib in Resources */,
618625
05B0DFAA267150F40068FF9B /* TCXCTemplate.pdf in Resources */,
@@ -671,6 +678,7 @@
671678
05AD458829084FEF00A791C8 /* SelectSensorsWindowController.swift in Sources */,
672679
05566A1A2990F85200E7A5F1 /* IOHID.m in Sources */,
673680
05566A0F2990F85200E7A5F1 /* ArrayIsNotEmpty.swift in Sources */,
681+
05566A75299195F400E7A5F1 /* GraphWindowController.swift in Sources */,
674682
05AA408D251CFA0600106CEA /* ThermalLog.swift in Sources */,
675683
055A932925277F990070F771 /* PercentToString.swift in Sources */,
676684
05566A132990F85200E7A5F1 /* ArrayIsEmpty.swift in Sources */,

Hot/Classes/ApplicationDelegate.swift

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate
3434
private var sensorsWindowController: SensorsWindowController?
3535
private var selectSensorsWindowController: SelectSensorsWindowController?
3636
private var sensorViewControllers: [ SensorViewController ] = []
37+
private var graphWindowController: GraphWindowController?
38+
private var exiting = false
3739

3840
@IBOutlet private var menu: NSMenu!
3941
@IBOutlet private var sensorsMenu: NSMenu!
@@ -73,6 +75,13 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate
7375

7476
self?.updateTitle()
7577
self?.updateSensors()
78+
79+
self?.graphWindowController?.graphView?.data = self?.infoViewController?.graphView?.data ?? []
80+
self?.graphWindowController?.schedulerLimit = self?.infoViewController?.schedulerLimit ?? 0
81+
self?.graphWindowController?.availableCPUs = self?.infoViewController?.availableCPUs ?? 0
82+
self?.graphWindowController?.speedLimit = self?.infoViewController?.speedLimit ?? 0
83+
self?.graphWindowController?.temperature = self?.infoViewController?.temperature ?? 0
84+
self?.graphWindowController?.thermalPressure = self?.infoViewController?.thermalPressure ?? 0
7685
}
7786

7887
UserDefaults.standard.addObserver( self, forKeyPath: "displayCPUTemperature", options: [], context: nil )
@@ -99,6 +108,19 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate
99108
self.updater.checkForUpdatesInBackground()
100109
}
101110
}
111+
112+
if UserDefaults.standard.bool( forKey: "showGraphPanel" )
113+
{
114+
DispatchQueue.main.asyncAfter( deadline: .now() + .seconds( 1 ) )
115+
{
116+
self.detachGraph( nil )
117+
}
118+
}
119+
}
120+
121+
func applicationWillTerminate( _ notification: Notification )
122+
{
123+
self.exiting = true
102124
}
103125

104126
private func initializePreferences()
@@ -412,8 +434,56 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate
412434

413435
func windowWillClose( _ notification: Notification )
414436
{
415-
self.sensorsWindowController?.stop( completion: nil )
437+
guard let window = notification.object as? NSWindow
438+
else
439+
{
440+
return
441+
}
442+
443+
if window == self.sensorsWindowController?.window
444+
{
445+
self.sensorsWindowController?.stop( completion: nil )
446+
447+
self.sensorsWindowController = nil
448+
}
449+
else if window == self.graphWindowController?.window
450+
{
451+
self.graphWindowController = nil
452+
453+
if self.exiting == false
454+
{
455+
UserDefaults.standard.set( false, forKey: "showGraphPanel" )
456+
}
457+
}
458+
}
459+
460+
@IBAction
461+
public func detachGraph( _ sender: Any? )
462+
{
463+
if self.graphWindowController == nil
464+
{
465+
self.graphWindowController = GraphWindowController()
466+
self.graphWindowController?.graphView?.data = self.infoViewController?.graphView?.data ?? []
467+
}
468+
469+
guard let window = self.graphWindowController?.window
470+
else
471+
{
472+
NSSound.beep()
473+
474+
return
475+
}
476+
477+
window.delegate = self
416478

417-
self.sensorsWindowController = nil
479+
if UserDefaults.standard.object( forKey: "NSWindow Frame GraphPanel" ) == nil
480+
{
481+
window.layoutIfNeeded()
482+
window.center()
483+
}
484+
485+
NSApp.activate( ignoringOtherApps: true )
486+
window.makeKeyAndOrderFront( nil )
487+
UserDefaults.standard.set( true, forKey: "showGraphPanel" )
418488
}
419489
}

Hot/Classes/GraphView.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import Cocoa
2626

2727
public class GraphView: NSView
2828
{
29-
public private( set ) var data = [ ( speed: Int, temperature: Int ) ]()
29+
public dynamic var data = [ ( speed: Int, temperature: Int ) ]()
30+
{
31+
didSet
32+
{
33+
self.needsDisplay = true
34+
}
35+
}
3036

3137
public func addData( speed: Int, temperature: Int )
3238
{
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2022, 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 Foundation
26+
27+
@objc
28+
public class GraphWindowController: NSWindowController
29+
{
30+
@IBOutlet public private( set ) var graphView: GraphView?
31+
32+
@objc public dynamic var schedulerLimit: Int = 0
33+
@objc public dynamic var availableCPUs: Int = 0
34+
@objc public dynamic var speedLimit: Int = 0
35+
@objc public dynamic var temperature: Int = 0
36+
@objc public dynamic var thermalPressure: Int = 0
37+
38+
#if arch( arm64 )
39+
@objc public private( set ) dynamic var isARM = true
40+
#else
41+
@objc public private( set ) dynamic var isARM = false
42+
#endif
43+
44+
public init()
45+
{
46+
super.init( window: nil )
47+
}
48+
49+
required init?( coder: NSCoder )
50+
{
51+
nil
52+
}
53+
54+
public override var windowNibName: NSNib.Name?
55+
{
56+
"GraphWindowController"
57+
}
58+
59+
public override func windowDidLoad()
60+
{
61+
super.windowDidLoad()
62+
}
63+
}

Hot/Classes/InfoViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class InfoViewController: NSViewController
4343
@objc public private( set ) dynamic var isARM = false
4444
#endif
4545

46-
@IBOutlet private var graphView: GraphView!
47-
@IBOutlet private var graphViewHeight: NSLayoutConstraint!
46+
@IBOutlet public private( set ) var graphView: GraphView?
47+
@IBOutlet private var graphViewHeight: NSLayoutConstraint!
4848

4949
deinit
5050
{
@@ -142,14 +142,14 @@ public class InfoViewController: NSViewController
142142

143143
if self.speedLimit > 0, self.temperature > 0
144144
{
145-
self.graphView.addData( speed: self.speedLimit, temperature: self.temperature )
145+
self.graphView?.addData( speed: self.speedLimit, temperature: self.temperature )
146146
}
147147
else if self.temperature > 0
148148
{
149-
self.graphView.addData( speed: 100, temperature: self.temperature )
149+
self.graphView?.addData( speed: 100, temperature: self.temperature )
150150
}
151151

152-
self.graphViewHeight.constant = self.graphView.canDisplay ? 100 : 0
152+
self.graphViewHeight.constant = self.graphView?.canDisplay ?? false ? 100 : 0
153153

154154
self.onUpdate?()
155155
}

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.8.0</string>
20+
<string>1.9.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>128</string>
22+
<string>129</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

Hot/UI/Base.lproj/InfoViewController.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<objects>

Hot/UI/Base.lproj/MainMenu.xib

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
66
</dependencies>
77
<objects>
88
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -718,6 +718,12 @@
718718
<action selector="viewAllSensors:" target="Voe-Tx-rLC" id="K7Q-o7-xbP"/>
719719
</connections>
720720
</menuItem>
721+
<menuItem title="Detach Graph..." id="xgZ-JM-aDy">
722+
<modifierMask key="keyEquivalentModifierMask"/>
723+
<connections>
724+
<action selector="detachGraph:" target="Voe-Tx-rLC" id="Tqg-wQ-nfG"/>
725+
</connections>
726+
</menuItem>
721727
<menuItem isSeparatorItem="YES" id="Nbp-cG-gpV"/>
722728
<menuItem title="Preferences..." keyEquivalent="," id="JFH-mp-6PU">
723729
<connections>

Hot/UI/Base.lproj/SelectSensorsWindowController.xib

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<objects>
@@ -59,8 +59,8 @@
5959
<font key="font" metaFont="system"/>
6060
</buttonCell>
6161
<connections>
62-
<binding destination="78O-9Q-VPc" name="title" keyPath="objectValue.name" id="Qyl-XD-RiT"/>
6362
<binding destination="78O-9Q-VPc" name="value" keyPath="objectValue.enabled" id="G1w-mW-e0L"/>
63+
<binding destination="78O-9Q-VPc" name="title" keyPath="objectValue.name" id="Qyl-XD-RiT"/>
6464
</connections>
6565
</button>
6666
</subviews>

0 commit comments

Comments
 (0)