Feature: Adjust status bar position

This commit is contained in:
yicheng 2018-08-07 23:01:03 +08:00
parent b1b43a0f11
commit a33a0f7d86
3 changed files with 13 additions and 7 deletions

View File

@ -45,7 +45,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.updateProxyList()
}
setupData()
// os_log(<#T##message: StaticString##StaticString#>, <#T##args: CVarArg...##CVarArg#>)
}
@ -68,7 +67,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
.showNetSpeedIndicatorObservable
.bind {[unowned self] (show) in
self.showNetSpeedIndicatorMenuItem.state = (show ?? true) ? .on : .off
self.statusItem = NSStatusBar.system.statusItem(withLength: (show ?? true) ? 57 : 22)
self.statusItem = NSStatusBar.system.statusItem(withLength: (show ?? true) ? 65 : 25)
self.statusItem.view = self.statusItemView
self.statusItemView.showSpeedContainer(show: (show ?? true))
self.statusItemView.statusItem = self.statusItem

View File

@ -20,6 +20,7 @@ class StatusItemView: NSView {
@IBOutlet weak var speedContainerView: NSView!
weak var statusItem:NSStatusItem?
var disposeBag = DisposeBag()
var isDarkMode = false
var onPopUpMenuAction:(()->())? = nil
@ -43,6 +44,7 @@ class StatusItemView: NSView {
let darkMode = (value ?? "Light") == "Dark"
let image = NSImage(named: NSImage.Name(rawValue: "menu_icon"))!.tint(color: darkMode ? NSColor.white : NSColor.black)
self.imageView.image = image
self.isDarkMode = darkMode
}.disposed(by: disposeBag)
}
@ -96,5 +98,10 @@ extension StatusItemView:NSMenuDelegate {
statusItem?.drawStatusBarBackground(in: self.bounds, withHighlight: highlight)
image.unlockFocus()
self.layer?.contents = image
if !self.isDarkMode {
self.uploadSpeedLabel.textColor = highlight ? NSColor.white : NSColor.black
self.downloadSpeedLabel.textColor = highlight ? NSColor.white : NSColor.black
}
}
}

View File

@ -15,7 +15,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="7SZ-08-T0A">
<rect key="frame" x="0.0" y="2" width="18" height="18"/>
<rect key="frame" x="3" y="2" width="18" height="18"/>
<constraints>
<constraint firstAttribute="width" constant="18" id="2lK-hJ-kRz"/>
<constraint firstAttribute="width" secondItem="7SZ-08-T0A" secondAttribute="height" multiplier="1:1" id="SFy-Pa-ZDj"/>
@ -23,7 +23,7 @@
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="menu_icon" id="Hsk-Wu-8gc"/>
</imageView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="x4I-nn-92U">
<rect key="frame" x="26" y="0.0" width="31" height="22"/>
<rect key="frame" x="23" y="0.0" width="31" height="22"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Hlw-Vg-wLD">
<rect key="frame" x="-2" y="1" width="35" height="11"/>
@ -54,10 +54,10 @@
</subviews>
<constraints>
<constraint firstItem="x4I-nn-92U" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="75I-1m-KLi"/>
<constraint firstAttribute="trailing" secondItem="x4I-nn-92U" secondAttribute="trailing" id="QUu-S7-d1r"/>
<constraint firstAttribute="trailing" secondItem="x4I-nn-92U" secondAttribute="trailing" constant="3" id="QUu-S7-d1r"/>
<constraint firstItem="7SZ-08-T0A" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="YW6-Cv-OQs"/>
<constraint firstAttribute="bottom" secondItem="x4I-nn-92U" secondAttribute="bottom" id="mZu-Sw-ZNJ"/>
<constraint firstItem="7SZ-08-T0A" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="uUH-eW-Jyi"/>
<constraint firstItem="7SZ-08-T0A" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" constant="3" id="uUH-eW-Jyi"/>
<constraint firstItem="x4I-nn-92U" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="yw8-7n-aCe"/>
</constraints>
<connections>
@ -70,6 +70,6 @@
</customView>
</objects>
<resources>
<image name="menu_icon" width="18" height="18"/>
<image name="menu_icon" width="16" height="16"/>
</resources>
</document>