Skip to content

Commit

Permalink
Do not return focus if new window is shown while popup is visible
Browse files Browse the repository at this point in the history
In rare case the Sparkle window can be shown while popup is visible and
Maccy would hide it upon closing. This prevents user from being able to
update Maccy.

It's tricky to reproduce:
1. Open Maccy.
2. Open Preferences.
3. Click "Check now".
4. Close Prefrences.
5. Minize the uppdate window.
6. Un-minimize the update window.
7. Popup Maccy.
8. Un-popup Maccy.
9. Observe that when Maccy hides, the update window hides too.

Fixes #371
  • Loading branch information
p0deje committed Feb 12, 2022
1 parent 69806f4 commit 5e9a41e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Maccy/Maccy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ class Maccy: NSObject {
// and fallback to default NSMenu behavior by enabling
// UserDefaults.standard.avoidTakingFocus.
private func withFocus(_ closure: @escaping () -> Void) {
Maccy.returnFocusToPreviousApp = extraVisibleWindows.count == 0
KeyboardShortcuts.disable(.popup)

if UserDefaults.standard.avoidTakingFocus {
Expand All @@ -317,8 +316,9 @@ class Maccy: NSObject {
Timer.scheduledTimer(withTimeInterval: 0.04, repeats: false) { _ in
closure()
KeyboardShortcuts.enable(.popup)
if Maccy.returnFocusToPreviousApp {
if Maccy.returnFocusToPreviousApp && self.extraVisibleWindows.count == 0 {
NSApp.hide(self)
Maccy.returnFocusToPreviousApp = true
}
}
}
Expand Down

0 comments on commit 5e9a41e

Please sign in to comment.