Ariver
2026-05-19 099cd85c325a605e0d6606817174bf99ea88c351
Apptag/ApptagApp.swift
@@ -29,6 +29,9 @@
final class AppDelegate: NSObject, NSApplicationDelegate {
    private static let showDockIconKey = "showDockIcon"
    private static let statusItemAutosaveName = "com.apptag.launcher.statusItem"
    private static let statusItemButtonIdentifier = NSUserInterfaceItemIdentifier("TagLauncherStatusItemButton")
    private static let statusItemAccessibilityLabel = "TagLauncher"
    private static let showAppListMenuItemIdentifier = NSUserInterfaceItemIdentifier("TagLauncherShowAppListMenuItem")
    private static let showAppListShortcutGlyphs = "⌥⇧␣"
    private static let overlayDefaultLevel = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.maximumWindow)))
@@ -192,12 +195,19 @@
    // MARK: - Menu Bar
    private func setupMenuBar() {
        removeMenuBarItem()
        statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
        if statusItem == nil {
            statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
        } else {
            statusItem?.length = NSStatusItem.squareLength
        }
        guard let statusItem else { return }
        statusItem.autosaveName = Self.statusItemAutosaveName
        statusItem.isVisible = true
        if let button = statusItem.button {
            button.identifier = Self.statusItemButtonIdentifier
            button.setAccessibilityIdentifier(Self.statusItemAutosaveName)
            button.setAccessibilityLabel(Self.statusItemAccessibilityLabel)
            button.image = makeMenuBarIcon()
            button.imageScaling = .scaleProportionallyDown
            button.imagePosition = .imageOnly
@@ -576,6 +586,7 @@
        }
        overlayWindow?.orderOut(nil)
        removeOverlayKeyMonitor()
        NotificationCenter.default.post(name: .tagLauncherOverlayDidHide, object: nil)
        if force {
            overlayWindow = nil
        }
@@ -826,15 +837,25 @@
final class DismissibleHostingView<Content: View>: NSHostingView<Content> {
    private let onBackdropTap: () -> Void
    private var suppressBackdropDismiss = false
    private var modalInteractionObserver: NSObjectProtocol?
    @MainActor required init(rootView: Content) {
        self.onBackdropTap = {}
        super.init(rootView: rootView)
        observeModalInteractionChanges()
    }
    init(rootView: Content, onBackdropTap: @escaping () -> Void) {
        self.onBackdropTap = onBackdropTap
        super.init(rootView: rootView)
        observeModalInteractionChanges()
    }
    deinit {
        if let modalInteractionObserver {
            NotificationCenter.default.removeObserver(modalInteractionObserver)
        }
    }
    @available(*, unavailable)
@@ -847,6 +868,10 @@
            return
        }
        if hit == self {
            if suppressBackdropDismiss {
                super.mouseDown(with: event)
                return
            }
            onBackdropTap()
            return
        }
@@ -869,6 +894,16 @@
        super.mouseDown(with: event)
    }
    private func observeModalInteractionChanges() {
        modalInteractionObserver = NotificationCenter.default.addObserver(
            forName: .tagLauncherModalInteractionChanged,
            object: nil,
            queue: .main
        ) { [weak self] notification in
            self?.suppressBackdropDismiss = (notification.userInfo?["active"] as? Bool) ?? false
        }
    }
    private func findTextFieldContainer(in view: NSView) -> TextFieldContainer? {
        if let container = view as? TextFieldContainer { return container }
        for sub in view.subviews {