README update; small fix in battery module; new menubar view layout;

This commit is contained in:
Serhiy Mytrovtsiy
2019-06-17 12:45:15 +02:00
parent ba93aa68aa
commit ba176ef87d
7 changed files with 39 additions and 35 deletions

View File

@@ -111,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 && 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)
}
}

View File

@@ -33,7 +33,7 @@ class BatteryReader: Reader {
updateTimer.invalidate()
updateTimer = nil
}
@objc func read() {
let psInfo = IOPSCopyPowerSourcesInfo().takeRetainedValue()
let psList = IOPSCopyPowerSourcesList(psInfo).takeRetainedValue() as [CFTypeRef]
@@ -41,10 +41,11 @@ class BatteryReader: Reader {
for ps in psList {
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
let isCharging = (psDesc[kIOPSIsChargingKey] as? Bool)
let powerSourceState = (psDesc[kIOPSPowerSourceStateKey] as? String)
let isCharged = (psDesc[kIOPSIsChargedKey] as? Bool)
var cap: Float = Float(psDesc[kIOPSCurrentCapacityKey] as! Int) / 100
if !isCharging! {
if isCharged == nil && powerSourceState! == "Battery Power" {
cap = 0 - cap
}

View File

@@ -1,8 +1,8 @@
<?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" initialViewController="QiE-cC-2Ak">
<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="14460.31"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@@ -67,8 +67,8 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="GVE-z9-HI2">
<rect key="frame" x="-2" y="0.0" width="80" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Version 1.0.0" id="Nkt-Z9-Av0">
<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"/>
@@ -85,8 +85,8 @@
</customSpacing>
</stackView>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="hXC-tE-nSc">
<rect key="frame" x="-2" y="41" width="253" height="34"/>
<textFieldCell key="cell" title="Application for macos that shows CPU, Memory and Disk usage on the menu bar." id="w6j-75-PxU">
<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"/>
@@ -174,7 +174,7 @@
</viewController>
<customObject id="orR-wl-rJd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-163" y="434"/>
<point key="canvasLocation" x="-163" y="400"/>
</scene>
</scenes>
<resources>

View File

@@ -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>

View File

@@ -48,6 +48,9 @@ extension Float {
}
return NSColor.systemOrange
case 0.4...1:
if self == 1 {
return NSColor.controlTextColor
}
if !colors.value {
return NSColor.controlTextColor
}