From d499b9d020f87e74d72b2200b8db64d2efc86ff1 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Sat, 31 Jul 2021 15:39:46 +0200 Subject: [PATCH] fix: fixed popup view behavior when pinned. Now a pinned popup will not close if click on the settings window. Additionally fixed bug when popup view does not hide if previously was pinned and closed. --- Kit/module/module.swift | 2 +- Kit/module/popup.swift | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Kit/module/module.swift b/Kit/module/module.swift index b0e7ae86..d0cf6ebc 100644 --- a/Kit/module/module.swift +++ b/Kit/module/module.swift @@ -293,7 +293,7 @@ open class Module: Module_p { } @objc private func listenForMouseDownInSettings(_ notification: Notification) { - if let popup = self.popup, popup.isVisible { + if let popup = self.popup, popup.isVisible && !popup.locked { self.popup?.setIsVisible(false) } } diff --git a/Kit/module/popup.swift b/Kit/module/popup.swift index 0c56f223..7ecc0faa 100644 --- a/Kit/module/popup.swift +++ b/Kit/module/popup.swift @@ -21,7 +21,6 @@ internal class PopupWindow: NSWindow, NSWindowDelegate { init(title: String, view: Popup_p?, visibilityCallback: @escaping (_ state: Bool) -> Void) { self.viewController.setup(title: title, view: view) - self.viewController.visibilityCallback = visibilityCallback super.init( contentRect: NSRect( @@ -35,6 +34,11 @@ internal class PopupWindow: NSWindow, NSWindowDelegate { defer: true ) + self.viewController.visibilityCallback = { [weak self] state in + self?.locked = false + visibilityCallback(state) + } + self.contentViewController = self.viewController self.titlebarAppearsTransparent = true self.animationBehavior = .default @@ -315,11 +319,6 @@ internal class HeaderView: NSStackView { @objc func openActivityMonitor(_ sender: Any) { self.window?.setIsVisible(false) - if self.isCloseAction { - self.setCloseButton(false) - return - } - NSWorkspace.shared.launchApplication( withBundleIdentifier: "com.apple.ActivityMonitor", options: [.default], @@ -333,14 +332,22 @@ internal class HeaderView: NSStackView { NotificationCenter.default.post(name: .toggleSettings, object: nil, userInfo: ["module": self.title]) } + @objc private func closePopup() { + self.window?.setIsVisible(false) + self.setCloseButton(false) + return + } + public func setCloseButton(_ state: Bool) { if state && !self.isCloseAction { self.activityButton?.image = Bundle(for: type(of: self)).image(forResource: "close")! self.activityButton?.toolTip = localizedString("Close popup") + self.activityButton?.action = #selector(self.closePopup) self.isCloseAction = true } else if !state && self.isCloseAction { self.activityButton?.image = Bundle(for: type(of: self)).image(forResource: "chart")! self.activityButton?.toolTip = localizedString("Open Activity Monitor") + self.activityButton?.action = #selector(self.openActivityMonitor) self.isCloseAction = false } }