@@ -151,7 +151,6 @@ internal class Popup: PopupWrapper {
151
151
value. reversed ( ) . forEach { ( drive: drive ) in
152
152
if let view = views. first ( where: { $0. name == drive. mediaName } ) {
153
153
view. updateReadWrite ( read: drive. activity. read, write: drive. activity. write)
154
- view. updateReadWritten ( read: drive. activity. readBytes, written: drive. activity. writeBytes)
155
154
}
156
155
}
157
156
}
@@ -281,25 +280,13 @@ internal class DiskView: NSStackView {
281
280
private var chartView : ChartView
282
281
private var barView : BarView
283
282
private var legendView : LegendView
284
- private var readView : SpeedView ?
285
- private var writeView : SpeedView ?
286
- private var readDataView : DataView
287
- private var writtenDataView : DataView
288
- private var temperatureView : TemperatureView ?
289
- private var lifeView : LifeView ?
283
+ private var detailsView : DetailsView
290
284
291
285
private var detailsState : Bool {
292
286
get { Store . shared. bool ( key: " \( self . uuid) _details " , defaultValue: false ) }
293
287
set { Store . shared. set ( key: " \( self . uuid) _details " , value: newValue) }
294
288
}
295
289
296
- private var readColor : NSColor {
297
- SColor . fromString ( Store . shared. string ( key: " \( ModuleType . disk. stringValue) _readColor " , defaultValue: SColor . secondBlue. key) ) . additional as! NSColor
298
- }
299
- private var writeColor : NSColor {
300
- SColor . fromString ( Store . shared. string ( key: " \( ModuleType . disk. stringValue) _writeColor " , defaultValue: SColor . secondRed. key) ) . additional as! NSColor
301
- }
302
-
303
290
init ( width: CGFloat , uuid: String = " " , name: String = " " , size: Int64 = 1 , free: Int64 = 1 , path: URL ? = nil , smart: smart_t ? = nil , resize: @escaping ( ) -> Void ) {
304
291
self . sizeCallback = resize
305
292
self . uuid = uuid
@@ -310,18 +297,10 @@ internal class DiskView: NSStackView {
310
297
self . chartView = ChartView ( width: innerWidth)
311
298
self . barView = BarView ( width: innerWidth, size: size, free: free)
312
299
self . legendView = LegendView ( width: innerWidth, id: " \( name) _ \( path? . absoluteString ?? " " ) " , size: size, free: free)
313
- self . readDataView = DataView ( width: innerWidth, title: " \( localizedString ( " Total read " ) ) : " )
314
- self . writtenDataView = DataView ( width: innerWidth, title: " \( localizedString ( " Total written " ) ) : " )
315
- if let smart {
316
- self . temperatureView = TemperatureView ( width: innerWidth, smart: smart)
317
- self . lifeView = LifeView ( width: innerWidth, smart: smart)
318
- }
300
+ self . detailsView = DetailsView ( width: innerWidth, id: " \( name) _ \( path? . absoluteString ?? " " ) " , smart: smart)
319
301
320
302
super. init ( frame: NSRect ( x: 0 , y: 0 , width: width, height: 0 ) )
321
303
322
- self . readView = SpeedView ( width: innerWidth, title: " \( localizedString ( " Read " ) ) : " , color: self . readColor)
323
- self . writeView = SpeedView ( width: innerWidth, title: " \( localizedString ( " Write " ) ) : " , color: self . writeColor)
324
-
325
304
self . widthAnchor. constraint ( equalToConstant: width) . isActive = true
326
305
self . orientation = . vertical
327
306
self . distribution = . fillProportionally
@@ -340,6 +319,7 @@ internal class DiskView: NSStackView {
340
319
self . addArrangedSubview ( self . chartView)
341
320
self . addArrangedSubview ( self . barView)
342
321
self . addArrangedSubview ( self . legendView)
322
+ self . addArrangedSubview ( self . detailsView)
343
323
344
324
self . toggleDetails ( )
345
325
}
@@ -356,19 +336,13 @@ internal class DiskView: NSStackView {
356
336
self . nameView. update ( free: free, read: nil , write: nil )
357
337
self . legendView. update ( free: free)
358
338
self . barView. update ( free: free)
359
- self . temperatureView? . update ( smart)
360
- self . lifeView? . update ( smart)
339
+ self . detailsView. update ( smart: smart)
361
340
}
362
341
363
342
public func updateReadWrite( read: Int64 , write: Int64 ) {
364
- self . readView? . update ( read)
365
- self . writeView? . update ( write)
366
343
self . nameView. update ( free: nil , read: read, write: write)
367
344
self . chartView. update ( read: read, write: write)
368
- }
369
- public func updateReadWritten( read: Int64 , written: Int64 ) {
370
- self . readDataView. update ( read)
371
- self . writtenDataView. update ( written)
345
+ self . detailsView. update ( read: read, write: write)
372
346
}
373
347
public func setChartColor( read: NSColor ? = nil , write: NSColor ? = nil ) {
374
348
self . chartView. setColors ( read: read, write: write)
@@ -379,25 +353,9 @@ internal class DiskView: NSStackView {
379
353
380
354
private func toggleDetails( ) {
381
355
if self . detailsState {
382
- if let view = self . readView {
383
- self . addArrangedSubview ( view)
384
- }
385
- if let view = self . writeView {
386
- self . addArrangedSubview ( view)
387
- }
388
- self . addArrangedSubview ( self . readDataView)
389
- self . addArrangedSubview ( self . writtenDataView)
390
- if let temperatureView = self . temperatureView, let lifeView = self . lifeView {
391
- self . addArrangedSubview ( temperatureView)
392
- self . addArrangedSubview ( lifeView)
393
- }
356
+ self . addArrangedSubview ( self . detailsView)
394
357
} else {
395
- self . readView? . removeFromSuperview ( )
396
- self . writeView? . removeFromSuperview ( )
397
- self . readDataView. removeFromSuperview ( )
398
- self . writtenDataView. removeFromSuperview ( )
399
- self . temperatureView? . removeFromSuperview ( )
400
- self . lifeView? . removeFromSuperview ( )
358
+ self . detailsView. removeFromSuperview ( )
401
359
}
402
360
403
361
let h = self . arrangedSubviews. map ( { $0. bounds. height + self . spacing } ) . reduce ( 0 , + ) - 5 + 10
@@ -636,12 +594,8 @@ internal class LegendView: NSView {
636
594
private var ready : Bool = false
637
595
638
596
private var showUsedSpace : Bool {
639
- get {
640
- Store . shared. bool ( key: " \( self . id) _usedSpace " , defaultValue: false )
641
- }
642
- set {
643
- Store . shared. set ( key: " \( self . id) _usedSpace " , value: newValue)
644
- }
597
+ get { Store . shared. bool ( key: " \( self . id) _usedSpace " , defaultValue: false ) }
598
+ set { Store . shared. set ( key: " \( self . id) _usedSpace " , value: newValue) }
645
599
}
646
600
647
601
private var legendField : NSTextField ? = nil
@@ -757,173 +711,128 @@ internal class LegendView: NSView {
757
711
}
758
712
}
759
713
760
- internal class TemperatureView : NSStackView {
761
- private var initialized : Bool = false
762
- private let field : NSTextField = TextView ( )
763
-
764
- init ( width: CGFloat , smart: smart_t ) {
765
- super. init ( frame: CGRect ( x: 0 , y: 0 , width: width, height: 16 ) )
766
-
767
- self . orientation = . horizontal
768
- self . spacing = 0
769
-
770
- let title = TextView ( )
771
- title. font = NSFont . systemFont ( ofSize: 11 , weight: . light)
772
- title. stringValue = " \( localizedString ( " Temperature " ) ) : "
773
- title. cell? . truncatesLastVisibleLine = true
774
-
775
- self . field. font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
776
- self . field. alignment = . right
777
- self . field. stringValue = " \( temperature ( Double ( smart. temperature) ) ) "
778
-
779
- self . addArrangedSubview ( title)
780
- self . addArrangedSubview ( NSView ( ) )
781
- self . addArrangedSubview ( self . field)
782
-
783
- self . widthAnchor. constraint ( equalToConstant: self . frame. width) . isActive = true
784
- self . heightAnchor. constraint ( equalToConstant: self . frame. height) . isActive = true
714
+ internal class DetailsView : NSStackView {
715
+ private var smartHeight : CGFloat {
716
+ get { ( 22 * 6 ) + Constants. Popup. separatorHeight }
785
717
}
786
718
787
- required init ? ( coder: NSCoder ) {
788
- fatalError ( " init(coder:) has not been implemented " )
789
- }
719
+ private var readSpeedValueField : ValueField ?
720
+ private var writeSpeedValueField : ValueField ?
790
721
791
- public func update( _ newValue: smart_t ? ) {
792
- if ( self . window? . isVisible ?? false ) || !self . initialized {
793
- if let newValue {
794
- self . field. stringValue = " \( temperature ( Double ( newValue. temperature) ) ) "
795
- } else {
796
- self . field. stringValue = " - "
797
- }
798
- self . initialized = true
799
- }
722
+ private var totalReadValueField : ValueField ?
723
+ private var totalWrittenValueField : ValueField ?
724
+ private var temperatureValueField : ValueField ?
725
+ private var healthValueField : ValueField ?
726
+ private var powerCyclesValueField : ValueField ?
727
+ private var powerOnHoursValueField : ValueField ?
728
+
729
+ private var readColor : NSColor {
730
+ SColor . fromString ( Store . shared. string ( key: " \( ModuleType . disk. stringValue) _readColor " , defaultValue: SColor . secondBlue. key) ) . additional as! NSColor
731
+ }
732
+ private var writeColor : NSColor {
733
+ SColor . fromString ( Store . shared. string ( key: " \( ModuleType . disk. stringValue) _writeColor " , defaultValue: SColor . secondRed. key) ) . additional as! NSColor
800
734
}
801
- }
802
-
803
- internal class LifeView : NSStackView {
804
- private var initialized : Bool = false
805
- private let field : NSTextField = TextView ( )
806
735
807
- init ( width: CGFloat , smart: smart_t ) {
808
- super. init ( frame: CGRect ( x: 0 , y: 0 , width: width, height: 16 ) )
736
+ public init ( width: CGFloat , id : String , smart: smart_t ? = nil ) {
737
+ super. init ( frame: CGRect ( x: 0 , y: 0 , width: width, height: 0 ) )
809
738
810
- self . orientation = . horizontal
739
+ self . orientation = . vertical
740
+ self . distribution = . fillProportionally
811
741
self . spacing = 0
812
742
813
- let title = TextView ( )
814
- title. font = NSFont . systemFont ( ofSize: 11 , weight: . light)
815
- title. stringValue = " \( localizedString ( " Health " ) ) : "
816
- title. cell? . truncatesLastVisibleLine = true
817
-
818
- self . field. font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
819
- self . field. alignment = . right
820
- self . field. stringValue = " \( smart. life) % "
743
+ self . addArrangedSubview ( self . initSpeed ( ) )
744
+ self . addArrangedSubview ( self . initSmart ( ) )
821
745
822
- self . addArrangedSubview ( title)
823
- self . addArrangedSubview ( NSView ( ) )
824
- self . addArrangedSubview ( self . field)
825
-
826
- self . widthAnchor. constraint ( equalToConstant: self . frame. width) . isActive = true
827
- self . heightAnchor. constraint ( equalToConstant: self . frame. height) . isActive = true
746
+ self . recalculateHeight ( )
828
747
}
829
748
830
749
required init ? ( coder: NSCoder ) {
831
750
fatalError ( " init(coder:) has not been implemented " )
832
751
}
833
752
834
- public func update( _ newValue: smart_t ? ) {
835
- if ( self . window? . isVisible ?? false ) || !self . initialized {
836
- if let newValue {
837
- self . field. stringValue = " \( newValue. life) % "
753
+ private func recalculateHeight( ) {
754
+ var h : CGFloat = 0
755
+ self . arrangedSubviews. forEach { v in
756
+ if let v = v as? NSStackView {
757
+ h += v. arrangedSubviews. map ( { $0. bounds. height } ) . reduce ( 0 , + )
838
758
} else {
839
- self . field . stringValue = " - "
759
+ h += v . bounds . height
840
760
}
841
- self . initialized = true
761
+ }
762
+ if self . frame. size. height != h {
763
+ self . setFrameSize ( NSSize ( width: self . frame. width, height: h) )
842
764
}
843
765
}
844
- }
845
-
846
- internal class DataView : NSStackView {
847
- private var initialized : Bool = false
848
- private let field : NSTextField = TextView ( )
849
766
850
- init ( width: CGFloat , title: String ) {
851
- super. init ( frame: CGRect ( x: 0 , y: 0 , width: width, height: 16 ) )
767
+ private func initSpeed( ) -> NSView {
768
+ let view : NSView = NSView ( frame: NSRect ( x: 0 , y: 0 , width: self . frame. width, height: 44 ) )
769
+ view. widthAnchor. constraint ( equalToConstant: view. bounds. width) . isActive = true
770
+ view. heightAnchor. constraint ( equalToConstant: view. bounds. height) . isActive = true
771
+ let container : NSStackView = NSStackView ( frame: NSRect ( x: 0 , y: 0 , width: view. frame. width, height: view. frame. height) )
772
+ container. orientation = . vertical
773
+ container. spacing = 0
852
774
853
- self . orientation = . horizontal
854
- self . spacing = 0
855
-
856
- let titleField = TextView ( )
857
- titleField. font = NSFont . systemFont ( ofSize: 11 , weight: . light)
858
- titleField. stringValue = title
859
- titleField. cell? . truncatesLastVisibleLine = true
775
+ ( _, _, self . readSpeedValueField) = popupWithColorRow ( container, color: self . readColor, title: " \( localizedString ( " Read " ) ) : " , value: " 0 KB/s " )
776
+ ( _, _, self . writeSpeedValueField) = popupWithColorRow ( container, color: self . writeColor, title: " \( localizedString ( " Write " ) ) : " , value: " 0 KB/s " )
860
777
861
- self . field. font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
862
- self . field. alignment = . right
863
- self . field. stringValue = " 0 "
778
+ self . readSpeedValueField? . font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
779
+ self . writeSpeedValueField? . font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
864
780
865
- self . addArrangedSubview ( titleField)
866
- self . addArrangedSubview ( NSView ( ) )
867
- self . addArrangedSubview ( self . field)
781
+ view. addSubview ( container)
868
782
869
- self . widthAnchor. constraint ( equalToConstant: self . frame. width) . isActive = true
870
- self . heightAnchor. constraint ( equalToConstant: self . frame. height) . isActive = true
783
+ return view
871
784
}
872
785
873
- required init ? ( coder: NSCoder ) {
874
- fatalError ( " init(coder:) has not been implemented " )
786
+ private func initSmart( ) -> NSView {
787
+ let view : NSView = NSView ( frame: NSRect ( x: 0 , y: 0 , width: self . frame. width, height: self . smartHeight) )
788
+ view. widthAnchor. constraint ( equalToConstant: view. bounds. width) . isActive = true
789
+ view. heightAnchor. constraint ( equalToConstant: view. bounds. height) . isActive = true
790
+ let separator = separatorView ( localizedString ( " SMART " ) , origin: NSPoint ( x: 0 , y: self . smartHeight- Constants. Popup. separatorHeight) , width: self . frame. width)
791
+ let container : NSStackView = NSStackView ( frame: NSRect ( x: 0 , y: 0 , width: view. frame. width, height: separator. frame. origin. y) )
792
+ container. orientation = . vertical
793
+ container. spacing = 0
794
+
795
+ self . totalReadValueField = popupRow ( container, title: " \( localizedString ( " Total read " ) ) : " , value: " 0 KB " ) . 1
796
+ self . totalWrittenValueField = popupRow ( container, title: " \( localizedString ( " Total written " ) ) : " , value: " 0 KB " ) . 1
797
+ self . temperatureValueField = popupRow ( container, title: " \( localizedString ( " Temperature " ) ) : " , value: " \( temperature ( 0 ) ) " ) . 1
798
+ self . healthValueField = popupRow ( container, title: " \( localizedString ( " Health " ) ) : " , value: " 0% " ) . 1
799
+ self . powerCyclesValueField = popupRow ( container, title: " \( localizedString ( " Power cycles " ) ) : " , value: " 0 " ) . 1
800
+ self . powerOnHoursValueField = popupRow ( container, title: " \( localizedString ( " Power on hours " ) ) : " , value: " 0 " ) . 1
801
+
802
+ self . totalReadValueField? . font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
803
+ self . totalWrittenValueField? . font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
804
+ self . temperatureValueField? . font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
805
+ self . healthValueField? . font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
806
+ self . powerCyclesValueField? . font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
807
+ self . powerOnHoursValueField? . font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
808
+
809
+ view. addSubview ( separator)
810
+ view. addSubview ( container)
811
+
812
+ return view
875
813
}
876
814
877
- public func update( _ newValue: Int64 ) {
878
- if ( self . window? . isVisible ?? false ) || !self . initialized {
879
- self . field. stringValue = Units ( bytes: newValue) . getReadableMemory ( )
880
- self . initialized = true
815
+ public func update( read: Int64 ? , write: Int64 ? ) {
816
+ guard self . window? . isVisible ?? false else { return }
817
+
818
+ if let read = read {
819
+ self . readSpeedValueField? . stringValue = Units ( bytes: read) . getReadableSpeed ( )
820
+ }
821
+ if let write = write {
822
+ self . writeSpeedValueField? . stringValue = Units ( bytes: write) . getReadableSpeed ( )
881
823
}
882
824
}
883
- }
884
- internal class SpeedView : NSStackView {
885
- private var initialized : Bool = false
886
- private let field : NSTextField = TextView ( )
887
825
888
- init ( width: CGFloat , title: String , color: NSColor ) {
889
- super. init ( frame: CGRect ( x: 0 , y: 0 , width: width, height: 16 ) )
890
-
891
- self . orientation = . horizontal
892
- self . spacing = 0
893
-
894
- let colorView : NSView = NSView ( frame: NSRect ( x: 0 , y: 0 , width: 12 , height: 12 ) )
895
- colorView. widthAnchor. constraint ( equalToConstant: 12 ) . isActive = true
896
- colorView. heightAnchor. constraint ( equalToConstant: 12 ) . isActive = true
897
- colorView. wantsLayer = true
898
- colorView. layer? . backgroundColor = color. cgColor
899
- colorView. layer? . cornerRadius = 2
826
+ public func update( smart: smart_t ? ) {
827
+ guard self . window? . isVisible ?? false , let smart else { return }
900
828
901
- let titleField = TextView ( )
902
- titleField. font = NSFont . systemFont ( ofSize: 11 , weight: . light)
903
- titleField. stringValue = title
904
- titleField. cell? . truncatesLastVisibleLine = true
829
+ self . totalReadValueField? . stringValue = Units ( bytes: smart. totalRead) . getReadableMemory ( style: . decimal)
830
+ self . totalWrittenValueField? . stringValue = Units ( bytes: smart. totalWritten) . getReadableMemory ( style: . decimal)
905
831
906
- self . field. font = NSFont . systemFont ( ofSize: 11 , weight: . regular)
907
- self . field. alignment = . right
908
- self . field. stringValue = " 0 "
832
+ self . temperatureValueField? . stringValue = " \( temperature ( Double ( smart. temperature) ) ) "
833
+ self . healthValueField? . stringValue = " \( smart. life) % "
909
834
910
- self . addArrangedSubview ( colorView)
911
- self . addArrangedSubview ( titleField)
912
- self . addArrangedSubview ( NSView ( ) )
913
- self . addArrangedSubview ( self . field)
914
-
915
- self . widthAnchor. constraint ( equalToConstant: self . frame. width) . isActive = true
916
- self . heightAnchor. constraint ( equalToConstant: self . frame. height) . isActive = true
917
- }
918
-
919
- required init ? ( coder: NSCoder ) {
920
- fatalError ( " init(coder:) has not been implemented " )
921
- }
922
-
923
- public func update( _ newValue: Int64 ) {
924
- if ( self . window? . isVisible ?? false ) || !self . initialized {
925
- self . field. stringValue = Units ( bytes: newValue) . getReadableSpeed ( )
926
- self . initialized = true
927
- }
835
+ self . powerCyclesValueField? . stringValue = " \( smart. powerCycles) "
836
+ self . powerOnHoursValueField? . stringValue = " \( smart. powerOnHours) "
928
837
}
929
838
}
0 commit comments