Skip to content

Commit

Permalink
Feature: support menu icon in dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yichengchen committed Aug 7, 2018
1 parent 86e3534 commit b4aa3d8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ClashX/ViewControllers/StatusItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import Foundation
import AppKit
import RxCocoa
import RxSwift

class StatusItemView: NSView {

@IBOutlet var imageView: NSImageView!
Expand All @@ -16,6 +19,7 @@ class StatusItemView: NSView {
@IBOutlet var downloadSpeedLabel: NSTextField!
@IBOutlet weak var speedContainerView: NSView!
weak var statusItem:NSStatusItem?
var disposeBag = DisposeBag()

var onPopUpMenuAction:(()->())? = nil

Expand All @@ -25,12 +29,23 @@ class StatusItemView: NSView {
let view = (topLevelObjects!.first(where: { $0 is NSView }) as? StatusItemView)!
view.statusItem = statusItem
view.menu = statusMenu
view.setupView()
statusMenu.delegate = view
return view
}
return NSView() as! StatusItemView
}

func setupView() {
UserDefaults.standard
.rx.observe(String.self, "AppleInterfaceStyle").bind {
value in
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
}.disposed(by: disposeBag)
}

func updateSpeedLabel(up:Int,down:Int) {
let kbup = up/1024
let kbdown = down/1024
Expand Down

0 comments on commit b4aa3d8

Please sign in to comment.