mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 16:24:30 +09:00
27
README.md
27
README.md
@@ -3,16 +3,15 @@ Simple macOS system monitor in your menu bar
|
||||
|
||||
[<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
|
||||
## Features
|
||||
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
|
||||
- CPU Usage
|
||||
- Memory Usage
|
||||
- Disk utilization
|
||||
- Battery level
|
||||
- Network usage
|
||||
- Black theme compatible
|
||||
|
||||
## Installation
|
||||
You can download latest version [here](https://github.com/exelban/stats/releases).
|
||||
@@ -23,8 +22,9 @@ You can download latest version [here](https://github.com/exelban/stats/releases
|
||||
| --- | --- | --- |
|
||||
| **CPU** | Percentage / Chart / Chart with value | Shows CPU usage |
|
||||
| **Memory** | Percentage / Chart / Chart with value | Shows RAM usage |
|
||||
| **Disk** | Percentage | Shows disk filling |
|
||||
| **Disk** | Percentage | Shows disk utilization |
|
||||
| **Battery** | Graphic / Percentage | Shows battery level and charging status |
|
||||
| **Newtork** | Dots / Upload/Download traffic | Shows network activity |
|
||||
|
||||
## Compatibility
|
||||
| macOS | Compatible |
|
||||
@@ -41,7 +41,7 @@ You can download latest version [here](https://github.com/exelban/stats/releases
|
||||
- [ ] temperature module
|
||||
- [X] battery module
|
||||
- [X] move to module system (CPU, RAM, DISK)
|
||||
- [ ] network module
|
||||
- [X] network module
|
||||
- [X] save settings
|
||||
- [ ] OTA updates
|
||||
- [X] charts
|
||||
@@ -49,6 +49,11 @@ You can download latest version [here](https://github.com/exelban/stats/releases
|
||||
|
||||
## What's new
|
||||
|
||||
### v1.2.0
|
||||
- added network module
|
||||
- added Check for updates window
|
||||
- fixed few bugs
|
||||
|
||||
### v1.1.0
|
||||
- added battery module
|
||||
- added chart widget for CPU and Memory
|
||||
@@ -58,4 +63,4 @@ You can download latest version [here](https://github.com/exelban/stats/releases
|
||||
- first release
|
||||
|
||||
## License
|
||||
[GNU General Public License](https://github.com/exelban/stats/blob/master/LICENSE)
|
||||
[MIT License](https://github.com/exelban/stats/blob/master/LICENSE)
|
||||
|
||||
@@ -12,9 +12,14 @@
|
||||
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 */; };
|
||||
9A426DB822C2B5EE00C064C4 /* macAppUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A426DB722C2B5EE00C064C4 /* macAppUpdater.swift */; };
|
||||
9A426DBE22C2BE0000C064C4 /* Updates.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9A426DBD22C2BE0000C064C4 /* Updates.storyboard */; };
|
||||
9A57A18522A1D26D0033E318 /* MenuBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A57A18422A1D26D0033E318 /* MenuBar.swift */; };
|
||||
9A57A19B22A1E1C50033E318 /* Module.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A57A19A22A1E1C50033E318 /* Module.swift */; };
|
||||
9A57A19D22A1E3270033E318 /* CPU.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A57A19C22A1E3270033E318 /* CPU.swift */; };
|
||||
9A58D1B022C150C800405315 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A58D1AF22C150C800405315 /* Network.swift */; };
|
||||
9A58D1B222C150D700405315 /* NetworkReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A58D1B122C150D700405315 /* NetworkReader.swift */; };
|
||||
9A58D1B422C179B200405315 /* NetworkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A58D1B322C179B200405315 /* NetworkView.swift */; };
|
||||
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 */; };
|
||||
@@ -55,9 +60,14 @@
|
||||
9A1410FF229E721200D29793 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
9A141101229E721200D29793 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
9A141102229E721200D29793 /* Stats.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Stats.entitlements; sourceTree = "<group>"; };
|
||||
9A426DB722C2B5EE00C064C4 /* macAppUpdater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = macAppUpdater.swift; sourceTree = "<group>"; };
|
||||
9A426DBD22C2BE0000C064C4 /* Updates.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Updates.storyboard; sourceTree = "<group>"; };
|
||||
9A57A18422A1D26D0033E318 /* MenuBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBar.swift; sourceTree = "<group>"; };
|
||||
9A57A19A22A1E1C50033E318 /* Module.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Module.swift; sourceTree = "<group>"; };
|
||||
9A57A19C22A1E3270033E318 /* CPU.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CPU.swift; sourceTree = "<group>"; };
|
||||
9A58D1AF22C150C800405315 /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
|
||||
9A58D1B122C150D700405315 /* NetworkReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkReader.swift; sourceTree = "<group>"; };
|
||||
9A58D1B322C179B200405315 /* NetworkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkView.swift; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
@@ -138,12 +148,22 @@
|
||||
path = Stats;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9A58D1AE22C150B800405315 /* Network */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A58D1AF22C150C800405315 /* Network.swift */,
|
||||
9A58D1B122C150D700405315 /* NetworkReader.swift */,
|
||||
);
|
||||
path = Network;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9A5B1CB3229E72A7008B9D3C /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A6CFC0022A1C9F5001E782D /* Assets.xcassets */,
|
||||
9AFFCB3A22B3FD0500B0E6D8 /* About.storyboard */,
|
||||
9A1410FE229E721200D29793 /* Main.storyboard */,
|
||||
9AFFCB3A22B3FD0500B0E6D8 /* About.storyboard */,
|
||||
9A426DBD22C2BE0000C064C4 /* Updates.storyboard */,
|
||||
9A141101229E721200D29793 /* Info.plist */,
|
||||
9A141102229E721200D29793 /* Stats.entitlements */,
|
||||
);
|
||||
@@ -153,10 +173,11 @@
|
||||
9A5B1CBA229E7892008B9D3C /* Modules */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9A09C89C22B3A7BB0018426F /* Battery */,
|
||||
9A7B8F5C22A2926500DEB352 /* CPU */,
|
||||
9A7B8F6222A2C17000DEB352 /* Memory */,
|
||||
9A7B8F6322A2C17500DEB352 /* Disk */,
|
||||
9A09C89C22B3A7BB0018426F /* Battery */,
|
||||
9A58D1AE22C150B800405315 /* Network */,
|
||||
);
|
||||
path = Modules;
|
||||
sourceTree = "<group>";
|
||||
@@ -167,6 +188,7 @@
|
||||
9A5B1CBE229E78F0008B9D3C /* Observable.swift */,
|
||||
9A57A19A22A1E1C50033E318 /* Module.swift */,
|
||||
9A5B1CC4229E7B40008B9D3C /* Extensions.swift */,
|
||||
9A426DB722C2B5EE00C064C4 /* macAppUpdater.swift */,
|
||||
);
|
||||
path = libs;
|
||||
sourceTree = "<group>";
|
||||
@@ -177,6 +199,7 @@
|
||||
9A09C8A122B3D94D0018426F /* BatteryView.swift */,
|
||||
9A74D59322B4315C004FE1FA /* Chart.swift */,
|
||||
9A74D59622B44498004FE1FA /* Mini.swift */,
|
||||
9A58D1B322C179B200405315 /* NetworkView.swift */,
|
||||
);
|
||||
path = Widgets;
|
||||
sourceTree = "<group>";
|
||||
@@ -279,6 +302,11 @@
|
||||
TargetAttributes = {
|
||||
9A1410F4229E721100D29793 = {
|
||||
CreatedOnToolsVersion = 10.2.1;
|
||||
SystemCapabilities = {
|
||||
com.apple.Sandbox = {
|
||||
enabled = 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
9AFA401D22AE49A100FE90BC = {
|
||||
CreatedOnToolsVersion = 10.2.1;
|
||||
@@ -312,6 +340,7 @@
|
||||
9A6CFC0122A1C9F5001E782D /* Assets.xcassets in Resources */,
|
||||
9AFFCB3B22B3FD0500B0E6D8 /* About.storyboard in Resources */,
|
||||
9A141100229E721200D29793 /* Main.storyboard in Resources */,
|
||||
9A426DBE22C2BE0000C064C4 /* Updates.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -332,15 +361,19 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
9A09C8A222B3D94D0018426F /* BatteryView.swift in Sources */,
|
||||
9A426DB822C2B5EE00C064C4 /* macAppUpdater.swift in Sources */,
|
||||
9A7B8F6F22A2C57000DEB352 /* DiskReader.swift in Sources */,
|
||||
9A7B8F6922A2C3A100DEB352 /* Memory.swift in Sources */,
|
||||
9A7B8F5E22A2A57600DEB352 /* CPUReader.swift in Sources */,
|
||||
9A74D59422B4315C004FE1FA /* Chart.swift in Sources */,
|
||||
9A58D1B422C179B200405315 /* NetworkView.swift in Sources */,
|
||||
9A09C89E22B3A7C90018426F /* Battery.swift in Sources */,
|
||||
9A7B8F6D22A2C3D600DEB352 /* MemoryReader.swift in Sources */,
|
||||
9A57A18522A1D26D0033E318 /* MenuBar.swift in Sources */,
|
||||
9A57A19D22A1E3270033E318 /* CPU.swift in Sources */,
|
||||
9A58D1B222C150D700405315 /* NetworkReader.swift in Sources */,
|
||||
9A09C8A022B3A7E20018426F /* BatteryReader.swift in Sources */,
|
||||
9A58D1B022C150C800405315 /* Network.swift in Sources */,
|
||||
9A57A19B22A1E1C50033E318 /* Module.swift in Sources */,
|
||||
9A5B1CBF229E78F0008B9D3C /* Observable.swift in Sources */,
|
||||
9A7B8F6B22A2C3A700DEB352 /* Disk.swift in Sources */,
|
||||
@@ -505,6 +538,10 @@
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = RP2S87B72W;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)",
|
||||
);
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Stats/Supporting Files/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
@@ -528,6 +565,10 @@
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = RP2S87B72W;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)",
|
||||
);
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Stats/Supporting Files/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
|
||||
@@ -13,7 +13,7 @@ extension Notification.Name {
|
||||
static let killLauncher = Notification.Name("killLauncher")
|
||||
}
|
||||
|
||||
let modules: Observable<[Module]> = Observable([CPU(), Memory(), Disk(), Battery()])
|
||||
let modules: Observable<[Module]> = Observable([CPU(), Memory(), Disk(), Battery(), Network()])
|
||||
let colors: Observable<Bool> = Observable(true)
|
||||
|
||||
@NSApplicationMain
|
||||
@@ -81,3 +81,72 @@ class AboutVC: NSViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UpdatesVC: NSViewController {
|
||||
@IBOutlet weak var mainView: NSStackView!
|
||||
@IBOutlet weak var spinnerView: NSView!
|
||||
@IBOutlet weak var noInternetView: NSView!
|
||||
@IBOutlet weak var mainTextLabel: NSTextFieldCell!
|
||||
@IBOutlet weak var currentVersionLabel: NSTextField!
|
||||
@IBOutlet weak var latestVersionLabel: NSTextField!
|
||||
@IBOutlet weak var downloadButton: NSButton!
|
||||
@IBOutlet weak var spinner: NSProgressIndicator!
|
||||
|
||||
let updater = macAppUpdater(user: "exelban", repo: "stats")
|
||||
var url: String?
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
self.view.wantsLayer = true
|
||||
|
||||
self.spinner.startAnimation(self)
|
||||
|
||||
updater.check() { result, error in
|
||||
if error != nil && error as! String == "No internet connection" {
|
||||
DispatchQueue.main.async(execute: {
|
||||
self.spinnerView.isHidden = true
|
||||
self.noInternetView.isHidden = false
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
guard error == nil, let version: version = result else {
|
||||
print("Error: \(error ?? "check error")")
|
||||
return
|
||||
}
|
||||
|
||||
DispatchQueue.main.async(execute: {
|
||||
self.spinner.stopAnimation(self)
|
||||
self.spinnerView.isHidden = true
|
||||
self.mainView.isHidden = false
|
||||
self.currentVersionLabel.stringValue = version.current
|
||||
self.latestVersionLabel.stringValue = version.latest
|
||||
self.url = version.url
|
||||
|
||||
if !version.newest {
|
||||
self.mainTextLabel.stringValue = "No new version available"
|
||||
self.downloadButton.isEnabled = false
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
if self.view.layer != nil {
|
||||
self.view.window?.backgroundColor = .white
|
||||
self.view.layer?.backgroundColor = .white
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func download(_ sender: Any) {
|
||||
guard let urlString = self.url, let url = URL(string: urlString) else {
|
||||
return
|
||||
}
|
||||
NSWorkspace.shared.open(url)
|
||||
self.view.window?.close()
|
||||
}
|
||||
|
||||
@IBAction func exit(_ sender: Any) {
|
||||
self.view.window?.close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
import Cocoa
|
||||
import ServiceManagement
|
||||
|
||||
let MODULE_HEIGHT = CGFloat(NSApplication.shared.mainMenu?.menuBarHeight ?? 22)
|
||||
let MODULE_WIDTH = CGFloat(32)
|
||||
let MODULE_HEIGHT: CGFloat = NSApplication.shared.mainMenu?.menuBarHeight ?? 22
|
||||
let MODULE_WIDTH: CGFloat = 32
|
||||
let MODULE_MARGIN: CGFloat = 2
|
||||
|
||||
class MenuBar {
|
||||
let defaults = UserDefaults.standard
|
||||
@@ -73,14 +74,27 @@ class MenuBar {
|
||||
menu.addItem(preferences)
|
||||
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
|
||||
let updateMenu = NSMenuItem(title: "Check for updates", action: #selector(checkUpdate), keyEquivalent: "")
|
||||
updateMenu.target = self
|
||||
|
||||
let aboutMenu = NSMenuItem(title: "About Stats", action: #selector(openAbout), keyEquivalent: "")
|
||||
aboutMenu.target = self
|
||||
|
||||
menu.addItem(updateMenu)
|
||||
menu.addItem(aboutMenu)
|
||||
menu.addItem(NSMenuItem(title: "Quit Stats", action: #selector(NSApplication.terminate(_:)), keyEquivalent: ""))
|
||||
|
||||
return menu
|
||||
}
|
||||
|
||||
@objc func checkUpdate(_ sender : NSMenuItem) {
|
||||
let updatesVC: NSWindowController? = NSStoryboard(name: "Updates", bundle: nil).instantiateController(withIdentifier: "UpdatesVC") as? NSWindowController
|
||||
updatesVC?.window?.center()
|
||||
updatesVC?.window?.level = .floating
|
||||
updatesVC!.showWindow(self)
|
||||
}
|
||||
|
||||
@objc func openAbout(_ sender : NSMenuItem) {
|
||||
let aboutVC: NSWindowController? = NSStoryboard(name: "About", bundle: nil).instantiateController(withIdentifier: "AboutVC") as? NSWindowController
|
||||
aboutVC?.window?.center()
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
import IOKit.ps
|
||||
|
||||
class BatteryReader: Reader {
|
||||
var usage: Observable<Float>!
|
||||
var usage: Observable<Double>!
|
||||
var available: Bool = false
|
||||
var updateTimer: Timer!
|
||||
|
||||
@@ -49,7 +49,7 @@ class BatteryReader: Reader {
|
||||
cap = 0 - cap
|
||||
}
|
||||
|
||||
self.usage << Float(cap)
|
||||
self.usage << Double(cap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,8 @@ class CPU: Module {
|
||||
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()
|
||||
self.active << false
|
||||
initWidget()
|
||||
self.active << true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
|
||||
class CPUReader: Reader {
|
||||
var usage: Observable<Float>!
|
||||
var usage: Observable<Double>!
|
||||
var available: Bool = true
|
||||
var cpuInfo: processor_info_array_t!
|
||||
var prevCpuInfo: processor_info_array_t?
|
||||
@@ -77,7 +77,7 @@ class CPUReader: Reader {
|
||||
inUseOnAllCores = inUseOnAllCores + inUse
|
||||
totalOnAllCores = totalOnAllCores + total
|
||||
}
|
||||
self.usage << (Float(inUseOnAllCores) / Float(totalOnAllCores))
|
||||
self.usage << (Double(inUseOnAllCores) / Double(totalOnAllCores))
|
||||
|
||||
CPUUsageLock.unlock()
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
|
||||
class DiskReader: Reader {
|
||||
var usage: Observable<Float>!
|
||||
var usage: Observable<Double>!
|
||||
var available: Bool = true
|
||||
var updateTimer: Timer!
|
||||
|
||||
@@ -38,7 +38,7 @@ class DiskReader: Reader {
|
||||
let free = freeDiskSpaceInBytes()
|
||||
let usedSpace = total - free
|
||||
|
||||
self.usage << (Float(usedSpace) / Float(total))
|
||||
self.usage << (Double(usedSpace) / Double(total))
|
||||
}
|
||||
|
||||
func totalDiskSpaceInBytes() -> Int64 {
|
||||
|
||||
@@ -102,6 +102,8 @@ class Memory: Module {
|
||||
sender.state = sender.state == NSControl.StateValue.on ? NSControl.StateValue.off : NSControl.StateValue.on
|
||||
self.defaults.set(widgetCode, forKey: "\(name)_widget")
|
||||
self.widgetType = widgetCode
|
||||
self.active << false
|
||||
self.initWidget()
|
||||
self.active << true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
|
||||
class MemoryReader: Reader {
|
||||
var usage: Observable<Float>!
|
||||
var usage: Observable<Double>!
|
||||
var available: Bool = true
|
||||
var updateTimer: Timer!
|
||||
var totalSize: Float
|
||||
@@ -68,7 +68,7 @@ class MemoryReader: Reader {
|
||||
let compressed = Float(stats.compressor_page_count) * Float(PAGE_SIZE)
|
||||
|
||||
let free = totalSize - (active + wired + compressed)
|
||||
self.usage << ((totalSize - free) / totalSize)
|
||||
self.usage << Double((totalSize - free) / totalSize)
|
||||
}
|
||||
else {
|
||||
print("Error with host_statistics64(): " + (String(cString: mach_error_string(kerr), encoding: String.Encoding.ascii) ?? "unknown error"))
|
||||
|
||||
131
Stats/Modules/Network/Network.swift
Normal file
131
Stats/Modules/Network/Network.swift
Normal file
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// Network.swift
|
||||
// Stats
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 24.06.2019.
|
||||
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class Network: Module {
|
||||
var name: String = "Network"
|
||||
var shortName: String = "NET"
|
||||
var view: NSView = NSView()
|
||||
var menu: NSMenuItem = NSMenuItem()
|
||||
var submenu: NSMenu = NSMenu()
|
||||
var active: Observable<Bool>
|
||||
var available: Observable<Bool>
|
||||
var reader: Reader = NetworkReader()
|
||||
var widgetType: WidgetType = 2.0
|
||||
|
||||
let defaults = UserDefaults.standard
|
||||
|
||||
init() {
|
||||
self.available = Observable(self.reader.available)
|
||||
self.active = Observable(defaults.object(forKey: name) != nil ? defaults.bool(forKey: name) : true)
|
||||
self.widgetType = defaults.object(forKey: "\(name)_widget") != nil ? defaults.float(forKey: "\(name)_widget") : Widgets.Dots
|
||||
initMenu()
|
||||
initWidget()
|
||||
}
|
||||
|
||||
func start() {
|
||||
self.reader.start()
|
||||
|
||||
self.reader.usage.subscribe(observer: self) { (value, _) in
|
||||
if !value.isNaN {
|
||||
(self.view as! Widget).value(value: value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
let dots = NSMenuItem(title: "Dots", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
dots.state = self.widgetType == Widgets.Dots ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
dots.target = self
|
||||
|
||||
let arrows = NSMenuItem(title: "Arrows", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
arrows.state = self.widgetType == Widgets.Arrows ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
arrows.target = self
|
||||
|
||||
let text = NSMenuItem(title: "Text", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
text.state = self.widgetType == Widgets.Text ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
text.target = self
|
||||
|
||||
let dotsWithText = NSMenuItem(title: "Dots with text", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
dotsWithText.state = self.widgetType == Widgets.DotsWithText ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
dotsWithText.target = self
|
||||
|
||||
let arrowsWithText = NSMenuItem(title: "Arrows with text", action: #selector(toggleWidget), keyEquivalent: "")
|
||||
arrowsWithText.state = self.widgetType == Widgets.ArrowsWithText ? NSControl.StateValue.on : NSControl.StateValue.off
|
||||
arrowsWithText.target = self
|
||||
|
||||
submenu.addItem(dots)
|
||||
submenu.addItem(arrows)
|
||||
submenu.addItem(text)
|
||||
submenu.addItem(dotsWithText)
|
||||
submenu.addItem(arrowsWithText)
|
||||
|
||||
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 {
|
||||
self.stop()
|
||||
} else {
|
||||
self.start()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func toggleWidget(_ sender: NSMenuItem) {
|
||||
var widgetCode: Float = 0.0
|
||||
|
||||
switch sender.title {
|
||||
case "Dots":
|
||||
widgetCode = Widgets.Dots
|
||||
case "Arrows":
|
||||
widgetCode = Widgets.Arrows
|
||||
case "Text":
|
||||
widgetCode = Widgets.Text
|
||||
case "Dots with text":
|
||||
widgetCode = Widgets.DotsWithText
|
||||
case "Arrows with text":
|
||||
widgetCode = Widgets.ArrowsWithText
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if self.widgetType == widgetCode {
|
||||
return
|
||||
}
|
||||
|
||||
for item in self.submenu.items {
|
||||
if item.title == "Dots" || item.title == "Arrows" || item.title == "Text" || item.title == "Dots with text" || item.title == "Arrows with text" {
|
||||
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.active << false
|
||||
initWidget()
|
||||
self.active << true
|
||||
}
|
||||
}
|
||||
66
Stats/Modules/Network/NetworkReader.swift
Normal file
66
Stats/Modules/Network/NetworkReader.swift
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// NetworkReader.swift
|
||||
// Stats
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 24.06.2019.
|
||||
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class NetworkReader: Reader {
|
||||
var usage: Observable<Double>!
|
||||
var available: Bool = true
|
||||
var updateTimer: Timer!
|
||||
|
||||
var netProcess: Process = Process()
|
||||
var pipe: Pipe = Pipe()
|
||||
|
||||
init() {
|
||||
self.usage = Observable(0)
|
||||
netProcess.launchPath = "/usr/bin/env"
|
||||
netProcess.arguments = ["netstat", "-w1", "-l", "en0"]
|
||||
netProcess.standardOutput = pipe
|
||||
}
|
||||
|
||||
func start() {
|
||||
if netProcess.isRunning {
|
||||
return
|
||||
}
|
||||
self.pipe.fileHandleForReading.waitForDataInBackgroundAndNotify()
|
||||
|
||||
NotificationCenter.default.addObserver(forName: NSNotification.Name.NSFileHandleDataAvailable, object: self.pipe.fileHandleForReading , queue: nil) { _ -> Void in
|
||||
defer {
|
||||
self.pipe.fileHandleForReading.waitForDataInBackgroundAndNotify()
|
||||
}
|
||||
|
||||
let output = self.pipe.fileHandleForReading.availableData
|
||||
if output.isEmpty {
|
||||
return
|
||||
}
|
||||
|
||||
let outputString = String(data: output, encoding: String.Encoding.utf8) ?? ""
|
||||
let arr = outputString.condenseWhitespace().split(separator: " ")
|
||||
|
||||
if !arr.isEmpty && Int64(arr[0]) != nil {
|
||||
guard let download = Int64(arr[2]), let upload = Int64(arr[5]) else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let value: Double = Double("\(download).\(upload)") else {
|
||||
return
|
||||
}
|
||||
|
||||
self.usage << value
|
||||
}
|
||||
}
|
||||
|
||||
netProcess.launch()
|
||||
}
|
||||
|
||||
func stop() {
|
||||
netProcess.interrupt()
|
||||
}
|
||||
|
||||
func read() {}
|
||||
}
|
||||
@@ -17,9 +17,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.1.0</string>
|
||||
<string>1.2.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<string>3</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-only</key>
|
||||
<true/>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-only</key>
|
||||
<true/>
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
287
Stats/Supporting Files/Updates.storyboard
Normal file
287
Stats/Supporting Files/Updates.storyboard
Normal file
@@ -0,0 +1,287 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<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>
|
||||
<scenes>
|
||||
<!--Window Controller-->
|
||||
<scene sceneID="Qxa-eF-fGn">
|
||||
<objects>
|
||||
<windowController storyboardIdentifier="UpdatesVC" id="eTp-5e-KuD" sceneMemberID="viewController">
|
||||
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="MdT-C2-Xn6">
|
||||
<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="140"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1057"/>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="eTp-5e-KuD" id="Kaj-pD-86v"/>
|
||||
</connections>
|
||||
</window>
|
||||
<connections>
|
||||
<segue destination="Jvz-IB-V0r" kind="relationship" relationship="window.shadowedContentViewController" id="xGi-4Z-y1y"/>
|
||||
</connections>
|
||||
</windowController>
|
||||
<customObject id="cb1-RP-9mi" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="4" y="48"/>
|
||||
</scene>
|
||||
<!--UpdatesVC-->
|
||||
<scene sceneID="dHW-OY-NO5">
|
||||
<objects>
|
||||
<viewController id="Jvz-IB-V0r" customClass="UpdatesVC" customModule="Stats" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" id="c5r-hq-Fd6">
|
||||
<rect key="frame" x="0.0" y="0.0" width="440" height="140"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<stackView hidden="YES" distribution="fill" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gbc-x4-ULo">
|
||||
<rect key="frame" x="20" y="20" width="400" height="100"/>
|
||||
<subviews>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="lil-l7-SfL">
|
||||
<rect key="frame" x="0.0" y="0.0" width="100" height="100"/>
|
||||
<subviews>
|
||||
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="dW0-Eg-dcV">
|
||||
<rect key="frame" x="5" y="20" width="80" height="80"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="80" id="M09-H6-mdV"/>
|
||||
<constraint firstAttribute="width" constant="80" id="OXL-r3-XPM"/>
|
||||
</constraints>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="AppIcon" id="qay-dJ-vRD"/>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="100" id="426-Mn-c7c"/>
|
||||
<constraint firstAttribute="width" constant="100" id="J6X-3U-Tq1"/>
|
||||
<constraint firstItem="dW0-Eg-dcV" firstAttribute="top" secondItem="lil-l7-SfL" secondAttribute="top" id="faU-OY-TeM"/>
|
||||
<constraint firstItem="dW0-Eg-dcV" firstAttribute="leading" secondItem="lil-l7-SfL" secondAttribute="leading" constant="5" id="hQN-bI-dc4"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
<stackView distribution="fill" orientation="vertical" alignment="trailing" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="a2t-Ca-JuB">
|
||||
<rect key="frame" x="108" y="0.0" width="292" height="100"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ouZ-jq-tRu">
|
||||
<rect key="frame" x="-2" y="82" width="296" height="18"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="New Version Available" id="ifE-Um-dTa">
|
||||
<font key="font" metaFont="systemBold" size="14"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="4" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ePi-7H-tuZ">
|
||||
<rect key="frame" x="0.0" y="36" width="292" height="38"/>
|
||||
<subviews>
|
||||
<stackView distribution="fillEqually" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ekt-ux-mcR">
|
||||
<rect key="frame" x="0.0" y="21" width="208" height="17"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="fOg-zl-1M0">
|
||||
<rect key="frame" x="-2" y="0.0" width="104" height="17"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="100" id="xw9-2q-BDa"/>
|
||||
</constraints>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Latest version:" id="ETQ-A6-cne">
|
||||
<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>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zPp-kk-s1Y">
|
||||
<rect key="frame" x="106" y="0.0" width="104" height="17"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="0.0.0" id="beD-Uf-T9l">
|
||||
<font key="font" metaFont="systemMedium" 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>
|
||||
<stackView distribution="fillEqually" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wYM-Rg-iB8">
|
||||
<rect key="frame" x="0.0" y="0.0" width="208" height="17"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gxk-NW-8MC">
|
||||
<rect key="frame" x="-2" y="0.0" width="104" height="17"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="100" id="3hv-Qv-72l"/>
|
||||
</constraints>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Current version:" id="pkM-KV-LXp">
|
||||
<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>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gob-ke-eHN">
|
||||
<rect key="frame" x="106" y="0.0" width="104" height="17"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="0.0.0" id="w43-pL-4IU">
|
||||
<font key="font" metaFont="systemMedium" 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>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="38" id="hTG-ET-Q9C"/>
|
||||
</constraints>
|
||||
<visibilityPriorities>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
</visibilityPriorities>
|
||||
<customSpacing>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
</customSpacing>
|
||||
</stackView>
|
||||
<stackView distribution="fill" orientation="horizontal" alignment="bottom" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="sXv-6U-z9c">
|
||||
<rect key="frame" x="132" y="0.0" width="160" height="28"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4Ft-uA-xyo">
|
||||
<rect key="frame" x="-6" y="-7" width="101" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Download" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="lYz-7d-p0I">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="download:" target="Jvz-IB-V0r" id="CaY-3w-sQl"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9JO-Ob-lhu">
|
||||
<rect key="frame" x="91" y="-7" width="75" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Close" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="kc0-rN-ti2">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="exit:" target="Jvz-IB-V0r" id="8ae-Af-YpV"/>
|
||||
</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="bottom" secondItem="sXv-6U-z9c" secondAttribute="bottom" id="0wF-S8-fdh"/>
|
||||
<constraint firstItem="ouZ-jq-tRu" firstAttribute="leading" secondItem="a2t-Ca-JuB" secondAttribute="leading" id="EHv-7M-gMc"/>
|
||||
<constraint firstItem="ePi-7H-tuZ" firstAttribute="leading" secondItem="a2t-Ca-JuB" secondAttribute="leading" id="OwE-N0-YYv"/>
|
||||
<constraint firstAttribute="trailing" secondItem="ouZ-jq-tRu" secondAttribute="trailing" id="rVg-xV-PZ3"/>
|
||||
<constraint firstAttribute="trailing" secondItem="ePi-7H-tuZ" secondAttribute="trailing" id="sxv-7o-0SH"/>
|
||||
</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 firstAttribute="width" constant="400" id="Acb-hj-G5c"/>
|
||||
<constraint firstAttribute="bottom" secondItem="a2t-Ca-JuB" secondAttribute="bottom" id="Ari-ig-V9M"/>
|
||||
<constraint firstAttribute="trailing" secondItem="a2t-Ca-JuB" secondAttribute="trailing" id="M7p-NR-yqx"/>
|
||||
<constraint firstItem="a2t-Ca-JuB" firstAttribute="top" secondItem="gbc-x4-ULo" secondAttribute="top" id="dyF-7z-8sN"/>
|
||||
<constraint firstAttribute="height" constant="100" id="f6V-S5-nxa"/>
|
||||
<constraint firstItem="a2t-Ca-JuB" firstAttribute="leading" secondItem="lil-l7-SfL" secondAttribute="trailing" constant="8" id="xeZ-6k-w1Q"/>
|
||||
</constraints>
|
||||
<visibilityPriorities>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
</visibilityPriorities>
|
||||
<customSpacing>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
</customSpacing>
|
||||
</stackView>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="TaT-Bx-z9f">
|
||||
<rect key="frame" x="0.0" y="0.0" width="440" height="140"/>
|
||||
<subviews>
|
||||
<progressIndicator wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" bezeled="NO" indeterminate="YES" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="4lV-OW-XAy">
|
||||
<rect key="frame" x="204" y="54" width="32" height="32"/>
|
||||
</progressIndicator>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="4lV-OW-XAy" firstAttribute="centerX" secondItem="TaT-Bx-z9f" secondAttribute="centerX" id="RSU-P4-ZMI"/>
|
||||
<constraint firstItem="4lV-OW-XAy" firstAttribute="centerY" secondItem="TaT-Bx-z9f" secondAttribute="centerY" id="yJ2-V9-z1C"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
<customView hidden="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VuR-f2-eNB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="440" height="140"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="jbE-84-Rxv">
|
||||
<rect key="frame" x="120" y="61" width="200" height="17"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Internet connection not available" id="zbB-5V-Hny">
|
||||
<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>
|
||||
<constraints>
|
||||
<constraint firstItem="jbE-84-Rxv" firstAttribute="centerX" secondItem="VuR-f2-eNB" secondAttribute="centerX" id="8Qe-nE-B8p"/>
|
||||
<constraint firstItem="jbE-84-Rxv" firstAttribute="centerY" secondItem="VuR-f2-eNB" secondAttribute="centerY" id="QGV-Gz-g7v"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="VuR-f2-eNB" firstAttribute="leading" secondItem="c5r-hq-Fd6" secondAttribute="leading" id="84G-yg-hMa"/>
|
||||
<constraint firstItem="gbc-x4-ULo" firstAttribute="centerX" secondItem="c5r-hq-Fd6" secondAttribute="centerX" id="Dpi-rK-AzM"/>
|
||||
<constraint firstItem="TaT-Bx-z9f" firstAttribute="leading" secondItem="c5r-hq-Fd6" secondAttribute="leading" id="E51-Oc-2V4"/>
|
||||
<constraint firstAttribute="bottom" secondItem="VuR-f2-eNB" secondAttribute="bottom" id="F2o-tO-1Cw"/>
|
||||
<constraint firstAttribute="trailing" secondItem="VuR-f2-eNB" secondAttribute="trailing" id="IpB-2O-18u"/>
|
||||
<constraint firstAttribute="bottom" secondItem="gbc-x4-ULo" secondAttribute="bottom" constant="20" id="LMa-In-o74"/>
|
||||
<constraint firstItem="gbc-x4-ULo" firstAttribute="top" secondItem="c5r-hq-Fd6" secondAttribute="top" constant="20" id="LRc-d3-GD7"/>
|
||||
<constraint firstItem="TaT-Bx-z9f" firstAttribute="top" secondItem="c5r-hq-Fd6" secondAttribute="top" id="R4W-Se-evk"/>
|
||||
<constraint firstAttribute="trailing" secondItem="TaT-Bx-z9f" secondAttribute="trailing" id="WwE-PV-CRA"/>
|
||||
<constraint firstItem="gbc-x4-ULo" firstAttribute="leading" secondItem="c5r-hq-Fd6" secondAttribute="leading" constant="20" id="dFH-7N-tFv"/>
|
||||
<constraint firstItem="VuR-f2-eNB" firstAttribute="top" secondItem="c5r-hq-Fd6" secondAttribute="top" id="dMy-6f-EzA"/>
|
||||
<constraint firstAttribute="bottom" secondItem="TaT-Bx-z9f" secondAttribute="bottom" id="eSI-Yp-nsb"/>
|
||||
<constraint firstAttribute="trailing" secondItem="gbc-x4-ULo" secondAttribute="trailing" constant="20" id="fVu-MD-LPi"/>
|
||||
<constraint firstItem="gbc-x4-ULo" firstAttribute="centerY" secondItem="c5r-hq-Fd6" secondAttribute="centerY" id="m0O-DZ-N1Z"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="currentVersionLabel" destination="gob-ke-eHN" id="CEW-EL-VoZ"/>
|
||||
<outlet property="downloadButton" destination="4Ft-uA-xyo" id="gIo-OP-jHo"/>
|
||||
<outlet property="latestVersionLabel" destination="zPp-kk-s1Y" id="Rw8-5R-dgM"/>
|
||||
<outlet property="mainTextLabel" destination="ifE-Um-dTa" id="srK-S1-Icw"/>
|
||||
<outlet property="mainView" destination="gbc-x4-ULo" id="8kc-ng-29G"/>
|
||||
<outlet property="noInternetView" destination="VuR-f2-eNB" id="LrM-sz-2Ej"/>
|
||||
<outlet property="spinner" destination="4lV-OW-XAy" id="a0Q-hW-TxG"/>
|
||||
<outlet property="spinnerView" destination="TaT-Bx-z9f" id="bsd-xe-n0O"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<customObject id="bP2-Gx-7ZJ" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="4" y="386"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="AppIcon" width="128" height="128"/>
|
||||
</resources>
|
||||
</document>
|
||||
@@ -12,7 +12,7 @@ class BatteryView: NSView, Widget {
|
||||
let batteryWidth: CGFloat = 32
|
||||
let percentageWidth: CGFloat = 40
|
||||
|
||||
var value: Float {
|
||||
var value: Double {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
@@ -90,7 +90,6 @@ class BatteryView: NSView, Widget {
|
||||
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
|
||||
@@ -118,7 +117,7 @@ class BatteryView: NSView, Widget {
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Float) {
|
||||
func value(value: Double) {
|
||||
if self.value != value {
|
||||
self.value = value
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import Cocoa
|
||||
|
||||
class Chart: NSView, Widget {
|
||||
var height: CGFloat = 0.0
|
||||
var points: [Float] {
|
||||
var points: [Double] {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class Chart: NSView, Widget {
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
|
||||
let lineColor: NSColor = NSColor.selectedMenuItemColor
|
||||
let lineColor: NSColor = NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 1.0)
|
||||
let gradientColor: NSColor = NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 0.5)
|
||||
|
||||
let context = NSGraphicsContext.current!.cgContext
|
||||
@@ -83,7 +83,7 @@ class Chart: NSView, Widget {
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Float) {
|
||||
func value(value: Double) {
|
||||
if self.points.count < 50 {
|
||||
self.points.append(value)
|
||||
return
|
||||
@@ -129,9 +129,9 @@ class ChartWithValue: Chart {
|
||||
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()
|
||||
override func value(value: Double) {
|
||||
self.valueLabel.stringValue = "\(Int(Float(value.roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.valueLabel.textColor = value.usageColor()
|
||||
|
||||
if self.points.count < 50 {
|
||||
self.points.append(value)
|
||||
|
||||
@@ -12,7 +12,7 @@ class Mini: NSView, Widget {
|
||||
var valueView: NSTextField = NSTextField()
|
||||
var labelView: NSTextField = NSTextField()
|
||||
|
||||
var value: Float = 0
|
||||
var value: Double = 0
|
||||
var label: String = "" {
|
||||
didSet {
|
||||
self.labelView.stringValue = label
|
||||
@@ -66,17 +66,17 @@ class Mini: NSView, Widget {
|
||||
}
|
||||
|
||||
func redraw() {
|
||||
self.valueView.textColor = Float(self.value).usageColor()
|
||||
self.valueView.textColor = self.value.usageColor()
|
||||
self.needsDisplay = true
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Float) {
|
||||
func value(value: Double) {
|
||||
if self.value != value {
|
||||
self.value = value
|
||||
|
||||
self.valueView.stringValue = "\(Int(Float(Float(value).roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.valueView.textColor = Float(value).usageColor()
|
||||
self.valueView.stringValue = "\(Int(Float(value.roundTo(decimalPlaces: 2))! * 100))%"
|
||||
self.valueView.textColor = value.usageColor()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
424
Stats/Widgets/NetworkView.swift
Normal file
424
Stats/Widgets/NetworkView.swift
Normal file
@@ -0,0 +1,424 @@
|
||||
//
|
||||
// NetworkView.swift
|
||||
// Stats
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 24.06.2019.
|
||||
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class NetworkDotsView: NSView, Widget {
|
||||
var download: Int64 {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
var upload: Int64 {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
|
||||
override init(frame: NSRect) {
|
||||
self.download = 0
|
||||
self.upload = 0
|
||||
super.init(frame: CGRect(x: 0, y: 0, width: 12, height: frame.size.height))
|
||||
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 workingHeight: CGFloat = (self.frame.size.height - (MODULE_MARGIN * 2))
|
||||
let height: CGFloat = ((workingHeight - MODULE_MARGIN) / 2) - 1
|
||||
|
||||
var uploadCircle = NSBezierPath()
|
||||
uploadCircle = NSBezierPath(ovalIn: CGRect(x: MODULE_MARGIN, y: height + (MODULE_MARGIN * 2) + 1, width: height, height: height))
|
||||
if self.upload >= 1_024 {
|
||||
NSColor.red.setFill()
|
||||
} else {
|
||||
NSColor.labelColor.setFill()
|
||||
}
|
||||
uploadCircle.fill()
|
||||
|
||||
var downloadCircle = NSBezierPath()
|
||||
downloadCircle = NSBezierPath(ovalIn: CGRect(x: MODULE_MARGIN, y: MODULE_MARGIN, width: height, height: height))
|
||||
if self.download >= 1_024 {
|
||||
NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 0.8).setFill()
|
||||
} else {
|
||||
NSColor.labelColor.setFill()
|
||||
}
|
||||
downloadCircle.fill()
|
||||
}
|
||||
|
||||
func redraw() {
|
||||
self.needsDisplay = true
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Double) {
|
||||
let values = value.splitAtDecimal()
|
||||
if self.download != values[0] {
|
||||
self.download = values[0]
|
||||
}
|
||||
if self.upload != values[1] {
|
||||
self.upload = values[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NetworkTextView: NSView, Widget {
|
||||
var downloadValue: NSTextField = NSTextField()
|
||||
var uploadValue: NSTextField = NSTextField()
|
||||
|
||||
override init(frame: NSRect) {
|
||||
super.init(frame: CGRect(x: 0, y: 0, width: MODULE_WIDTH + 20, height: frame.size.height))
|
||||
self.wantsLayer = true
|
||||
self.valueView()
|
||||
}
|
||||
|
||||
required init?(coder decoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
}
|
||||
|
||||
func redraw() {
|
||||
self.needsDisplay = true
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Double) {
|
||||
let values = value.splitAtDecimal()
|
||||
downloadValue.stringValue = Units(bytes: values[0]).getReadableUnit()
|
||||
uploadValue.stringValue = Units(bytes: values[1]).getReadableUnit()
|
||||
}
|
||||
|
||||
func valueView() {
|
||||
downloadValue = NSTextField(frame: NSMakeRect(MODULE_MARGIN, MODULE_MARGIN, self.frame.size.width - MODULE_MARGIN, 9))
|
||||
downloadValue.isEditable = false
|
||||
downloadValue.isSelectable = false
|
||||
downloadValue.isBezeled = false
|
||||
downloadValue.wantsLayer = true
|
||||
downloadValue.textColor = .labelColor
|
||||
downloadValue.backgroundColor = .controlColor
|
||||
downloadValue.canDrawSubviewsIntoLayer = true
|
||||
downloadValue.alignment = .right
|
||||
downloadValue.font = NSFont.systemFont(ofSize: 9, weight: .light)
|
||||
downloadValue.stringValue = "0 KB/s"
|
||||
|
||||
uploadValue = NSTextField(frame: NSMakeRect(MODULE_MARGIN, self.frame.size.height - 10, self.frame.size.width - MODULE_MARGIN, 9))
|
||||
uploadValue.isEditable = false
|
||||
uploadValue.isSelectable = false
|
||||
uploadValue.isBezeled = false
|
||||
uploadValue.wantsLayer = true
|
||||
uploadValue.textColor = .labelColor
|
||||
uploadValue.backgroundColor = .controlColor
|
||||
uploadValue.canDrawSubviewsIntoLayer = true
|
||||
uploadValue.alignment = .right
|
||||
uploadValue.font = NSFont.systemFont(ofSize: 9, weight: .light)
|
||||
uploadValue.stringValue = "0 KB/s"
|
||||
|
||||
self.addSubview(downloadValue)
|
||||
self.addSubview(uploadValue)
|
||||
}
|
||||
}
|
||||
|
||||
class NetworkArrowsView: NSView, Widget {
|
||||
var download: Int64 {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
var upload: Int64 {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
|
||||
override init(frame: NSRect) {
|
||||
self.download = 0
|
||||
self.upload = 0
|
||||
super.init(frame: CGRect(x: 0, y: 0, width: 8, height: frame.size.height))
|
||||
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 arrowAngle = CGFloat(Double.pi / 5)
|
||||
let pointerLineLength: CGFloat = 3.5
|
||||
let workingHeight: CGFloat = (self.frame.size.height - (MODULE_MARGIN * 2))
|
||||
let height: CGFloat = ((workingHeight - MODULE_MARGIN) / 2)
|
||||
|
||||
let downloadArrow = NSBezierPath()
|
||||
let downloadStart = CGPoint(x: MODULE_MARGIN + (pointerLineLength/2), y: height + MODULE_MARGIN)
|
||||
let downloadEnd = CGPoint(x: MODULE_MARGIN + (pointerLineLength/2), y: MODULE_MARGIN)
|
||||
|
||||
downloadArrow.addArrow(start: downloadStart, end: downloadEnd, pointerLineLength: pointerLineLength, arrowAngle: arrowAngle)
|
||||
|
||||
if self.download >= 1_024 {
|
||||
NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 0.8).set()
|
||||
} else {
|
||||
NSColor.labelColor.set()
|
||||
}
|
||||
downloadArrow.lineWidth = 1
|
||||
downloadArrow.stroke()
|
||||
downloadArrow.close()
|
||||
|
||||
let uploadArrow = NSBezierPath()
|
||||
let uploadStart = CGPoint(x: MODULE_MARGIN + (pointerLineLength/2), y: height + (MODULE_MARGIN * 2))
|
||||
let uploadEnd = CGPoint(x: MODULE_MARGIN + (pointerLineLength/2), y: (MODULE_MARGIN * 2) + (height * 2))
|
||||
|
||||
uploadArrow.addArrow(start: uploadStart, end: uploadEnd, pointerLineLength: pointerLineLength, arrowAngle: arrowAngle)
|
||||
|
||||
if self.upload >= 1_024 {
|
||||
NSColor.red.set()
|
||||
} else {
|
||||
NSColor.labelColor.set()
|
||||
}
|
||||
uploadArrow.lineWidth = 1
|
||||
uploadArrow.stroke()
|
||||
uploadArrow.close()
|
||||
}
|
||||
|
||||
func redraw() {
|
||||
self.needsDisplay = true
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Double) {
|
||||
let values = value.splitAtDecimal()
|
||||
if self.download != values[0] {
|
||||
self.download = values[0]
|
||||
}
|
||||
if self.upload != values[1] {
|
||||
self.upload = values[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NetworkDotsTextView: NSView, Widget {
|
||||
var download: Int64 {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
var upload: Int64 {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
|
||||
var downloadValue: NSTextField = NSTextField()
|
||||
var uploadValue: NSTextField = NSTextField()
|
||||
|
||||
override init(frame: NSRect) {
|
||||
self.download = 0
|
||||
self.upload = 0
|
||||
super.init(frame: CGRect(x: 0, y: 0, width: MODULE_WIDTH + 26, height: frame.size.height))
|
||||
self.wantsLayer = true
|
||||
self.valueView()
|
||||
}
|
||||
|
||||
required init?(coder decoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
|
||||
let workingHeight: CGFloat = (self.frame.size.height - (MODULE_MARGIN * 2))
|
||||
let height: CGFloat = ((workingHeight - MODULE_MARGIN) / 2) - 1
|
||||
|
||||
var uploadCircle = NSBezierPath()
|
||||
uploadCircle = NSBezierPath(ovalIn: CGRect(x: MODULE_MARGIN, y: height + (MODULE_MARGIN * 2) + 1, width: height, height: height))
|
||||
if self.upload >= 1_024 {
|
||||
NSColor.red.setFill()
|
||||
} else {
|
||||
NSColor.labelColor.setFill()
|
||||
}
|
||||
uploadCircle.fill()
|
||||
|
||||
var downloadCircle = NSBezierPath()
|
||||
downloadCircle = NSBezierPath(ovalIn: CGRect(x: MODULE_MARGIN, y: MODULE_MARGIN, width: height, height: height))
|
||||
if self.download >= 1_024 {
|
||||
NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 0.8).setFill()
|
||||
} else {
|
||||
NSColor.labelColor.setFill()
|
||||
}
|
||||
downloadCircle.fill()
|
||||
}
|
||||
|
||||
func redraw() {
|
||||
self.needsDisplay = true
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Double) {
|
||||
let values = value.splitAtDecimal()
|
||||
if self.download != values[0] {
|
||||
self.download = values[0]
|
||||
downloadValue.stringValue = Units(bytes: self.download).getReadableUnit()
|
||||
}
|
||||
if self.upload != values[1] {
|
||||
self.upload = values[1]
|
||||
uploadValue.stringValue = Units(bytes: self.upload).getReadableUnit()
|
||||
}
|
||||
}
|
||||
|
||||
func valueView() {
|
||||
downloadValue = NSTextField(frame: NSMakeRect(MODULE_MARGIN, MODULE_MARGIN, self.frame.size.width - MODULE_MARGIN, 9))
|
||||
downloadValue.isEditable = false
|
||||
downloadValue.isSelectable = false
|
||||
downloadValue.isBezeled = false
|
||||
downloadValue.wantsLayer = true
|
||||
downloadValue.textColor = .labelColor
|
||||
downloadValue.backgroundColor = .controlColor
|
||||
downloadValue.canDrawSubviewsIntoLayer = true
|
||||
downloadValue.alignment = .right
|
||||
downloadValue.font = NSFont.systemFont(ofSize: 9, weight: .light)
|
||||
downloadValue.stringValue = "0 KB/s"
|
||||
|
||||
uploadValue = NSTextField(frame: NSMakeRect(MODULE_MARGIN, self.frame.size.height - 10, self.frame.size.width - MODULE_MARGIN, 9))
|
||||
uploadValue.isEditable = false
|
||||
uploadValue.isSelectable = false
|
||||
uploadValue.isBezeled = false
|
||||
uploadValue.wantsLayer = true
|
||||
uploadValue.textColor = .labelColor
|
||||
uploadValue.backgroundColor = .controlColor
|
||||
uploadValue.canDrawSubviewsIntoLayer = true
|
||||
uploadValue.alignment = .right
|
||||
uploadValue.font = NSFont.systemFont(ofSize: 9, weight: .light)
|
||||
uploadValue.stringValue = "0 KB/s"
|
||||
|
||||
self.addSubview(downloadValue)
|
||||
self.addSubview(uploadValue)
|
||||
}
|
||||
}
|
||||
|
||||
class NetworkArrowsTextView: NSView, Widget {
|
||||
var download: Int64 {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
var upload: Int64 {
|
||||
didSet {
|
||||
self.redraw()
|
||||
}
|
||||
}
|
||||
|
||||
var downloadValue: NSTextField = NSTextField()
|
||||
var uploadValue: NSTextField = NSTextField()
|
||||
|
||||
override init(frame: NSRect) {
|
||||
self.download = 0
|
||||
self.upload = 0
|
||||
super.init(frame: CGRect(x: 0, y: 0, width: MODULE_WIDTH + 24, height: frame.size.height))
|
||||
self.wantsLayer = true
|
||||
self.valueView()
|
||||
}
|
||||
|
||||
required init?(coder decoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
super.draw(dirtyRect)
|
||||
|
||||
let arrowAngle = CGFloat(Double.pi / 5)
|
||||
let pointerLineLength: CGFloat = 3.5
|
||||
let workingHeight: CGFloat = (self.frame.size.height - (MODULE_MARGIN * 2))
|
||||
let height: CGFloat = ((workingHeight - MODULE_MARGIN) / 2)
|
||||
|
||||
let downloadArrow = NSBezierPath()
|
||||
let downloadStart = CGPoint(x: MODULE_MARGIN + (pointerLineLength/2), y: height + MODULE_MARGIN)
|
||||
let downloadEnd = CGPoint(x: MODULE_MARGIN + (pointerLineLength/2), y: MODULE_MARGIN)
|
||||
|
||||
downloadArrow.addArrow(start: downloadStart, end: downloadEnd, pointerLineLength: pointerLineLength, arrowAngle: arrowAngle)
|
||||
|
||||
if self.download >= 1_024 {
|
||||
NSColor(red: (26/255.0), green: (126/255.0), blue: (252/255.0), alpha: 0.8).set()
|
||||
} else {
|
||||
NSColor.labelColor.set()
|
||||
}
|
||||
downloadArrow.lineWidth = 1
|
||||
downloadArrow.stroke()
|
||||
downloadArrow.close()
|
||||
|
||||
let uploadArrow = NSBezierPath()
|
||||
let uploadStart = CGPoint(x: MODULE_MARGIN + (pointerLineLength/2), y: height + (MODULE_MARGIN * 2))
|
||||
let uploadEnd = CGPoint(x: MODULE_MARGIN + (pointerLineLength/2), y: (MODULE_MARGIN * 2) + (height * 2))
|
||||
|
||||
uploadArrow.addArrow(start: uploadStart, end: uploadEnd, pointerLineLength: pointerLineLength, arrowAngle: arrowAngle)
|
||||
|
||||
if self.upload >= 1_024 {
|
||||
NSColor.red.set()
|
||||
} else {
|
||||
NSColor.labelColor.set()
|
||||
}
|
||||
uploadArrow.lineWidth = 1
|
||||
uploadArrow.stroke()
|
||||
uploadArrow.close()
|
||||
}
|
||||
|
||||
func redraw() {
|
||||
self.needsDisplay = true
|
||||
setNeedsDisplay(self.frame)
|
||||
}
|
||||
|
||||
func value(value: Double) {
|
||||
let values = value.splitAtDecimal()
|
||||
if self.download != values[0] {
|
||||
self.download = values[0]
|
||||
downloadValue.stringValue = Units(bytes: self.download).getReadableUnit()
|
||||
}
|
||||
if self.upload != values[1] {
|
||||
self.upload = values[1]
|
||||
uploadValue.stringValue = Units(bytes: self.upload).getReadableUnit()
|
||||
}
|
||||
}
|
||||
|
||||
func valueView() {
|
||||
downloadValue = NSTextField(frame: NSMakeRect(MODULE_MARGIN, MODULE_MARGIN, self.frame.size.width - MODULE_MARGIN, 9))
|
||||
downloadValue.isEditable = false
|
||||
downloadValue.isSelectable = false
|
||||
downloadValue.isBezeled = false
|
||||
downloadValue.wantsLayer = true
|
||||
downloadValue.textColor = .labelColor
|
||||
downloadValue.backgroundColor = .controlColor
|
||||
downloadValue.canDrawSubviewsIntoLayer = true
|
||||
downloadValue.alignment = .right
|
||||
downloadValue.font = NSFont.systemFont(ofSize: 9, weight: .light)
|
||||
downloadValue.stringValue = "0 KB/s"
|
||||
|
||||
uploadValue = NSTextField(frame: NSMakeRect(MODULE_MARGIN, self.frame.size.height - 10, self.frame.size.width - MODULE_MARGIN, 9))
|
||||
uploadValue.isEditable = false
|
||||
uploadValue.isSelectable = false
|
||||
uploadValue.isBezeled = false
|
||||
uploadValue.wantsLayer = true
|
||||
uploadValue.textColor = .labelColor
|
||||
uploadValue.backgroundColor = .controlColor
|
||||
uploadValue.canDrawSubviewsIntoLayer = true
|
||||
uploadValue.alignment = .right
|
||||
uploadValue.font = NSFont.systemFont(ofSize: 9, weight: .light)
|
||||
uploadValue.stringValue = "0 KB/s"
|
||||
|
||||
self.addSubview(downloadValue)
|
||||
self.addSubview(uploadValue)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import Cocoa
|
||||
|
||||
extension Float {
|
||||
extension Double {
|
||||
func roundTo(decimalPlaces: Int) -> String {
|
||||
return NSString(format: "%.\(decimalPlaces)f" as NSString, self) as String
|
||||
}
|
||||
@@ -59,6 +59,10 @@ extension Float {
|
||||
return NSColor.systemRed
|
||||
}
|
||||
}
|
||||
|
||||
func splitAtDecimal() -> [Int64] {
|
||||
return "\(self)".split(separator: ".").map{Int64($0)!}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Unit : Float {
|
||||
@@ -68,6 +72,76 @@ public enum Unit : Float {
|
||||
case gigabyte = 1073741824
|
||||
}
|
||||
|
||||
public struct Units {
|
||||
public let bytes: Int64
|
||||
|
||||
public init(bytes: Int64) {
|
||||
self.bytes = bytes
|
||||
}
|
||||
|
||||
public var kilobytes: Double {
|
||||
return Double(bytes) / 1_024
|
||||
}
|
||||
public var megabytes: Double {
|
||||
return kilobytes / 1_024
|
||||
}
|
||||
public var gigabytes: Double {
|
||||
return megabytes / 1_024
|
||||
}
|
||||
|
||||
public func getReadableTuple() -> (Double, String) {
|
||||
switch bytes {
|
||||
case 0..<1_024:
|
||||
return (0, "KB/s")
|
||||
case 1_024..<(1_024 * 1_024):
|
||||
return (Double(String(format: "%.2f", kilobytes))!, "KB/s")
|
||||
case 1_024..<(1_024 * 1_024 * 1_024):
|
||||
return (Double(String(format: "%.2f", megabytes))!, "MB/s")
|
||||
case (1_024 * 1_024 * 1_024)...Int64.max:
|
||||
return (Double(String(format: "%.2f", gigabytes))!, "GB/s")
|
||||
default:
|
||||
return (Double(String(format: "%.2f", kilobytes))!, "KB/s")
|
||||
}
|
||||
}
|
||||
|
||||
public func getReadableUnit() -> String {
|
||||
switch bytes {
|
||||
case 0..<1_024:
|
||||
return "0 KB/s"
|
||||
case 1_024..<(1_024 * 1_024):
|
||||
return String(format: "%.0f KB/s", kilobytes)
|
||||
case 1_024..<(1_024 * 1_024 * 1_024):
|
||||
return String(format: "%.2f MB/s", megabytes)
|
||||
case (1_024 * 1_024 * 1_024)...Int64.max:
|
||||
return String(format: "%.2f GB/s", gigabytes)
|
||||
default:
|
||||
return String(format: "%.0f KB/s", kilobytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
func condenseWhitespace() -> String {
|
||||
let components = self.components(separatedBy: .whitespacesAndNewlines)
|
||||
return components.filter { !$0.isEmpty }.joined(separator: " ")
|
||||
}
|
||||
}
|
||||
|
||||
extension NSBezierPath {
|
||||
func addArrow(start: CGPoint, end: CGPoint, pointerLineLength: CGFloat, arrowAngle: CGFloat) {
|
||||
self.move(to: start)
|
||||
self.line(to: end)
|
||||
|
||||
let startEndAngle = atan((end.y - start.y) / (end.x - start.x)) + ((end.x - start.x) < 0 ? CGFloat(Double.pi) : 0)
|
||||
let arrowLine1 = CGPoint(x: end.x + pointerLineLength * cos(CGFloat(Double.pi) - startEndAngle + arrowAngle), y: end.y - pointerLineLength * sin(CGFloat(Double.pi) - startEndAngle + arrowAngle))
|
||||
let arrowLine2 = CGPoint(x: end.x + pointerLineLength * cos(CGFloat(Double.pi) - startEndAngle - arrowAngle), y: end.y - pointerLineLength * sin(CGFloat(Double.pi) - startEndAngle - arrowAngle))
|
||||
|
||||
self.line(to: arrowLine1)
|
||||
self.move(to: end)
|
||||
self.line(to: arrowLine2)
|
||||
}
|
||||
}
|
||||
|
||||
//extension NSView {
|
||||
// var backgroundColor: NSColor? {
|
||||
// get {
|
||||
|
||||
@@ -24,7 +24,6 @@ protocol Module: class {
|
||||
|
||||
extension Module {
|
||||
func initWidget() {
|
||||
self.active << false
|
||||
switch self.widgetType {
|
||||
case Widgets.Mini:
|
||||
let widget = Mini(frame: NSMakeRect(0, 0, MODULE_WIDTH, MODULE_HEIGHT))
|
||||
@@ -34,15 +33,26 @@ extension Module {
|
||||
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))
|
||||
case Widgets.Dots:
|
||||
self.view = NetworkDotsView(frame: NSMakeRect(0, 0, MODULE_WIDTH, MODULE_HEIGHT))
|
||||
break
|
||||
case Widgets.Arrows:
|
||||
self.view = NetworkArrowsView(frame: NSMakeRect(0, 0, MODULE_WIDTH, MODULE_HEIGHT))
|
||||
break
|
||||
case Widgets.Text:
|
||||
self.view = NetworkTextView(frame: NSMakeRect(0, 0, MODULE_WIDTH, MODULE_HEIGHT))
|
||||
break
|
||||
case Widgets.DotsWithText:
|
||||
self.view = NetworkDotsTextView(frame: NSMakeRect(0, 0, MODULE_WIDTH, MODULE_HEIGHT))
|
||||
break
|
||||
case Widgets.ArrowsWithText:
|
||||
self.view = NetworkArrowsTextView(frame: NSMakeRect(0, 0, MODULE_WIDTH, 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 start() {
|
||||
@@ -79,7 +89,7 @@ extension Module {
|
||||
}
|
||||
|
||||
protocol Reader {
|
||||
var usage: Observable<Float>! { get }
|
||||
var usage: Observable<Double>! { get }
|
||||
var available: Bool { get }
|
||||
var updateTimer: Timer! { get set }
|
||||
func start()
|
||||
@@ -88,7 +98,7 @@ protocol Reader {
|
||||
}
|
||||
|
||||
protocol Widget {
|
||||
func value(value: Float)
|
||||
func value(value: Double)
|
||||
func redraw()
|
||||
}
|
||||
|
||||
@@ -98,4 +108,10 @@ struct Widgets {
|
||||
static let Mini: WidgetType = 0.0
|
||||
static let Chart: WidgetType = 1.0
|
||||
static let ChartWithValue: WidgetType = 1.1
|
||||
|
||||
static let Dots: WidgetType = 2.0
|
||||
static let Arrows: WidgetType = 2.1
|
||||
static let Text: WidgetType = 2.2
|
||||
static let DotsWithText: WidgetType = 2.3
|
||||
static let ArrowsWithText: WidgetType = 2.4
|
||||
}
|
||||
|
||||
136
Stats/libs/macAppUpdater.swift
Normal file
136
Stats/libs/macAppUpdater.swift
Normal file
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// macAppUpdater.swift
|
||||
// Stats
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 25.06.2019.
|
||||
// Copyright © 2019 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SystemConfiguration
|
||||
|
||||
extension String: Error {}
|
||||
|
||||
struct version {
|
||||
let current: String
|
||||
let latest: String
|
||||
let newest: Bool
|
||||
let url: String
|
||||
}
|
||||
|
||||
public class macAppUpdater {
|
||||
let user: String
|
||||
let repo: String
|
||||
|
||||
let appName: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String
|
||||
let currentVersion: String = "v\(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String)"
|
||||
|
||||
var url: String {
|
||||
return "https://api.github.com/repos/\(user)/\(repo)/releases/latest"
|
||||
}
|
||||
|
||||
init(user: String, repo: String) {
|
||||
self.user = user
|
||||
self.repo = repo
|
||||
}
|
||||
|
||||
func fetchLastVersion(completionHandler: @escaping (_ result: [String]?, _ error: Error?) -> Void) {
|
||||
let task = URLSession.shared.dataTask(with: URL(string: self.url)!) { data, response, error in
|
||||
guard let data = data, error == nil else { return }
|
||||
|
||||
do {
|
||||
let jsonResponse = try JSONSerialization.jsonObject(with: data, options: [])
|
||||
guard let jsonArray = jsonResponse as? [String: Any] else {
|
||||
completionHandler(nil, "parse json")
|
||||
return
|
||||
}
|
||||
let lastVersion = jsonArray["tag_name"] as? String
|
||||
|
||||
guard let assets = jsonArray["assets"] as? [[String: Any]] else {
|
||||
completionHandler(nil, "parse assets")
|
||||
return
|
||||
}
|
||||
if let asset = assets.first(where: {$0["name"] as! String == "\(self.appName).dmg"}) {
|
||||
let downloadURL = asset["browser_download_url"] as? String
|
||||
completionHandler([lastVersion!, downloadURL!], nil)
|
||||
}
|
||||
} catch let parsingError {
|
||||
completionHandler(nil, parsingError)
|
||||
}
|
||||
}
|
||||
task.resume()
|
||||
}
|
||||
|
||||
func checkIfNewer(current: String, latest: String) -> Bool {
|
||||
guard let currentNumber: Int64 = Int64(current.replacingOccurrences(of: "[v.]", with: "", options: [.regularExpression])) else {
|
||||
print("Error: wrong version tag \(current)")
|
||||
return false
|
||||
}
|
||||
guard let latestNumber: Int64 = Int64(latest.replacingOccurrences(of: "[v.]", with: "", options: [.regularExpression])) else {
|
||||
print("Error: wrong version tag \(latest)")
|
||||
return false
|
||||
}
|
||||
return latestNumber>currentNumber
|
||||
}
|
||||
|
||||
func check(completionHandler: @escaping (_ result: version?, _ error: Error?) -> Void) {
|
||||
if !Reachability.isConnectedToNetwork() {
|
||||
completionHandler(nil, "No internet connection")
|
||||
return
|
||||
}
|
||||
|
||||
fetchLastVersion() { result, error in
|
||||
guard error == nil else {
|
||||
completionHandler(nil, error)
|
||||
return
|
||||
}
|
||||
|
||||
guard let results = result, results.count > 1 else {
|
||||
completionHandler(nil, "wrong results")
|
||||
return
|
||||
}
|
||||
|
||||
let downloadURL: String = result![1]
|
||||
let lastVersion: String = result![0]
|
||||
let newVersion: Bool = self.checkIfNewer(current: self.currentVersion, latest: lastVersion)
|
||||
|
||||
completionHandler(version(current: self.currentVersion, latest: lastVersion, newest: newVersion, url: downloadURL), nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// https://stackoverflow.com/questions/30743408/check-for-internet-connection-with-swift
|
||||
public class Reachability {
|
||||
class func isConnectedToNetwork() -> Bool {
|
||||
var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
|
||||
zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
|
||||
zeroAddress.sin_family = sa_family_t(AF_INET)
|
||||
|
||||
let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) {
|
||||
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in
|
||||
SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress)
|
||||
}
|
||||
}
|
||||
|
||||
var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)
|
||||
if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false {
|
||||
return false
|
||||
}
|
||||
|
||||
/* Only Working for WIFI
|
||||
let isReachable = flags == .reachable
|
||||
let needsConnection = flags == .connectionRequired
|
||||
|
||||
return isReachable && !needsConnection
|
||||
*/
|
||||
|
||||
// Working for Cellular and WIFI
|
||||
let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0
|
||||
let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
|
||||
let ret = (isReachable && !needsConnection)
|
||||
|
||||
return ret
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user