@@ -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}
0 commit comments