From 6ad586d446775a1554e220dba0bba415c9f49711 Mon Sep 17 00:00:00 2001 From: yicheng <11733500+yichengchen@users.noreply.github.com> Date: Sat, 22 Feb 2020 14:26:15 +0800 Subject: [PATCH] fix(speedtest): try to fix speedtest button click issue --- ClashX/Views/MenuItemBaseView.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ClashX/Views/MenuItemBaseView.swift b/ClashX/Views/MenuItemBaseView.swift index fed056b..5a521fd 100644 --- a/ClashX/Views/MenuItemBaseView.swift +++ b/ClashX/Views/MenuItemBaseView.swift @@ -86,6 +86,14 @@ class MenuItemBaseView: NSView { labels.forEach { updateBackground($0) } } + override func viewWillMove(toWindow newWindow: NSWindow?) { + super.viewWillMove(toWindow: newWindow) + if let newWindow = newWindow,!newWindow.isKeyWindow { + newWindow.becomeKey() + } + updateTrackingAreas() + } + override func viewDidMoveToWindow() { super.viewDidMoveToWindow() } @@ -101,7 +109,9 @@ class MenuItemBaseView: NSView { } override func mouseUp(with event: NSEvent) { - didClickView() + DispatchQueue.main.async { + self.didClickView() + } } override func updateTrackingAreas() {