From c54cc2d62b1c6f648dbba9a77579e2d196ed11d8 Mon Sep 17 00:00:00 2001 From: yichengchen Date: Mon, 8 Oct 2018 23:08:08 +0800 Subject: [PATCH] Imporve network indicator switch effect. slove issue #34 --- ClashX/AppDelegate.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ClashX/AppDelegate.swift b/ClashX/AppDelegate.swift index 5b267be..3e4a6d4 100644 --- a/ClashX/AppDelegate.swift +++ b/ClashX/AppDelegate.swift @@ -83,7 +83,11 @@ 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) ? 65 : 25) + let statusItemLength:CGFloat = (show ?? true) ? 65 : 25 + if (self.statusItem == nil) { + self.statusItem = NSStatusBar.system.statusItem(withLength: statusItemLength) + } + self.statusItem.length = statusItemLength self.statusItem.view = self.statusItemView self.statusItemView.showSpeedContainer(show: (show ?? true)) self.statusItemView.statusItem = self.statusItem @@ -389,7 +393,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } @IBAction func actionShowNetSpeedIndicator(_ sender: NSMenuItem) { - ConfigManager.shared.showNetSpeedIndicator = !ConfigManager.shared.showNetSpeedIndicator + ConfigManager.shared.showNetSpeedIndicator = !(sender.state == .on) } @IBAction func actionShowLog(_ sender: Any) {