mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-27 15:17:38 +00:00
improve dock icon mgmt
This commit is contained in:
parent
ea4cc0ab84
commit
13fdb57f1b
1 changed files with 26 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import AppKit
|
import AppKit
|
||||||
|
import OSLog
|
||||||
|
|
||||||
/// Centralized manager for dock icon visibility.
|
/// Centralized manager for dock icon visibility.
|
||||||
///
|
///
|
||||||
|
|
@ -12,9 +13,15 @@ final class DockIconManager {
|
||||||
|
|
||||||
private var windowObservers: [NSObjectProtocol] = []
|
private var windowObservers: [NSObjectProtocol] = []
|
||||||
private var activeWindows = Set<NSWindow>()
|
private var activeWindows = Set<NSWindow>()
|
||||||
|
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "VibeTunnel", category: "DockIconManager")
|
||||||
|
|
||||||
private init() {
|
private init() {
|
||||||
setupNotifications()
|
setupNotifications()
|
||||||
|
// Check for any existing windows after a small delay
|
||||||
|
Task { @MainActor in
|
||||||
|
try? await Task.sleep(for: .milliseconds(100))
|
||||||
|
checkExistingWindows()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
|
@ -27,6 +34,7 @@ final class DockIconManager {
|
||||||
/// Register a window to be tracked for dock icon visibility.
|
/// Register a window to be tracked for dock icon visibility.
|
||||||
/// The dock icon will remain visible as long as any registered window is open.
|
/// The dock icon will remain visible as long as any registered window is open.
|
||||||
func trackWindow(_ window: NSWindow) {
|
func trackWindow(_ window: NSWindow) {
|
||||||
|
logger.info("Tracking window: \(window.title, privacy: .public)")
|
||||||
activeWindows.insert(window)
|
activeWindows.insert(window)
|
||||||
updateDockVisibility()
|
updateDockVisibility()
|
||||||
|
|
||||||
|
|
@ -38,7 +46,10 @@ final class DockIconManager {
|
||||||
) { [weak self, weak window] _ in
|
) { [weak self, weak window] _ in
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
guard let self, let window else { return }
|
guard let self, let window else { return }
|
||||||
|
self.logger.info("Window closing: \(window.title, privacy: .public)")
|
||||||
self.activeWindows.remove(window)
|
self.activeWindows.remove(window)
|
||||||
|
// Add a small delay to avoid race conditions with window state changes
|
||||||
|
try? await Task.sleep(for: .milliseconds(100))
|
||||||
self.updateDockVisibility()
|
self.updateDockVisibility()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,10 +63,14 @@ final class DockIconManager {
|
||||||
let userWantsDockHidden = !UserDefaults.standard.bool(forKey: "showInDock")
|
let userWantsDockHidden = !UserDefaults.standard.bool(forKey: "showInDock")
|
||||||
let hasActiveWindows = !activeWindows.isEmpty
|
let hasActiveWindows = !activeWindows.isEmpty
|
||||||
|
|
||||||
|
logger.info("Updating dock visibility - User wants hidden: \(userWantsDockHidden), Active windows: \(self.activeWindows.count)")
|
||||||
|
|
||||||
// Show dock if user wants it shown OR if any windows are open
|
// Show dock if user wants it shown OR if any windows are open
|
||||||
if !userWantsDockHidden || hasActiveWindows {
|
if !userWantsDockHidden || hasActiveWindows {
|
||||||
|
logger.info("Showing dock icon")
|
||||||
NSApp.setActivationPolicy(.regular)
|
NSApp.setActivationPolicy(.regular)
|
||||||
} else {
|
} else {
|
||||||
|
logger.info("Hiding dock icon")
|
||||||
NSApp.setActivationPolicy(.accessory)
|
NSApp.setActivationPolicy(.accessory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -85,4 +100,15 @@ final class DockIconManager {
|
||||||
updateDockVisibility()
|
updateDockVisibility()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check for any existing windows and track them
|
||||||
|
private func checkExistingWindows() {
|
||||||
|
logger.info("Checking for existing windows...")
|
||||||
|
for window in NSApp.windows {
|
||||||
|
if window.isVisible && !window.isKind(of: NSPanel.self) {
|
||||||
|
logger.info("Found existing window: \(window.title, privacy: .public)")
|
||||||
|
trackWindow(window)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue