Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/Pesty/Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ final class Settings {
static let quickPasteModifier = "quickPasteModifier"
static let plainTextModifier = "plainTextModifier"
static let launchAtLogin = "launchAtLogin"
static let hideOnClickOutside = "hideOnClickOutside"
static let pasteDirectly = "pasteDirectly"
static let playSound = "playSound"
static let ignoreConcealed = "ignoreConcealed"
Expand Down Expand Up @@ -111,6 +112,10 @@ final class Settings {
d.set(launchAtLogin, forKey: Keys.launchAtLogin); LaunchAtLogin.set(enabled: launchAtLogin) }
}

var hideOnClickOutside: Bool {
didSet { guard isLoaded else { return }; d.set(hideOnClickOutside, forKey: Keys.hideOnClickOutside) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply auto-hide immediately when it is enabled

When the preference is changed from off to on while the bar is already visible behind the Settings window, this setter only persists the value. The panel lost key status while the option was still off, so windowDidResignKey has already returned without hiding it; subsequent clicks in other apps produce no new resignation event, leaving the bar visible despite the enabled setting until the user focuses or toggles it again. Reconcile the currently presented panel when enabling this option.

Useful? React with 👍 / 👎.

}

var pasteDirectly: Bool {
didSet { guard isLoaded else { return }; d.set(pasteDirectly, forKey: Keys.pasteDirectly) }
}
Expand Down Expand Up @@ -167,6 +172,7 @@ final class Settings {
Keys.quickPasteModifier: cmdKey,
Keys.plainTextModifier: shiftKey,
Keys.launchAtLogin: false,
Keys.hideOnClickOutside: true,
Keys.pasteDirectly: true,
Keys.playSound: false,
Keys.ignoreConcealed: true,
Expand All @@ -183,6 +189,7 @@ final class Settings {
quickPasteModifier = d.integer(forKey: Keys.quickPasteModifier)
plainTextModifier = d.integer(forKey: Keys.plainTextModifier)
launchAtLogin = d.bool(forKey: Keys.launchAtLogin)
hideOnClickOutside = d.bool(forKey: Keys.hideOnClickOutside)
pasteDirectly = d.bool(forKey: Keys.pasteDirectly)
playSound = d.bool(forKey: Keys.playSound)
ignoreConcealed = d.bool(forKey: Keys.ignoreConcealed)
Expand Down
1 change: 1 addition & 0 deletions Sources/Pesty/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ private struct GeneralSettings: View {
#endif
Toggle("Ignore passwords (concealed clips)", isOn: $settings.ignoreConcealed)
Toggle("Play sound on paste", isOn: $settings.playSound)
Toggle("Hide Pesty when clicking outside", isOn: $settings.hideOnClickOutside)
Toggle("Launch at login", isOn: $settings.launchAtLogin)
Toggle("Show Pesty in the menu bar", isOn: $settings.showMenuBarIcon)
VStack(alignment: .leading) {
Expand Down
8 changes: 6 additions & 2 deletions Sources/Pesty/UI/BarWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ final class BarWindowController: NSWindowController, NSWindowDelegate {
func show() {
guard let panel = window else { return }
guard let screen = Self.targetScreen() else { return }
panel.level = Settings.shared.hideOnClickOutside ? .modalPanel : .floating
let vf = screen.visibleFrame
let height = min(CGFloat(Settings.shared.barHeight), vf.height)
let onScreen = NSRect(x: vf.minX, y: vf.minY, width: vf.width, height: height)
Expand Down Expand Up @@ -174,7 +175,8 @@ final class BarWindowController: NSWindowController, NSWindowDelegate {
// The panel can lose key focus while it is still animating up, and
// windowDidResignKey ignores that because the bar is not .shown yet.
// Catch it here so the bar does not sit on screen unfocused forever.
if panel.isVisible, !panel.isKeyWindow, !AppController.shared.suppressAutoHide {
if Settings.shared.hideOnClickOutside,
panel.isVisible, !panel.isKeyWindow, !AppController.shared.suppressAutoHide {
AppController.shared.hideBar()
}
}
Expand Down Expand Up @@ -222,7 +224,9 @@ final class BarWindowController: NSWindowController, NSWindowDelegate {
}

func windowDidResignKey(_ notification: Notification) {
guard phase == .shown, !AppController.shared.suppressAutoHide else { return }
guard Settings.shared.hideOnClickOutside,
phase == .shown,
!AppController.shared.suppressAutoHide else { return }
AppController.shared.hideBar()
}
}
Loading