mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
40
README.md
40
README.md
@@ -1,19 +1,30 @@
|
||||
# Stats
|
||||
Application for macos that shows CPU, Memory and Disk usage on the menu bar
|
||||
Simple macOS system monitor in your menu bar
|
||||
|
||||
[<img src="https://serhiy.s3.eu-central-1.amazonaws.com/Github_repo/stats/widgets%3Fv1.0.0.png" width="500">](https://github.com/exelban/stats/releases)
|
||||
[<img src="https://serhiy.s3.eu-central-1.amazonaws.com/Github_repo/stats/widgets%3Fv1.1.0.1.png">](https://github.com/exelban/stats/releases)
|
||||
|
||||
## Why
|
||||
Stats is a application which allows you to monitor your macOS system.
|
||||
Also its:
|
||||
|
||||
- free
|
||||
- easy to use
|
||||
- no advertisement
|
||||
- no tracking
|
||||
- few types of widgets
|
||||
- black theme compatible
|
||||
|
||||
## Installation
|
||||
You can download latest version [here](https://github.com/exelban/stats/releases).
|
||||
|
||||
## Widgets
|
||||
Each widget can be disabled in menu.
|
||||
## Modules
|
||||
|
||||
| Name | Type | Description |
|
||||
| Name | Available widgets | Description |
|
||||
| --- | --- | --- |
|
||||
| **CPU** | Percentage | Shows CPU usage |
|
||||
| **Memory** | Percentage | Shows RAM usage |
|
||||
| **CPU** | Percentage / Chart / Chart with value | Shows CPU usage |
|
||||
| **Memory** | Percentage / Chart / Chart with value | Shows RAM usage |
|
||||
| **Disk** | Percentage | Shows disk filling |
|
||||
| **Battery** | Graphic / Percentage | Shows battery level and charging status |
|
||||
|
||||
## Compatibility
|
||||
| macOS | Compatible |
|
||||
@@ -22,18 +33,27 @@ Each widget can be disabled in menu.
|
||||
| 10.14.1 *(Mojave)* | **true** |
|
||||
|
||||
## Todo
|
||||
- [ ] Battery percentage
|
||||
- [ ] Create new logo
|
||||
- [ ] Window with preferences
|
||||
- [ ] Save last modules values
|
||||
- [ ] Colors toggle for each module
|
||||
- [ ] temperature module
|
||||
- [ ] battery module
|
||||
- [X] battery module
|
||||
- [X] move to module system (CPU, RAM, DISK)
|
||||
- [ ] network module
|
||||
- [X] save settings
|
||||
- [ ] tests
|
||||
- [ ] OTA updates
|
||||
- [ ] charts
|
||||
- [X] charts
|
||||
- [X] autostart on boot
|
||||
|
||||
## What's new
|
||||
|
||||
### v1.1.0
|
||||
- added battery module
|
||||
- added chart widget for CPU and Memory
|
||||
- added About Stats window
|
||||
|
||||
### v1.0.0
|
||||
- first release
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
9A09C89E22B3A7C90018426F /* Battery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A09C89D22B3A7C90018426F /* Battery.swift */; };
|
||||
9A09C8A022B3A7E20018426F /* BatteryReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A09C89F22B3A7E20018426F /* BatteryReader.swift */; };
|
||||
9A09C8A222B3D94D0018426F /* BatteryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A09C8A122B3D94D0018426F /* BatteryView.swift */; };
|
||||
9A1410F9229E721100D29793 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A1410F8229E721100D29793 /* AppDelegate.swift */; };
|
||||
9A141100229E721200D29793 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9A1410FE229E721200D29793 /* Main.storyboard */; };
|
||||
9A57A18522A1D26D0033E318 /* MenuBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A57A18422A1D26D0033E318 /* MenuBar.swift */; };
|
||||
@@ -15,10 +18,9 @@
|
||||
9A5B1CBF229E78F0008B9D3C /* Observable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A5B1CBE229E78F0008B9D3C /* Observable.swift */; };
|
||||
9A5B1CC5229E7B40008B9D3C /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A5B1CC4229E7B40008B9D3C /* Extensions.swift */; };
|
||||
9A6CFC0122A1C9F5001E782D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9A6CFC0022A1C9F5001E782D /* Assets.xcassets */; };
|
||||
9A7B8F5B22A290A200DEB352 /* CPU.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9A7B8F5A22A290A200DEB352 /* CPU.xib */; };
|
||||
9A74D59422B4315C004FE1FA /* Chart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A74D59322B4315C004FE1FA /* Chart.swift */; };
|
||||
9A74D59722B44498004FE1FA /* Mini.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A74D59622B44498004FE1FA /* Mini.swift */; };
|
||||
9A7B8F5E22A2A57600DEB352 /* CPUReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A7B8F5D22A2A57600DEB352 /* CPUReader.swift */; };
|
||||
9A7B8F6522A2C19D00DEB352 /* Memory.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9A7B8F6422A2C19D00DEB352 /* Memory.xib */; };
|
||||
9A7B8F6722A2C1B900DEB352 /* Disk.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9A7B8F6622A2C1B900DEB352 /* Disk.xib */; };
|
||||
9A7B8F6922A2C3A100DEB352 /* Memory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A7B8F6822A2C3A100DEB352 /* Memory.swift */; };
|
||||
9A7B8F6B22A2C3A700DEB352 /* Disk.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A7B8F6A22A2C3A700DEB352 /* Disk.swift */; };
|
||||
9A7B8F6D22A2C3D600DEB352 /* MemoryReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A7B8F6C22A2C3D600DEB352 /* MemoryReader.swift */; };
|
||||
@@ -27,6 +29,7 @@
|
||||
9AFA402822AE49A200FE90BC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9AFA402622AE49A200FE90BC /* Main.storyboard */; };
|
||||
9AFA402F22AE49AE00FE90BC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AFA402E22AE49AE00FE90BC /* AppDelegate.swift */; };
|
||||
9AFA403022AE49DD00FE90BC /* StatsLauncher.app in Copy Files */ = {isa = PBXBuildFile; fileRef = 9AFA401E22AE49A100FE90BC /* StatsLauncher.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
9AFFCB3B22B3FD0500B0E6D8 /* About.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9AFFCB3A22B3FD0500B0E6D8 /* About.storyboard */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
@@ -44,6 +47,9 @@
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
9A09C89D22B3A7C90018426F /* Battery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Battery.swift; sourceTree = "<group>"; };
|
||||
9A09C89F22B3A7E20018426F /* BatteryReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryReader.swift; sourceTree = "<group>"; };
|
||||
9A09C8A122B3D94D0018426F /* BatteryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryView.swift; sourceTree = "<group>"; };
|
||||
9A1410F5229E721100D29793 /* Stats.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Stats.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
9A1410F8229E721100D29793 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
9A1410FF229E721200D29793 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
@@ -55,10 +61,9 @@
|
||||
9A5B1CBE229E78F0008B9D3C /* Observable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Observable.swift; sourceTree = "<group>"; };
|
||||
9A5B1CC4229E7B40008B9D3C /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
|
||||
9A6CFC0022A1C9F5001E782D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
9A7B8F5A22A290A200DEB352 /* CPU.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CPU.xib; sourceTree = "<group>"; };
|
||||
9A74D59322B4315C004FE1FA /* Chart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Chart.swift; sourceTree = "<group>"; };
|
||||
9A74D59622B44498004FE1FA /* Mini.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mini.swift; sourceTree = "<group>"; };
|
||||
9A7B8F5D22A2A57600DEB352 /* CPUReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CPUReader.swift; sourceTree = "<group>"; };
|
||||
9A7B8F6422A2C19D00DEB352 /* Memory.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = Memory.xib; sourceTree = "<group>"; };
|
||||
9A7B8F6622A2C1B900DEB352 /* Disk.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = Disk.xib; sourceTree = "<group>"; };
|
||||
9A7B8F6822A2C3A100DEB352 /* Memory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Memory.swift; sourceTree = "<group>"; };
|
||||
9A7B8F6A22A2C3A700DEB352 /* Disk.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Disk.swift; sourceTree = "<group>"; };
|
||||
9A7B8F6C22A2C3D600DEB352 /* MemoryReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryReader.swift; sourceTree = "<group>"; };
|
||||
@@ -71,6 +76,7 @@
|
||||
9AFA402922AE49A200FE90BC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
9AFA402A22AE49A200FE90BC /* StatsLauncher.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = StatsLauncher.entitlements; sourceTree = "<group>"; };
|
||||
9AFA402E22AE49AE00FE90BC /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
9AFFCB3A22B3FD0500B0E6D8 /* About.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = About.storyboard; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -91,6 +97,15 @@
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
9A09C89C22B3A7BB0018426F /* Battery */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A09C89D22B3A7C90018426F /* Battery.swift */,
|
||||
9A09C89F22B3A7E20018426F /* BatteryReader.swift */,
|
||||
);
|
||||
path = Battery;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9A1410EC229E721100D29793 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -113,6 +128,7 @@
|
||||
9A1410F7229E721100D29793 /* Stats */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A74D59522B440D4004FE1FA /* Widgets */,
|
||||
9A5B1CB3229E72A7008B9D3C /* Supporting Files */,
|
||||
9A5B1CBA229E7892008B9D3C /* Modules */,
|
||||
9A5B1CBD229E78D2008B9D3C /* libs */,
|
||||
@@ -126,6 +142,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A6CFC0022A1C9F5001E782D /* Assets.xcassets */,
|
||||
9AFFCB3A22B3FD0500B0E6D8 /* About.storyboard */,
|
||||
9A1410FE229E721200D29793 /* Main.storyboard */,
|
||||
9A141101229E721200D29793 /* Info.plist */,
|
||||
9A141102229E721200D29793 /* Stats.entitlements */,
|
||||
@@ -136,6 +153,7 @@
|
||||
9A5B1CBA229E7892008B9D3C /* Modules */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A09C89C22B3A7BB0018426F /* Battery */,
|
||||
9A7B8F5C22A2926500DEB352 /* CPU */,
|
||||
9A7B8F6222A2C17000DEB352 /* Memory */,
|
||||
9A7B8F6322A2C17500DEB352 /* Disk */,
|
||||
@@ -153,10 +171,19 @@
|
||||
path = libs;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9A74D59522B440D4004FE1FA /* Widgets */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A09C8A122B3D94D0018426F /* BatteryView.swift */,
|
||||
9A74D59322B4315C004FE1FA /* Chart.swift */,
|
||||
9A74D59622B44498004FE1FA /* Mini.swift */,
|
||||
);
|
||||
path = Widgets;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9A7B8F5C22A2926500DEB352 /* CPU */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A7B8F5A22A290A200DEB352 /* CPU.xib */,
|
||||
9A57A19C22A1E3270033E318 /* CPU.swift */,
|
||||
9A7B8F5D22A2A57600DEB352 /* CPUReader.swift */,
|
||||
);
|
||||
@@ -166,7 +193,6 @@
|
||||
9A7B8F6222A2C17000DEB352 /* Memory */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A7B8F6422A2C19D00DEB352 /* Memory.xib */,
|
||||
9A7B8F6822A2C3A100DEB352 /* Memory.swift */,
|
||||
9A7B8F6C22A2C3D600DEB352 /* MemoryReader.swift */,
|
||||
);
|
||||
@@ -176,7 +202,6 @@
|
||||
9A7B8F6322A2C17500DEB352 /* Disk */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A7B8F6622A2C1B900DEB352 /* Disk.xib */,
|
||||
9A7B8F6A22A2C3A700DEB352 /* Disk.swift */,
|
||||
9A7B8F6E22A2C57000DEB352 /* DiskReader.swift */,
|
||||
);
|
||||
@@ -284,10 +309,8 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
9A7B8F5B22A290A200DEB352 /* CPU.xib in Resources */,
|
||||
9A6CFC0122A1C9F5001E782D /* Assets.xcassets in Resources */,
|
||||
9A7B8F6722A2C1B900DEB352 /* Disk.xib in Resources */,
|
||||
9A7B8F6522A2C19D00DEB352 /* Memory.xib in Resources */,
|
||||
9AFFCB3B22B3FD0500B0E6D8 /* About.storyboard in Resources */,
|
||||
9A141100229E721200D29793 /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -308,16 +331,21 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
9A09C8A222B3D94D0018426F /* BatteryView.swift in Sources */,
|
||||
9A7B8F6F22A2C57000DEB352 /* DiskReader.swift in Sources */,
|
||||
9A7B8F6922A2C3A100DEB352 /* Memory.swift in Sources */,
|
||||
9A7B8F5E22A2A57600DEB352 /* CPUReader.swift in Sources */,
|
||||
9A74D59422B4315C004FE1FA /* Chart.swift in Sources */,
|
||||
9A09C89E22B3A7C90018426F /* Battery.swift in Sources */,
|
||||
9A7B8F6D22A2C3D600DEB352 /* MemoryReader.swift in Sources */,
|
||||
9A57A18522A1D26D0033E318 /* MenuBar.swift in Sources */,
|
||||
9A57A19D22A1E3270033E318 /* CPU.swift in Sources */,
|
||||
9A09C8A022B3A7E20018426F /* BatteryReader.swift in Sources */,
|
||||
9A57A19B22A1E1C50033E318 /* Module.swift in Sources */,
|
||||
9A5B1CBF229E78F0008B9D3C /* Observable.swift in Sources */,
|
||||
9A7B8F6B22A2C3A700DEB352 /* Disk.swift in Sources */,
|
||||
9A1410F9229E721100D29793 /* AppDelegate.swift in Sources */,
|
||||
9A74D59722B44498004FE1FA /* Mini.swift in Sources */,
|
||||
9A5B1CC5229E7B40008B9D3C /* Extensions.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
||||
@@ -13,7 +13,7 @@ extension Notification.Name {
|
||||
static let killLauncher = Notification.Name("killLauncher")
|
||||
}
|
||||
|
||||
let modules: Observable<[Module]> = Observable([CPU(), Memory(), Disk()])
|
||||
let modules: Observable<[Module]> = Observable([CPU(), Memory(), Disk(), Battery()])
|
||||
let colors: Observable<Bool> = Observable(true)
|
||||
|
||||
@NSApplicationMain
|
||||
@@ -54,3 +54,30 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AboutVC: NSViewController {
|
||||
@IBOutlet weak var versionLabel: NSTextField!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
self.view.wantsLayer = true
|
||||
}
|
||||
|
||||
@IBAction func openLink(_ sender: Any) {
|
||||
NSWorkspace.shared.open(URL(string: "https://github.com/exelban/stats")!)
|
||||
}
|
||||
|
||||
@IBAction func exit(_ sender: Any) {
|
||||
self.view.window?.close()
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
if self.view.layer != nil {
|
||||
self.view.window?.backgroundColor = .white
|
||||
self.view.layer?.backgroundColor = .white
|
||||
|
||||
let versionNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
|
||||
versionLabel.stringValue = "Version \(versionNumber)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import Cocoa
|
||||
import ServiceManagement
|
||||
|
||||
let MODULE_HEIGHT = CGFloat(NSApplication.shared.mainMenu?.menuBarHeight ?? 22)
|
||||
let MODULE_WIDTH = CGFloat(28)
|
||||
let MODULE_WIDTH = CGFloat(32)
|
||||
|
||||
class MenuBar {
|
||||
let defaults = UserDefaults.standard
|
||||
@@ -34,6 +34,13 @@ class MenuBar {
|
||||
for module in modules.value {
|
||||
module.active.subscribe(observer: self) { (value, _) in
|
||||
self.buildModulesView()
|
||||
self.menuBarItem.menu?.removeAllItems()
|
||||
self.menuBarItem.menu = self.buildMenu()
|
||||
}
|
||||
module.available.subscribe(observer: self) { (value, _) in
|
||||
self.buildModulesView()
|
||||
self.menuBarItem.menu?.removeAllItems()
|
||||
self.menuBarItem.menu = self.buildMenu()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +49,9 @@ class MenuBar {
|
||||
let menu = NSMenu()
|
||||
|
||||
for module in modules.value {
|
||||
menu.addItem(module.menu())
|
||||
if module.available.value {
|
||||
menu.addItem(module.menu)
|
||||
}
|
||||
}
|
||||
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
@@ -64,11 +73,21 @@ class MenuBar {
|
||||
menu.addItem(preferences)
|
||||
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
let aboutMenu = NSMenuItem(title: "About Stats", action: #selector(openAbout), keyEquivalent: "")
|
||||
aboutMenu.target = self
|
||||
menu.addItem(aboutMenu)
|
||||
menu.addItem(NSMenuItem(title: "Quit Stats", action: #selector(NSApplication.terminate(_:)), keyEquivalent: ""))
|
||||
|
||||
return menu
|
||||
}
|
||||
|
||||
@objc func openAbout(_ sender : NSMenuItem) {
|
||||
let aboutVC: NSWindowController? = NSStoryboard(name: "About", bundle: nil).instantiateController(withIdentifier: "AboutVC") as? NSWindowController
|
||||
aboutVC?.window?.center()
|
||||
aboutVC?.window?.level = .floating
|
||||
aboutVC!.showWindow(self)
|
||||
}
|
||||
|
||||
@objc func toggleMenu(_ sender : NSMenuItem) {
|
||||
let launcherId = "eu.exelban.StatsLauncher"
|
||||
let status = sender.state != NSControl.StateValue.on
|
||||
@@ -92,32 +111,32 @@ class MenuBar {
|
||||
}
|
||||
|
||||
self.menuBarButton.image = NSImage(named:NSImage.Name("tray_icon"))
|
||||
var WIDTH = CGFloat(modules.value.count * 28)
|
||||
|
||||
let view: NSView = NSView(frame: NSMakeRect(0, 0, WIDTH, MODULE_HEIGHT))
|
||||
|
||||
let stack: NSStackView = NSStackView(frame: NSMakeRect(0, 0, WIDTH, MODULE_HEIGHT))
|
||||
stack.orientation = NSUserInterfaceLayoutOrientation.horizontal
|
||||
stack.distribution = NSStackView.Distribution.fillEqually
|
||||
stack.spacing = 0
|
||||
self.menuBarItem.length = MODULE_WIDTH
|
||||
var WIDTH = CGFloat(modules.value.count) * MODULE_WIDTH
|
||||
|
||||
WIDTH = 0
|
||||
for module in modules.value {
|
||||
if module.active.value {
|
||||
if module.active.value && module.available.value {
|
||||
module.start()
|
||||
WIDTH = WIDTH + module.view.frame.size.width
|
||||
stack.addView(module.view, in: NSStackView.Gravity.center)
|
||||
}
|
||||
}
|
||||
|
||||
if stack.subviews.count != 0 {
|
||||
let view: NSView = NSView(frame: NSMakeRect(0, 0, WIDTH, MODULE_HEIGHT))
|
||||
|
||||
var x: CGFloat = 0
|
||||
for module in modules.value {
|
||||
if module.active.value && module.available.value {
|
||||
module.view.frame = CGRect(x: x, y: 0, width: module.view.frame.size.width, height: module.view.frame.size.height)
|
||||
view.addSubview(module.view)
|
||||
x = x + module.view.frame.size.width
|
||||
}
|
||||
}
|
||||
|
||||
if view.subviews.count != 0 {
|
||||
view.frame.size.width = WIDTH
|
||||
stack.frame.size.width = WIDTH
|
||||
self.menuBarItem.length = WIDTH
|
||||
|
||||
view.addSubview(stack)
|
||||
|
||||
self.menuBarButton.image = nil
|
||||
self.menuBarItem.length = WIDTH
|
||||
self.menuBarButton.addSubview(view)
|
||||
}
|
||||
}
|
||||
|
||||
101
Stats/Modules/Battery/Battery.swift
Normal file
101
Stats/Modules/Battery/Battery.swift
Normal file
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// Battery.swift
|
||||
// Stats
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 14/06/2019.
|
||||
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class Battery: Module {
|
||||
let name: String = "Battery"
|
||||
let shortName: String = ""
|
||||
var view: NSView = NSView()
|
||||
var menu: NSMenuItem = NSMenuItem()
|
||||
var submenu: NSMenu = NSMenu()
|
||||
var active: Observable<Bool>
|
||||
var available: Observable<Bool>
|
||||
var reader: Reader = BatteryReader()
|
||||
|
||||
let defaults = UserDefaults.standard
|
||||
var widgetType: WidgetType = Widgets.Mini
|
||||
let percentageView: Observable<Bool>
|
||||
|
||||
init() {
|
||||
self.available = Observable(self.reader.available)
|
||||
self.active = Observable(defaults.object(forKey: name) != nil ? defaults.bool(forKey: name) : true)
|
||||
self.percentageView = Observable(defaults.object(forKey: "\(self.name)_percentage") != nil ? defaults.bool(forKey: "\(self.name)_percentage") : false)
|
||||
self.view = BatteryView(frame: NSMakeRect(0, 0, MODULE_WIDTH, MODULE_HEIGHT))
|
||||
initMenu()
|
||||
initWidget()
|
||||
}
|
||||
|
||||
func start() {
|
||||
if !self.reader.usage.value.isNaN {
|
||||
let value = self.reader.usage!.value
|
||||
(self.view as! BatteryView).setCharging(value: value > 0)
|
||||
(self.view as! Widget).value(value: abs(value))
|
||||
}
|
||||
|
||||
self.reader.start()
|
||||
self.reader.usage.subscribe(observer: self) { (value, _) in
|
||||
if !value.isNaN {
|
||||
(self.view as! BatteryView).setCharging(value: value > 0)
|
||||
(self.view as! Widget).value(value: abs(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func initWidget() {
|
||||
self.active << false
|
||||
(self.view as! BatteryView).setPercentage(value: self.percentageView.value)
|
||||
self.active << true
|
||||
}
|
||||
|
||||
func initMenu() {
|
||||
menu = NSMenuItem(title: name, action: #selector(toggle), keyEquivalent: "")
|
||||
submenu = NSMenu()
|
||||
|
||||
if defaults.object(forKey: name) != nil {
|
||||
menu.state = defaults.bool(forKey: name) ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
} else {
|
||||
menu.state = NSControl.StateValue.on
|
||||
}
|
||||
menu.target = self
|
||||
menu.isEnabled = true
|
||||
|
||||
let percentage = NSMenuItem(title: "Percentage", action: #selector(togglePercentage), keyEquivalent: "")
|
||||
percentage.state = defaults.bool(forKey: "\(self.name)_percentage") ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
percentage.target = self
|
||||
|
||||
submenu.addItem(percentage)
|
||||
menu.submenu = submenu
|
||||
}
|
||||
|
||||
@objc func toggle(_ sender: NSMenuItem) {
|
||||
let state = sender.state != NSControl.StateValue.on
|
||||
|
||||
sender.state = sender.state == NSControl.StateValue.on ? NSControl.StateValue.off : NSControl.StateValue.on
|
||||
self.defaults.set(state, forKey: name)
|
||||
self.active << state
|
||||
|
||||
if !state {
|
||||
menu.submenu = nil
|
||||
self.stop()
|
||||
} else {
|
||||
menu.submenu = submenu
|
||||
self.start()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func togglePercentage(_ sender: NSMenuItem) {
|
||||
let state = sender.state != NSControl.StateValue.on
|
||||
|
||||
sender.state = sender.state == NSControl.StateValue.on ? NSControl.StateValue.off : NSControl.StateValue.on
|
||||
self.defaults.set(state, forKey: "\(self.name)_percentage")
|
||||
self.percentageView << state
|
||||
self.initWidget()
|
||||
}
|
||||
}
|
||||
|
||||
56
Stats/Modules/Battery/BatteryReader.swift
Normal file
56
Stats/Modules/Battery/BatteryReader.swift
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// BatteryReader.swift
|
||||
// Stats
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 14/06/2019.
|
||||
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import IOKit.ps
|
||||
|
||||
class BatteryReader: Reader {
|
||||
var usage: Observable<Float>!
|
||||
var available: Bool = false
|
||||
var updateTimer: Timer!
|
||||
|
||||
init() {
|
||||
self.usage = Observable(0)
|
||||
read()
|
||||
}
|
||||
|
||||
func start() {
|
||||
if updateTimer != nil {
|
||||
return
|
||||
}
|
||||
updateTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(read), userInfo: nil, repeats: true)
|
||||
}
|
||||
|
||||
func stop() {
|
||||
if updateTimer == nil {
|
||||
return
|
||||
}
|
||||
updateTimer.invalidate()
|
||||
updateTimer = nil
|
||||
}
|
||||
|
||||
@objc func read() {
|
||||
let psInfo = IOPSCopyPowerSourcesInfo().takeRetainedValue()
|
||||
let psList = IOPSCopyPowerSourcesList(psInfo).takeRetainedValue() as [CFTypeRef]
|
||||
self.available = psList.count != 0
|
||||
|
||||
for ps in psList {
|
||||
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
|
||||
let powerSourceState = (psDesc[kIOPSPowerSourceStateKey] as? String)
|
||||
let isCharged = (psDesc[kIOPSIsChargedKey] as? Bool)
|
||||
var cap: Float = Float(psDesc[kIOPSCurrentCapacityKey] as! Int) / 100
|
||||
|
||||
if isCharged == nil && powerSourceState! == "Battery Power" {
|
||||
cap = 0 - cap
|
||||
}
|
||||
|
||||
self.usage << Float(cap)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,61 +10,97 @@ import Cocoa
|
||||
|
||||
class CPU: Module {
|
||||
let name: String = "CPU"
|
||||
let shortName: String = "CPU"
|
||||
var view: NSView = NSView()
|
||||
let defaults = UserDefaults.standard
|
||||
|
||||
var menu: NSMenuItem = NSMenuItem()
|
||||
var submenu: NSMenu = NSMenu()
|
||||
var active: Observable<Bool>
|
||||
var available: Observable<Bool>
|
||||
var reader: Reader = CPUReader()
|
||||
|
||||
@IBOutlet weak var value: NSTextField!
|
||||
let defaults = UserDefaults.standard
|
||||
var widgetType: WidgetType
|
||||
|
||||
init() {
|
||||
self.available = Observable(true)
|
||||
self.active = Observable(defaults.object(forKey: name) != nil ? defaults.bool(forKey: name) : true)
|
||||
self.view = loadViewFromNib()
|
||||
self.widgetType = defaults.object(forKey: "\(name)_widget") != nil ? defaults.float(forKey: "\(name)_widget") : Widgets.Mini
|
||||
initMenu()
|
||||
initWidget()
|
||||
}
|
||||
|
||||
func start() {
|
||||
if !self.reader.usage.value.isNaN {
|
||||
self.value.stringValue = "\(Int(Float(self.reader.usage.value.roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.value.textColor = self.reader.usage.value.usageColor()
|
||||
}
|
||||
func initMenu() {
|
||||
menu = NSMenuItem(title: name, action: #selector(toggle), keyEquivalent: "")
|
||||
submenu = NSMenu()
|
||||
|
||||
self.reader.start()
|
||||
self.reader.usage.subscribe(observer: self) { (value, _) in
|
||||
if !value.isNaN {
|
||||
self.value.stringValue = "\(Int(Float(value.roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.value.textColor = value.usageColor()
|
||||
}
|
||||
}
|
||||
|
||||
colors.subscribe(observer: self) { (value, _) in
|
||||
self.value.textColor = self.reader.usage.value.usageColor()
|
||||
}
|
||||
}
|
||||
|
||||
func menu() -> NSMenuItem {
|
||||
let menu = NSMenuItem(title: name, action: #selector(toggle), keyEquivalent: "")
|
||||
if defaults.object(forKey: name) != nil {
|
||||
menu.state = defaults.bool(forKey: name) ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
} else {
|
||||
menu.state = NSControl.StateValue.on
|
||||
}
|
||||
menu.target = self
|
||||
menu.isEnabled = true
|
||||
return menu
|
||||
|
||||
let mini = NSMenuItem(title: "Mini", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
mini.state = self.widgetType == Widgets.Mini ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
mini.target = self
|
||||
|
||||
let chart = NSMenuItem(title: "Chart", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
chart.state = self.widgetType == Widgets.Chart ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
chart.target = self
|
||||
|
||||
let chartWithValue = NSMenuItem(title: "Chart with value", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
chartWithValue.state = self.widgetType == Widgets.ChartWithValue ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
chartWithValue.target = self
|
||||
|
||||
submenu.addItem(mini)
|
||||
submenu.addItem(chart)
|
||||
submenu.addItem(chartWithValue)
|
||||
|
||||
menu.submenu = submenu
|
||||
}
|
||||
|
||||
@objc func toggle(_ sender: NSMenuItem) {
|
||||
let state = sender.state != NSControl.StateValue.on
|
||||
|
||||
sender.state = sender.state == NSControl.StateValue.on ? NSControl.StateValue.off : NSControl.StateValue.on
|
||||
self.defaults.set(state, forKey: name)
|
||||
self.active << state
|
||||
|
||||
if !state {
|
||||
menu.submenu = nil
|
||||
self.stop()
|
||||
} else {
|
||||
menu.submenu = submenu
|
||||
self.start()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func toggleWidget(_ sender: NSMenuItem) {
|
||||
var widgetCode: Float = 0.0
|
||||
|
||||
switch sender.title {
|
||||
case "Mini":
|
||||
widgetCode = Widgets.Mini
|
||||
case "Chart":
|
||||
widgetCode = Widgets.Chart
|
||||
case "Chart with value":
|
||||
widgetCode = Widgets.ChartWithValue
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if self.widgetType == widgetCode {
|
||||
return
|
||||
}
|
||||
|
||||
for item in self.submenu.items {
|
||||
if item.title == "Mini" || item.title == "Chart" || item.title == "Chart with value" {
|
||||
item.state = NSControl.StateValue.off
|
||||
}
|
||||
}
|
||||
|
||||
sender.state = sender.state == NSControl.StateValue.on ? NSControl.StateValue.off : NSControl.StateValue.on
|
||||
self.defaults.set(widgetCode, forKey: "\(name)_widget")
|
||||
self.widgetType = widgetCode
|
||||
self.initWidget()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner">
|
||||
<connections>
|
||||
<outlet property="value" destination="TXn-kg-jq1" id="e0R-gJ-2zT"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customView identifier="CPU" id="c22-O7-iKe">
|
||||
<rect key="frame" x="0.0" y="0.0" width="28" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<subviews>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="fuk-Yl-Mga">
|
||||
<rect key="frame" x="0.0" y="0.0" width="28" height="22"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="LO0-sZ-E6r">
|
||||
<rect key="frame" x="-2" y="11" width="24" height="9"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="CPU" id="TrQ-4e-Tib">
|
||||
<font key="font" metaFont="systemLight" size="7"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TXn-kg-jq1">
|
||||
<rect key="frame" x="-2" y="0.0" width="8" height="13"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" id="3Xv-9c-3y5">
|
||||
<font key="font" metaFont="system" size="10"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="LO0-sZ-E6r" firstAttribute="top" secondItem="fuk-Yl-Mga" secondAttribute="top" constant="2" id="0SG-E2-zVZ"/>
|
||||
<constraint firstItem="TXn-kg-jq1" firstAttribute="top" secondItem="fuk-Yl-Mga" secondAttribute="top" constant="9" id="1WZ-E9-iKh"/>
|
||||
<constraint firstAttribute="width" constant="28" id="TeP-YH-zJb"/>
|
||||
<constraint firstItem="LO0-sZ-E6r" firstAttribute="leading" secondItem="fuk-Yl-Mga" secondAttribute="leading" id="qf8-uc-Nqz"/>
|
||||
<constraint firstItem="TXn-kg-jq1" firstAttribute="leading" secondItem="fuk-Yl-Mga" secondAttribute="leading" id="uie-Bo-uLC"/>
|
||||
<constraint firstAttribute="height" constant="22" id="yuY-bI-RAD"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="fuk-Yl-Mga" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="IlM-4E-if4"/>
|
||||
<constraint firstItem="fuk-Yl-Mga" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="n6Y-Dl-WZW"/>
|
||||
</constraints>
|
||||
<point key="canvasLocation" x="-248" y="-5"/>
|
||||
</customView>
|
||||
</objects>
|
||||
</document>
|
||||
@@ -10,6 +10,7 @@ import Foundation
|
||||
|
||||
class CPUReader: Reader {
|
||||
var usage: Observable<Float>!
|
||||
var available: Bool = true
|
||||
var cpuInfo: processor_info_array_t!
|
||||
var prevCpuInfo: processor_info_array_t?
|
||||
var numCpuInfo: mach_msg_type_number_t = 0
|
||||
|
||||
@@ -10,40 +10,32 @@ import Cocoa
|
||||
|
||||
class Disk: Module {
|
||||
let name: String = "Disk"
|
||||
let shortName: String = "SSD"
|
||||
var view: NSView = NSView()
|
||||
var menu: NSMenuItem = NSMenuItem()
|
||||
let defaults = UserDefaults.standard
|
||||
var widgetType: WidgetType
|
||||
|
||||
var active: Observable<Bool>
|
||||
var available: Observable<Bool>
|
||||
var reader: Reader = DiskReader()
|
||||
|
||||
@IBOutlet weak var value: NSTextField!
|
||||
|
||||
init() {
|
||||
self.available = Observable(true)
|
||||
self.active = Observable(defaults.object(forKey: name) != nil ? defaults.bool(forKey: name) : true)
|
||||
self.view = loadViewFromNib()
|
||||
self.widgetType = defaults.object(forKey: "\(name)_widget") != nil ? defaults.float(forKey: "\(name)_widget") : Widgets.Mini
|
||||
|
||||
self.initMenu()
|
||||
|
||||
let widget = Mini(frame: NSMakeRect(0, 0, MODULE_WIDTH, MODULE_HEIGHT))
|
||||
widget.label = self.shortName
|
||||
self.view = widget
|
||||
}
|
||||
|
||||
func start() {
|
||||
if !self.reader.usage.value.isNaN {
|
||||
self.value.stringValue = "\(Int(Float(self.reader.usage.value.roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.value.textColor = self.reader.usage.value.usageColor()
|
||||
}
|
||||
|
||||
self.reader.start()
|
||||
self.reader.usage.subscribe(observer: self) { (value, _) in
|
||||
if !value.isNaN {
|
||||
self.value.stringValue = "\(Int(Float(value.roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.value.textColor = value.usageColor()
|
||||
}
|
||||
}
|
||||
|
||||
colors.subscribe(observer: self) { (value, _) in
|
||||
self.value.textColor = self.reader.usage.value.usageColor()
|
||||
}
|
||||
}
|
||||
|
||||
func menu() -> NSMenuItem {
|
||||
let menu = NSMenuItem(title: name, action: #selector(toggle), keyEquivalent: "")
|
||||
func initMenu() {
|
||||
menu = NSMenuItem(title: name, action: #selector(toggle), keyEquivalent: "")
|
||||
if defaults.object(forKey: name) != nil {
|
||||
menu.state = defaults.bool(forKey: name) ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
} else {
|
||||
@@ -51,7 +43,6 @@ class Disk: Module {
|
||||
}
|
||||
menu.target = self
|
||||
menu.isEnabled = true
|
||||
return menu
|
||||
}
|
||||
|
||||
@objc func toggle(_ sender: NSMenuItem) {
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner">
|
||||
<connections>
|
||||
<outlet property="value" destination="ynz-6E-8RQ" id="6K4-yo-kWJ"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customView identifier="CPU" id="L5h-u0-PHQ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="28" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<subviews>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="vHb-ac-rqs">
|
||||
<rect key="frame" x="0.0" y="0.0" width="28" height="22"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kt4-RP-7O0">
|
||||
<rect key="frame" x="-2" y="11" width="23" height="9"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="SSD" id="qLa-gn-BoV">
|
||||
<font key="font" metaFont="systemLight" size="7"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ynz-6E-8RQ">
|
||||
<rect key="frame" x="-2" y="0.0" width="8" height="13"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" id="foy-v3-uvP">
|
||||
<font key="font" metaFont="system" size="10"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="28" id="8DC-Wm-Hq7"/>
|
||||
<constraint firstItem="ynz-6E-8RQ" firstAttribute="leading" secondItem="vHb-ac-rqs" secondAttribute="leading" id="MDR-Ch-YzB"/>
|
||||
<constraint firstItem="kt4-RP-7O0" firstAttribute="top" secondItem="vHb-ac-rqs" secondAttribute="top" constant="2" id="Nd4-YH-TQD"/>
|
||||
<constraint firstItem="ynz-6E-8RQ" firstAttribute="top" secondItem="vHb-ac-rqs" secondAttribute="top" constant="9" id="Zzv-LQ-LWx"/>
|
||||
<constraint firstAttribute="height" constant="22" id="sZU-qm-ImR"/>
|
||||
<constraint firstItem="kt4-RP-7O0" firstAttribute="leading" secondItem="vHb-ac-rqs" secondAttribute="leading" id="yoF-RQ-AIG"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="vHb-ac-rqs" firstAttribute="leading" secondItem="L5h-u0-PHQ" secondAttribute="leading" id="06R-ZA-Fy9"/>
|
||||
<constraint firstItem="vHb-ac-rqs" firstAttribute="top" secondItem="L5h-u0-PHQ" secondAttribute="top" id="Zt9-77-xk9"/>
|
||||
</constraints>
|
||||
<point key="canvasLocation" x="-106" y="7"/>
|
||||
</customView>
|
||||
</objects>
|
||||
</document>
|
||||
@@ -10,6 +10,7 @@ import Foundation
|
||||
|
||||
class DiskReader: Reader {
|
||||
var usage: Observable<Float>!
|
||||
var available: Bool = true
|
||||
var updateTimer: Timer!
|
||||
|
||||
init() {
|
||||
|
||||
@@ -10,48 +10,55 @@ import Cocoa
|
||||
|
||||
class Memory: Module {
|
||||
let name: String = "Memory"
|
||||
let shortName: String = "MEM"
|
||||
var view: NSView = NSView()
|
||||
let defaults = UserDefaults.standard
|
||||
|
||||
var menu: NSMenuItem = NSMenuItem()
|
||||
var submenu: NSMenu = NSMenu()
|
||||
var active: Observable<Bool>
|
||||
var available: Observable<Bool>
|
||||
var reader: Reader = MemoryReader()
|
||||
var widgetType: WidgetType
|
||||
|
||||
let defaults = UserDefaults.standard
|
||||
|
||||
@IBOutlet weak var value: NSTextField!
|
||||
|
||||
init() {
|
||||
self.available = Observable(true)
|
||||
self.active = Observable(defaults.object(forKey: name) != nil ? defaults.bool(forKey: name) : true)
|
||||
self.view = loadViewFromNib()
|
||||
self.widgetType = defaults.object(forKey: "\(name)_widget") != nil ? defaults.float(forKey: "\(name)_widget") : Widgets.Mini
|
||||
initMenu()
|
||||
initWidget()
|
||||
}
|
||||
|
||||
func start() {
|
||||
if !self.reader.usage.value.isNaN {
|
||||
self.value.stringValue = "\(Int(Float(self.reader.usage.value.roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.value.textColor = self.reader.usage.value.usageColor()
|
||||
}
|
||||
func initMenu() {
|
||||
menu = NSMenuItem(title: name, action: #selector(toggle), keyEquivalent: "")
|
||||
submenu = NSMenu()
|
||||
|
||||
self.reader.start()
|
||||
self.reader.usage.subscribe(observer: self) { (value, _) in
|
||||
if !value.isNaN {
|
||||
self.value.stringValue = "\(Int(Float(value.roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.value.textColor = value.usageColor()
|
||||
}
|
||||
}
|
||||
|
||||
colors.subscribe(observer: self) { (value, _) in
|
||||
self.value.textColor = self.reader.usage.value.usageColor()
|
||||
}
|
||||
}
|
||||
|
||||
func menu() -> NSMenuItem {
|
||||
let menu = NSMenuItem(title: name, action: #selector(toggle), keyEquivalent: "")
|
||||
if defaults.object(forKey: name) != nil {
|
||||
menu.state = defaults.bool(forKey: name) ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
} else {
|
||||
menu.state = NSControl.StateValue.on
|
||||
}
|
||||
menu.target = self
|
||||
menu.isEnabled = true
|
||||
return menu
|
||||
|
||||
let mini = NSMenuItem(title: "Mini", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
mini.state = self.widgetType == Widgets.Mini ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
mini.target = self
|
||||
|
||||
let chart = NSMenuItem(title: "Chart", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
chart.state = self.widgetType == Widgets.Chart ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
chart.target = self
|
||||
|
||||
let chartWithValue = NSMenuItem(title: "Chart with value", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
chartWithValue.state = self.widgetType == Widgets.ChartWithValue ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
chartWithValue.target = self
|
||||
|
||||
submenu.addItem(mini)
|
||||
submenu.addItem(chart)
|
||||
submenu.addItem(chartWithValue)
|
||||
|
||||
menu.submenu = submenu
|
||||
}
|
||||
|
||||
@objc func toggle(_ sender: NSMenuItem) {
|
||||
@@ -67,4 +74,34 @@ class Memory: Module {
|
||||
self.start()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func toggleWidget(_ sender: NSMenuItem) {
|
||||
var widgetCode: Float = 0.0
|
||||
|
||||
switch sender.title {
|
||||
case "Mini":
|
||||
widgetCode = Widgets.Mini
|
||||
case "Chart":
|
||||
widgetCode = Widgets.Chart
|
||||
case "Chart with value":
|
||||
widgetCode = Widgets.ChartWithValue
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if self.widgetType == widgetCode {
|
||||
return
|
||||
}
|
||||
|
||||
for item in self.submenu.items {
|
||||
if item.title == "Mini" || item.title == "Chart" || item.title == "Chart with value" {
|
||||
item.state = NSControl.StateValue.off
|
||||
}
|
||||
}
|
||||
|
||||
sender.state = sender.state == NSControl.StateValue.on ? NSControl.StateValue.off : NSControl.StateValue.on
|
||||
self.defaults.set(widgetCode, forKey: "\(name)_widget")
|
||||
self.widgetType = widgetCode
|
||||
self.initWidget()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner">
|
||||
<connections>
|
||||
<outlet property="value" destination="pcp-bW-A5a" id="05g-TN-E6h"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customView identifier="CPU" id="zVf-HY-0OA">
|
||||
<rect key="frame" x="0.0" y="0.0" width="28" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<subviews>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="tl1-23-Yde">
|
||||
<rect key="frame" x="0.0" y="0.0" width="28" height="22"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="dVi-1r-SQt">
|
||||
<rect key="frame" x="-2" y="11" width="25" height="9"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="MEM" id="U2z-9g-lnI">
|
||||
<font key="font" metaFont="systemLight" size="7"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pcp-bW-A5a">
|
||||
<rect key="frame" x="-2" y="0.0" width="8" height="13"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" id="0Nx-Gf-K16">
|
||||
<font key="font" metaFont="system" size="10"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="dVi-1r-SQt" firstAttribute="leading" secondItem="tl1-23-Yde" secondAttribute="leading" id="80x-aW-s8H"/>
|
||||
<constraint firstItem="pcp-bW-A5a" firstAttribute="leading" secondItem="tl1-23-Yde" secondAttribute="leading" id="8r6-W0-PTu"/>
|
||||
<constraint firstItem="dVi-1r-SQt" firstAttribute="top" secondItem="tl1-23-Yde" secondAttribute="top" constant="2" id="Oj6-S6-2IB"/>
|
||||
<constraint firstAttribute="height" constant="22" id="euO-l5-Zwz"/>
|
||||
<constraint firstItem="pcp-bW-A5a" firstAttribute="top" secondItem="tl1-23-Yde" secondAttribute="top" constant="9" id="fOM-cd-BF6"/>
|
||||
<constraint firstAttribute="width" constant="28" id="tbx-wa-WQ3"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="tl1-23-Yde" firstAttribute="top" secondItem="zVf-HY-0OA" secondAttribute="top" id="Xwk-Wm-7N3"/>
|
||||
<constraint firstItem="tl1-23-Yde" firstAttribute="leading" secondItem="zVf-HY-0OA" secondAttribute="leading" id="oDv-Kz-VfI"/>
|
||||
</constraints>
|
||||
<point key="canvasLocation" x="-127" y="13"/>
|
||||
</customView>
|
||||
</objects>
|
||||
</document>
|
||||
@@ -10,6 +10,7 @@ import Foundation
|
||||
|
||||
class MemoryReader: Reader {
|
||||
var usage: Observable<Float>!
|
||||
var available: Bool = true
|
||||
var updateTimer: Timer!
|
||||
var totalSize: Float
|
||||
|
||||
|
||||
183
Stats/Supporting Files/About.storyboard
Normal file
183
Stats/Supporting Files/About.storyboard
Normal file
@@ -0,0 +1,183 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="QiE-cC-2Ak">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Window Controller-->
|
||||
<scene sceneID="8HR-Pk-O94">
|
||||
<objects>
|
||||
<windowController storyboardIdentifier="AboutVC" showSeguePresentationStyle="single" id="LUd-pu-twQ" sceneMemberID="viewController">
|
||||
<window key="window" title="About Stats" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="QOQ-ZU-enD">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="425" y="313" width="440" height="180"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1057"/>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="LUd-pu-twQ" id="h2N-hZ-Kra"/>
|
||||
</connections>
|
||||
</window>
|
||||
<connections>
|
||||
<segue destination="QiE-cC-2Ak" kind="relationship" relationship="window.shadowedContentViewController" id="CVD-cp-pGq"/>
|
||||
</connections>
|
||||
</windowController>
|
||||
<customObject id="iDr-bC-G86" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-163" y="55"/>
|
||||
</scene>
|
||||
<!--AboutVC-->
|
||||
<scene sceneID="acX-Wz-Ppn">
|
||||
<objects>
|
||||
<viewController showSeguePresentationStyle="single" id="QiE-cC-2Ak" customClass="AboutVC" customModule="Stats" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" id="rt1-Hc-A69">
|
||||
<rect key="frame" x="0.0" y="0.0" width="440" height="180"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<stackView distribution="fill" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="d8s-oR-aVd">
|
||||
<rect key="frame" x="20" y="20" width="400" height="160"/>
|
||||
<subviews>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="GM4-w7-FBX">
|
||||
<rect key="frame" x="0.0" y="0.0" width="140" height="160"/>
|
||||
<subviews>
|
||||
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Bvo-ng-CVb">
|
||||
<rect key="frame" x="0.0" y="16" width="128" height="128"/>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="AppIcon" id="T1x-rH-I2h"/>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="Bvo-ng-CVb" firstAttribute="centerY" secondItem="GM4-w7-FBX" secondAttribute="centerY" id="QxO-no-u5V"/>
|
||||
<constraint firstItem="Bvo-ng-CVb" firstAttribute="leading" secondItem="GM4-w7-FBX" secondAttribute="leading" id="t8e-fb-8bS"/>
|
||||
<constraint firstAttribute="width" constant="140" id="zzZ-Yq-fyL"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="20" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xYZ-jd-NgM">
|
||||
<rect key="frame" x="148" y="4" width="252" height="156"/>
|
||||
<subviews>
|
||||
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="0.0" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5Xy-ma-TDb">
|
||||
<rect key="frame" x="0.0" y="95" width="252" height="61"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="I2K-b4-4R0">
|
||||
<rect key="frame" x="-2" y="17" width="78" height="44"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Stats" id="4dC-76-a7n">
|
||||
<font key="font" metaFont="systemThin" size="36"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="GVE-z9-HI2">
|
||||
<rect key="frame" x="-2" y="0.0" width="49" height="17"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Version" id="Nkt-Z9-Av0">
|
||||
<font key="font" metaFont="systemLight" size="13"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<visibilityPriorities>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
</visibilityPriorities>
|
||||
<customSpacing>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
</customSpacing>
|
||||
</stackView>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="hXC-tE-nSc">
|
||||
<rect key="frame" x="-2" y="41" width="256" height="34"/>
|
||||
<textFieldCell key="cell" title="Simple macOS system monitor in your menu bar" id="w6j-75-PxU">
|
||||
<font key="font" metaFont="systemLight" size="13"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<stackView distribution="fillEqually" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="IBu-iz-oac">
|
||||
<rect key="frame" x="0.0" y="0.0" width="252" height="21"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="jBn-hr-r9y">
|
||||
<rect key="frame" x="-6" y="-7" width="134" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Webpage" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="HtX-JA-Ozy">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="openLink:" target="QiE-cC-2Ak" id="7El-Ks-Xau"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ewS-nM-fd0">
|
||||
<rect key="frame" x="124" y="-7" width="134" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Close" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="xDy-hu-mXO">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="exit:" target="QiE-cC-2Ak" id="MUD-YE-JiL"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<visibilityPriorities>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
</visibilityPriorities>
|
||||
<customSpacing>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
</customSpacing>
|
||||
</stackView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="IBu-iz-oac" secondAttribute="trailing" id="2r4-03-6C6"/>
|
||||
<constraint firstAttribute="trailing" secondItem="5Xy-ma-TDb" secondAttribute="trailing" id="BHW-gJ-qdK"/>
|
||||
<constraint firstItem="5Xy-ma-TDb" firstAttribute="leading" secondItem="xYZ-jd-NgM" secondAttribute="leading" id="TpI-3d-3ed"/>
|
||||
<constraint firstItem="IBu-iz-oac" firstAttribute="leading" secondItem="xYZ-jd-NgM" secondAttribute="leading" id="shP-Sm-N1e"/>
|
||||
</constraints>
|
||||
<visibilityPriorities>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
</visibilityPriorities>
|
||||
<customSpacing>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
</customSpacing>
|
||||
</stackView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="GM4-w7-FBX" firstAttribute="leading" secondItem="d8s-oR-aVd" secondAttribute="leading" id="HVl-6t-W0k"/>
|
||||
<constraint firstAttribute="height" constant="160" id="ev6-MZ-oMf"/>
|
||||
<constraint firstAttribute="width" constant="400" id="jZQ-gt-h4Y"/>
|
||||
<constraint firstAttribute="bottom" secondItem="GM4-w7-FBX" secondAttribute="bottom" id="o0Z-kY-6vo"/>
|
||||
<constraint firstItem="GM4-w7-FBX" firstAttribute="top" secondItem="d8s-oR-aVd" secondAttribute="top" id="sdB-TX-uLp"/>
|
||||
</constraints>
|
||||
<visibilityPriorities>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
</visibilityPriorities>
|
||||
<customSpacing>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
</customSpacing>
|
||||
</stackView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="d8s-oR-aVd" secondAttribute="trailing" constant="20" id="J2E-0b-nZb"/>
|
||||
<constraint firstAttribute="bottom" secondItem="d8s-oR-aVd" secondAttribute="bottom" constant="20" id="S3Y-bd-xoh"/>
|
||||
<constraint firstItem="d8s-oR-aVd" firstAttribute="leading" secondItem="rt1-Hc-A69" secondAttribute="leading" constant="20" id="nCP-al-GOl"/>
|
||||
<constraint firstItem="d8s-oR-aVd" firstAttribute="top" secondItem="rt1-Hc-A69" secondAttribute="top" id="snD-Ul-jpB"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="versionLabel" destination="GVE-z9-HI2" id="44o-1s-1eU"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<customObject id="orR-wl-rJd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-163" y="400"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="AppIcon" width="128" height="128"/>
|
||||
</resources>
|
||||
</document>
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<string>1.1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
|
||||
143
Stats/Widgets/BatteryView.swift
Normal file
143
Stats/Widgets/BatteryView.swift
Normal file
@@ -0,0 +1,143 @@
|
||||
//
|
||||
// BatteryView.swift
|
||||
// Stats
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 14/06/2019.
|
||||
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class BatteryView: NSView, Widget {
|
||||
let batteryWidth: CGFloat = 32
|
||||
let percentageWidth: CGFloat = 40
|
||||
|
||||
var value: Float {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
var charging: Bool {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
var percentage: Bool {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
|
||||
var percentageValue: NSTextField = NSTextField()
|
||||
|
||||
override init(frame: NSRect) {
|
||||
self.value = 1.0
|
||||
self.charging = false
|
||||
self.percentage = false
|
||||
super.init(frame: frame)
|
||||
self.wantsLayer = true
|
||||
self.percentageView()
|
||||
}
|
||||
|
||||
required init?(coder decoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
|
||||
var x: CGFloat = 4.0
|
||||
var w: CGFloat = dirtyRect.size.width - (x * 2)
|
||||
let h: CGFloat = 11.0
|
||||
let y: CGFloat = (dirtyRect.size.height - h) / 2
|
||||
let r: CGFloat = 1.0
|
||||
if self.percentage {
|
||||
w = batteryWidth - (x * 2)
|
||||
x = percentageWidth + x
|
||||
}
|
||||
|
||||
let battery = NSBezierPath(roundedRect: NSRect(x: x-1, y: y, width: w-1, height: h), xRadius: r, yRadius: r)
|
||||
|
||||
let bPX: CGFloat = x+w-2
|
||||
let bPY: CGFloat = (dirtyRect.size.height / 2) - 2
|
||||
let batteryPoint = NSBezierPath(roundedRect: NSRect(x: bPX, y: bPY, width: 2, height: 4), xRadius: r, yRadius: r)
|
||||
if self.charging {
|
||||
NSColor.systemGreen.set()
|
||||
} else {
|
||||
NSColor.labelColor.set()
|
||||
}
|
||||
batteryPoint.lineWidth = 1.1
|
||||
batteryPoint.stroke()
|
||||
batteryPoint.fill()
|
||||
|
||||
let maxWidth = w-4
|
||||
let inner = NSBezierPath(roundedRect: NSRect(x: x+0.5, y: y+1.5, width: maxWidth*CGFloat(self.value), height: h-3), xRadius: 0.5, yRadius: 0.5)
|
||||
self.value.batteryColor().set()
|
||||
inner.lineWidth = 0
|
||||
inner.stroke()
|
||||
inner.close()
|
||||
inner.fill()
|
||||
|
||||
if self.charging {
|
||||
NSColor.systemGreen.set()
|
||||
} else {
|
||||
NSColor.labelColor.set()
|
||||
}
|
||||
battery.lineWidth = 0.8
|
||||
battery.stroke()
|
||||
}
|
||||
|
||||
func percentageView() {
|
||||
if self.percentage {
|
||||
percentageValue = NSTextField(frame: NSMakeRect(0, 0, percentageWidth, self.frame.size.height - 2))
|
||||
percentageValue.textColor = NSColor.red
|
||||
percentageValue.isEditable = false
|
||||
percentageValue.isSelectable = false
|
||||
percentageValue.isBezeled = false
|
||||
percentageValue.wantsLayer = true
|
||||
percentageValue.textColor = .labelColor
|
||||
percentageValue.backgroundColor = .controlColor
|
||||
percentageValue.canDrawSubviewsIntoLayer = true
|
||||
percentageValue.alignment = .natural
|
||||
percentageValue.font = NSFont.systemFont(ofSize: 13, weight: .light)
|
||||
percentageValue.stringValue = "\(Int(self.value * 100))%"
|
||||
|
||||
self.addSubview(percentageValue)
|
||||
self.frame = CGRect(x: 0, y: 0, width: batteryWidth + percentageWidth, height: self.frame.size.height)
|
||||
} else {
|
||||
for subview in self.subviews {
|
||||
subview.removeFromSuperview()
|
||||
}
|
||||
self.addSubview(NSView())
|
||||
self.frame = CGRect(x: 0, y: 0, width: batteryWidth, height: self.frame.size.height)
|
||||
}
|
||||
}
|
||||
|
||||
func redraw() {
|
||||
self.needsDisplay = true
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Float) {
|
||||
if self.value != value {
|
||||
self.value = value
|
||||
|
||||
if percentage {
|
||||
self.percentageValue.stringValue = "\(Int(self.value * 100))%"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setCharging(value: Bool) {
|
||||
if self.charging != value {
|
||||
self.charging = value
|
||||
}
|
||||
}
|
||||
|
||||
func setPercentage(value: Bool) {
|
||||
if self.percentage != value {
|
||||
self.percentage = value
|
||||
self.percentageView()
|
||||
}
|
||||
}
|
||||
}
|
||||
149
Stats/Widgets/Chart.swift
Normal file
149
Stats/Widgets/Chart.swift
Normal file
@@ -0,0 +1,149 @@
|
||||
//
|
||||
// CPUView.swift
|
||||
// Stats
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 14.06.2019.
|
||||
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class Chart: NSView, Widget {
|
||||
var height: CGFloat = 0.0
|
||||
var points: [Float] {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
|
||||
override init(frame: NSRect) {
|
||||
self.points = Array(repeating: 0.0, count: 50)
|
||||
super.init(frame: frame)
|
||||
self.wantsLayer = true
|
||||
self.addSubview(NSView())
|
||||
}
|
||||
|
||||
required init?(coder decoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
|
||||
let lineColor: NSColor = NSColor.selectedMenuItemColor
|
||||
let gradientColor: NSColor = NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 0.5)
|
||||
|
||||
let context = NSGraphicsContext.current!.cgContext
|
||||
let xOffset: CGFloat = 4.0
|
||||
let yOffset: CGFloat = 3.0
|
||||
if height == 0 {
|
||||
height = self.frame.size.height - CGFloat((yOffset * 2))
|
||||
}
|
||||
let xRatio = Double(self.frame.size.width - (xOffset * 2)) / (Double(self.points.count) - 1)
|
||||
|
||||
let columnXPoint = { (point: Int) -> CGFloat in
|
||||
return CGFloat((Double(point) * xRatio)) + xOffset
|
||||
}
|
||||
let columnYPoint = { (point: Int) -> CGFloat in
|
||||
return CGFloat((CGFloat(truncating: self.points[point] as NSNumber) * self.height)) + yOffset
|
||||
}
|
||||
|
||||
let graphPath = NSBezierPath()
|
||||
let x: CGFloat = columnXPoint(0)
|
||||
let y: CGFloat = columnYPoint(0)
|
||||
graphPath.move(to: CGPoint(x: x, y: y))
|
||||
|
||||
for i in 1..<self.points.count {
|
||||
graphPath.line(to: CGPoint(x: columnXPoint(i), y: columnYPoint(i)))
|
||||
}
|
||||
|
||||
lineColor.setStroke()
|
||||
graphPath.stroke()
|
||||
context.saveGState()
|
||||
|
||||
let clippingPath = graphPath.copy() as! NSBezierPath
|
||||
|
||||
clippingPath.line(to: CGPoint(x: columnXPoint(self.points.count - 1), y: yOffset - 0.5))
|
||||
clippingPath.line(to: CGPoint(x: columnXPoint(0), y: yOffset - 0.5))
|
||||
clippingPath.close()
|
||||
clippingPath.addClip()
|
||||
|
||||
gradientColor.setFill()
|
||||
let rectPath = NSBezierPath(rect: dirtyRect)
|
||||
rectPath.fill()
|
||||
|
||||
context.restoreGState()
|
||||
|
||||
graphPath.lineWidth = 0.5
|
||||
graphPath.stroke()
|
||||
}
|
||||
|
||||
func redraw() {
|
||||
self.needsDisplay = true
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Float) {
|
||||
if self.points.count < 50 {
|
||||
self.points.append(value)
|
||||
return
|
||||
}
|
||||
|
||||
for (i, _) in self.points.enumerated() {
|
||||
if i+1 < self.points.count {
|
||||
self.points[i] = self.points[i+1]
|
||||
} else {
|
||||
self.points[i] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ChartWithValue: Chart {
|
||||
var valueLabel: NSTextField = NSTextField()
|
||||
|
||||
override init(frame: NSRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
self.wantsLayer = true
|
||||
|
||||
valueLabel = NSTextField(frame: NSMakeRect(2, MODULE_HEIGHT - 11, self.frame.size.width, 10))
|
||||
valueLabel.textColor = NSColor.red
|
||||
valueLabel.isEditable = false
|
||||
valueLabel.isSelectable = false
|
||||
valueLabel.isBezeled = false
|
||||
valueLabel.wantsLayer = true
|
||||
valueLabel.textColor = .labelColor
|
||||
valueLabel.backgroundColor = .controlColor
|
||||
valueLabel.canDrawSubviewsIntoLayer = true
|
||||
valueLabel.alignment = .natural
|
||||
valueLabel.font = NSFont.systemFont(ofSize: 8, weight: .ultraLight)
|
||||
valueLabel.stringValue = ""
|
||||
valueLabel.addSubview(NSView())
|
||||
|
||||
self.height = 7.0
|
||||
self.addSubview(valueLabel)
|
||||
}
|
||||
|
||||
required init?(coder decoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func value(value: Float) {
|
||||
self.valueLabel.stringValue = "\(Int(Float(Float(value).roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.valueLabel.textColor = Float(value).usageColor()
|
||||
|
||||
if self.points.count < 50 {
|
||||
self.points.append(value)
|
||||
return
|
||||
}
|
||||
|
||||
for (i, _) in self.points.enumerated() {
|
||||
if i+1 < self.points.count {
|
||||
self.points[i] = self.points[i+1]
|
||||
} else {
|
||||
self.points[i] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
Stats/Widgets/Mini.swift
Normal file
82
Stats/Widgets/Mini.swift
Normal file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Mini.swift
|
||||
// Stats
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 14.06.2019.
|
||||
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class Mini: NSView, Widget {
|
||||
var valueView: NSTextField = NSTextField()
|
||||
var labelView: NSTextField = NSTextField()
|
||||
|
||||
var value: Float = 0
|
||||
var label: String = "" {
|
||||
didSet {
|
||||
self.labelView.stringValue = label
|
||||
}
|
||||
}
|
||||
|
||||
override init(frame: NSRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
self.wantsLayer = true
|
||||
|
||||
let xOffset: CGFloat = 1.0
|
||||
|
||||
let labelView = NSTextField(frame: NSMakeRect(xOffset, 13, self.frame.size.width, 7))
|
||||
labelView.textColor = NSColor.red
|
||||
labelView.isEditable = false
|
||||
labelView.isSelectable = false
|
||||
labelView.isBezeled = false
|
||||
labelView.wantsLayer = true
|
||||
labelView.textColor = .labelColor
|
||||
labelView.backgroundColor = .controlColor
|
||||
labelView.canDrawSubviewsIntoLayer = true
|
||||
labelView.alignment = .natural
|
||||
labelView.font = NSFont.systemFont(ofSize: 7, weight: .ultraLight)
|
||||
labelView.stringValue = self.label
|
||||
labelView.addSubview(NSView())
|
||||
|
||||
let valueView = NSTextField(frame: NSMakeRect(xOffset, 3, self.frame.size.width, 10))
|
||||
valueView.textColor = NSColor.red
|
||||
valueView.isEditable = false
|
||||
valueView.isSelectable = false
|
||||
valueView.isBezeled = false
|
||||
valueView.wantsLayer = true
|
||||
valueView.textColor = .labelColor
|
||||
valueView.backgroundColor = .controlColor
|
||||
valueView.canDrawSubviewsIntoLayer = true
|
||||
valueView.alignment = .natural
|
||||
valueView.font = NSFont.systemFont(ofSize: 10, weight: .regular)
|
||||
valueView.stringValue = ""
|
||||
valueView.addSubview(NSView())
|
||||
|
||||
self.labelView = labelView
|
||||
self.valueView = valueView
|
||||
|
||||
self.addSubview(self.labelView)
|
||||
self.addSubview(self.valueView)
|
||||
}
|
||||
|
||||
required init?(coder decoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func redraw() {
|
||||
self.valueView.textColor = Float(self.value).usageColor()
|
||||
self.needsDisplay = true
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Float) {
|
||||
if self.value != value {
|
||||
self.value = value
|
||||
|
||||
self.valueView.stringValue = "\(Int(Float(Float(value).roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.valueView.textColor = Float(value).usageColor()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,21 @@ extension Float {
|
||||
return NSString(format: "%.\(decimalPlaces)f" as NSString, self) as String
|
||||
}
|
||||
|
||||
func usageColor() -> NSColor {
|
||||
func usageColor(reversed: Bool = false) -> NSColor {
|
||||
if !colors.value {
|
||||
return NSColor.textColor
|
||||
}
|
||||
|
||||
if reversed {
|
||||
switch self {
|
||||
case 0.6...0.8:
|
||||
return NSColor.systemOrange
|
||||
case 0.8...1:
|
||||
return NSColor.systemGreen
|
||||
default:
|
||||
return NSColor.systemRed
|
||||
}
|
||||
} else {
|
||||
switch self {
|
||||
case 0.6...0.8:
|
||||
return NSColor.systemOrange
|
||||
@@ -28,6 +38,27 @@ extension Float {
|
||||
return NSColor.systemGreen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func batteryColor() -> NSColor {
|
||||
switch self {
|
||||
case 0.2...0.4:
|
||||
if !colors.value {
|
||||
return NSColor.controlTextColor
|
||||
}
|
||||
return NSColor.systemOrange
|
||||
case 0.4...1:
|
||||
if self == 1 {
|
||||
return NSColor.controlTextColor
|
||||
}
|
||||
if !colors.value {
|
||||
return NSColor.controlTextColor
|
||||
}
|
||||
return NSColor.systemGreen
|
||||
default:
|
||||
return NSColor.systemRed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Unit : Float {
|
||||
@@ -37,3 +68,15 @@ public enum Unit : Float {
|
||||
case gigabyte = 1073741824
|
||||
}
|
||||
|
||||
//extension NSView {
|
||||
// var backgroundColor: NSColor? {
|
||||
// get {
|
||||
// guard let color = layer?.backgroundColor else { return nil }
|
||||
// return NSColor(cgColor: color)
|
||||
// }
|
||||
// set {
|
||||
// wantsLayer = true
|
||||
// layer?.backgroundColor = newValue?.cgColor
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -8,35 +8,94 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
protocol Module {
|
||||
protocol Module: class {
|
||||
var name: String { get }
|
||||
var shortName: String { get }
|
||||
var view: NSView { get set }
|
||||
var menu: NSMenuItem { get }
|
||||
var active: Observable<Bool> { get }
|
||||
var available: Observable<Bool> { get }
|
||||
var reader: Reader { get }
|
||||
var view: NSView { get }
|
||||
var widgetType: WidgetType { get }
|
||||
|
||||
func menu() -> NSMenuItem
|
||||
func start()
|
||||
func stop()
|
||||
}
|
||||
|
||||
extension Module {
|
||||
func stop() {
|
||||
self.reader.stop()
|
||||
self.reader.usage.unsubscribe(observer: self as AnyObject)
|
||||
func initWidget() {
|
||||
self.active << false
|
||||
switch self.widgetType {
|
||||
case Widgets.Mini:
|
||||
let widget = Mini(frame: NSMakeRect(0, 0, MODULE_WIDTH, MODULE_HEIGHT))
|
||||
widget.label = self.shortName
|
||||
self.view = widget
|
||||
break
|
||||
case Widgets.Chart:
|
||||
self.view = Chart(frame: NSMakeRect(0, 0, MODULE_WIDTH + 7, MODULE_HEIGHT))
|
||||
break
|
||||
case Widgets.ChartWithValue:
|
||||
self.view = ChartWithValue(frame: NSMakeRect(0, 0, MODULE_WIDTH + 7, MODULE_HEIGHT))
|
||||
break
|
||||
default:
|
||||
let widget = Mini(frame: NSMakeRect(0, 0, MODULE_WIDTH, MODULE_HEIGHT))
|
||||
widget.label = self.shortName
|
||||
self.view = widget
|
||||
}
|
||||
self.active << true
|
||||
}
|
||||
|
||||
func loadViewFromNib() -> NSView {
|
||||
var topLevelObjects: NSArray?
|
||||
if Bundle.main.loadNibNamed(NSNib.Name(String(describing: Self.self)), owner: self, topLevelObjects: &topLevelObjects) {
|
||||
return (topLevelObjects?.first(where: { $0 is NSView } ) as? NSView)!
|
||||
func start() {
|
||||
if !self.reader.usage.value.isNaN {
|
||||
guard let widget = self.view as? Widget else {
|
||||
return
|
||||
}
|
||||
return NSView()
|
||||
widget.value(value: self.reader.usage.value)
|
||||
}
|
||||
|
||||
self.reader.start()
|
||||
self.reader.usage.subscribe(observer: self) { (value, _) in
|
||||
if !value.isNaN {
|
||||
guard let widget = self.view as? Widget else {
|
||||
return
|
||||
}
|
||||
widget.value(value: value)
|
||||
}
|
||||
}
|
||||
|
||||
colors.subscribe(observer: self) { (value, _) in
|
||||
guard let widget = self.view as? Widget else {
|
||||
return
|
||||
}
|
||||
widget.redraw()
|
||||
}
|
||||
}
|
||||
|
||||
func stop() {
|
||||
self.reader.stop()
|
||||
self.reader.usage.unsubscribe(observer: self)
|
||||
colors.unsubscribe(observer: self)
|
||||
}
|
||||
}
|
||||
|
||||
protocol Reader {
|
||||
var usage: Observable<Float>! { get }
|
||||
var available: Bool { get }
|
||||
var updateTimer: Timer! { get set }
|
||||
func start()
|
||||
func read()
|
||||
func stop()
|
||||
func read()
|
||||
}
|
||||
|
||||
protocol Widget {
|
||||
func value(value: Float)
|
||||
func redraw()
|
||||
}
|
||||
|
||||
typealias WidgetType = Float
|
||||
|
||||
struct Widgets {
|
||||
static let Mini: WidgetType = 0.0
|
||||
static let Chart: WidgetType = 1.0
|
||||
static let ChartWithValue: WidgetType = 1.1
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user