| | |
| | | @State private var refreshInProgress = false |
| | | @State private var refreshAgainAfterCurrent = false |
| | | @State private var refreshAgainForceLayout = false |
| | | @State private var refreshAgainUseCache = true |
| | | @FocusState private var bubbleNoteFocused: Bool |
| | | |
| | | // Quick Search |
| | |
| | | @State private var quickSearchSelectionScrollToken = 0 |
| | | @State private var quickSearchCloseHidesOverlay = false |
| | | @State private var quickSearchOnlySession = false |
| | | @State private var quickSearchOpenedAt: Date? = nil |
| | | @State private var quickSearchErrorMessage: String? = nil |
| | | @State private var initialQuickSearchConsumed = false |
| | | |
| | |
| | | } |
| | | .onAppear { |
| | | refreshNotchHeight() |
| | | refreshAppsIfNeeded() |
| | | refreshAppsForOverlay() |
| | | if let initialQuickSearchSource, !initialQuickSearchConsumed { |
| | | initialQuickSearchConsumed = true |
| | | if initialQuickSearchSource == QuickSearchOpenSource.globalHidden { |
| | |
| | | quickSearchVisible = true |
| | | quickSearchFocusToken &+= 1 |
| | | } |
| | | quickSearchOpenedAt = Date() |
| | | refreshQuickSearchResults() |
| | | refreshAppsForQuickSearch() |
| | | NotificationCenter.default.post( |
| | | name: .tagLauncherQuickSearchVisibilityChanged, |
| | | object: nil, |
| | |
| | | .onReceive(NotificationCenter.default.publisher(for: .tagLauncherOverlayDidShow)) { _ in |
| | | resetTransientDragState() |
| | | refreshNotchHeight() |
| | | refreshAppsIfNeeded() |
| | | refreshAppsForOverlay() |
| | | } |
| | | .onReceive(NotificationCenter.default.publisher(for: .tagLauncherOverlayDidHide)) { _ in |
| | | resetTransientDragState() |
| | |
| | | let source = notification.userInfo?["source"] as? String ?? QuickSearchOpenSource.mainOverlay |
| | | openQuickSearch(source: source) |
| | | } |
| | | .onReceive(NotificationCenter.default.publisher(for: .tagLauncherQuickSearchDismissRequested)) { _ in |
| | | closeQuickSearch() |
| | | .onReceive(NotificationCenter.default.publisher(for: .tagLauncherQuickSearchDismissRequested)) { notification in |
| | | let source = notification.userInfo?["source"] as? String |
| | | closeQuickSearch(dismissalSource: source) |
| | | } |
| | | .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in |
| | | guard allApps.isEmpty, !refreshInProgress else { return } |
| | |
| | | .onReceive(NotificationCenter.default.publisher(for: .appLanguageDidChange)) { _ in |
| | | let appsSnapshot = allApps |
| | | DispatchQueue.global(qos: .userInitiated).async { |
| | | _ = AppleDefaultAppCatalog.relocalizeDefaultNotesForCurrentLanguage(apps: appsSnapshot) |
| | | _ = SmartStartService.relocalizeDefaultNotesForCurrentLanguage(apps: appsSnapshot) |
| | | DispatchQueue.main.async { |
| | | refreshApps(forceLayoutRefresh: true) |
| | |
| | | .ignoresSafeArea() |
| | | .contentShape(Rectangle()) |
| | | .onTapGesture { |
| | | closeQuickSearch() |
| | | closeQuickSearch(dismissalSource: QuickSearchDismissSource.backdrop) |
| | | } |
| | | .zIndex(899) |
| | | |
| | |
| | | selectedID: quickSearchSelectedID, |
| | | focusToken: quickSearchFocusToken, |
| | | selectionScrollToken: quickSearchSelectionScrollToken, |
| | | isLoading: quickSearchDocuments.isEmpty && refreshInProgress, |
| | | isLoading: quickSearchShouldShowLoading, |
| | | maxVisibleRows: quickSearchMaxVisibleRows(in: proxy.size), |
| | | panelTopY: quickSearchPanelTopY(in: proxy.size), |
| | | panelHeight: quickSearchPanelContentHeight(in: proxy.size), |
| | |
| | | } |
| | | |
| | | private func quickSearchPanelContentHeight(in size: CGSize) -> CGFloat { |
| | | let hasResultList = !(quickSearchDocuments.isEmpty && refreshInProgress) |
| | | let hasResultList = !quickSearchShouldShowLoading |
| | | && quickSearchErrorMessage == nil |
| | | && !quickSearchResults.isEmpty |
| | | let visibleRows = min(max(1, quickSearchResults.count), quickSearchMaxVisibleRows(in: size)) |
| | |
| | | quickSearchCloseHidesOverlay = quickSearchCloseHidesOverlay |
| | | || source == QuickSearchOpenSource.globalHidden |
| | | quickSearchVisible = true |
| | | quickSearchOpenedAt = Date() |
| | | quickSearchQuery = "" |
| | | quickSearchManualSelection = false |
| | | quickSearchErrorMessage = nil |
| | | quickSearchFocusToken &+= 1 |
| | | refreshQuickSearchResults() |
| | | refreshAppsForQuickSearch() |
| | | NotificationCenter.default.post( |
| | | name: .tagLauncherQuickSearchVisibilityChanged, |
| | | object: nil, |
| | |
| | | && !quickSearchVisible |
| | | } |
| | | |
| | | private func closeQuickSearch(notify: Bool = true, hideOverlayIfNeeded: Bool = true) { |
| | | private var quickSearchShouldShowLoading: Bool { |
| | | quickSearchVisible && refreshInProgress && quickSearchResults.isEmpty |
| | | } |
| | | |
| | | private func closeQuickSearch( |
| | | notify: Bool = true, |
| | | hideOverlayIfNeeded: Bool = true, |
| | | dismissalSource: String? = nil |
| | | ) { |
| | | Diagnostics.log("content.quickSearch.closeRequest", [ |
| | | "source": dismissalSource, |
| | | "notify": notify, |
| | | "hideOverlayIfNeeded": hideOverlayIfNeeded, |
| | | "quickSearchVisible": quickSearchVisible, |
| | | "quickSearchCloseHidesOverlay": quickSearchCloseHidesOverlay, |
| | | "quickSearchOnlySession": quickSearchOnlySession |
| | | ]) |
| | | if shouldIgnoreEarlyQuickSearchDismiss(from: dismissalSource) { |
| | | return |
| | | } |
| | | let shouldHideOverlay = quickSearchVisible && quickSearchCloseHidesOverlay && hideOverlayIfNeeded |
| | | guard quickSearchVisible else { return } |
| | | quickSearchVisible = false |
| | | quickSearchOpenedAt = nil |
| | | quickSearchQuery = "" |
| | | quickSearchResults = [] |
| | | quickSearchSelectedID = nil |
| | |
| | | } |
| | | } |
| | | |
| | | private func shouldIgnoreEarlyQuickSearchDismiss(from source: String?) -> Bool { |
| | | guard quickSearchVisible, |
| | | let quickSearchOpenedAt, |
| | | source == QuickSearchDismissSource.mouse || source == QuickSearchDismissSource.backdrop |
| | | else { return false } |
| | | |
| | | let age = Date().timeIntervalSince(quickSearchOpenedAt) |
| | | let gracePeriod: TimeInterval = quickSearchOnlySession ? 1.25 : 0.30 |
| | | guard age < gracePeriod else { return false } |
| | | Diagnostics.log("content.quickSearch.ignoredEarlyDismiss", [ |
| | | "source": source, |
| | | "age": String(format: "%.3f", age), |
| | | "gracePeriod": String(format: "%.2f", gracePeriod) |
| | | ]) |
| | | return true |
| | | } |
| | | |
| | | private func refreshQuickSearchResults() { |
| | | let previousSelection = quickSearchSelectedID |
| | | quickSearchResults = QuickSearchEngine.search(quickSearchQuery, documents: quickSearchDocuments) |
| | | quickSearchResults = QuickSearchEngine.search( |
| | | quickSearchQuery, |
| | | documents: quickSearchDocuments.filter { FileManager.default.fileExists(atPath: $0.app.path.path) } |
| | | ) |
| | | |
| | | if quickSearchResults.isEmpty { |
| | | quickSearchSelectedID = nil |
| | |
| | | } |
| | | |
| | | private func handleQuickSearchCommand(_ command: QuickSearchCommand) { |
| | | Diagnostics.log("content.quickSearch.command", [ |
| | | "command": String(describing: command), |
| | | "quickSearchCloseHidesOverlay": quickSearchCloseHidesOverlay, |
| | | "quickSearchOnlySession": quickSearchOnlySession |
| | | ]) |
| | | switch command { |
| | | case .moveUp: |
| | | moveQuickSearchSelection(by: -1) |
| | |
| | | refreshApps() |
| | | } |
| | | |
| | | private func refreshAppsForOverlay() { |
| | | // Each overlay show creates a fresh ContentView with empty `allApps`. The indexer |
| | | // cache may still be warm from a prior overlay/settings scan, so path-signature |
| | | // alone must not skip the first hydrate or the grid spinner never clears. |
| | | guard allApps.isEmpty || AppIndexer.shouldRefreshForSearchPathChanges() else { return } |
| | | refreshApps() |
| | | } |
| | | |
| | | private func refreshAppsForQuickSearch() { |
| | | guard allApps.isEmpty |
| | | || quickSearchDocuments.isEmpty |
| | | || AppIndexer.shouldRefreshForSearchPathChanges() |
| | | else { return } |
| | | refreshApps() |
| | | } |
| | | |
| | | private func refreshNotchHeight() { |
| | | let mousePoint = NSEvent.mouseLocation |
| | | let activeScreen = NSScreen.screens.first(where: { |
| | |
| | | } |
| | | } |
| | | |
| | | func refreshApps(forceLayoutRefresh: Bool = false) { |
| | | func refreshApps(forceLayoutRefresh: Bool = false, useCache: Bool = true) { |
| | | guard !refreshInProgress else { |
| | | if forceLayoutRefresh { |
| | | refreshAgainAfterCurrent = true |
| | | refreshAgainForceLayout = true |
| | | } |
| | | refreshAgainAfterCurrent = true |
| | | refreshAgainForceLayout = refreshAgainForceLayout || forceLayoutRefresh |
| | | refreshAgainUseCache = refreshAgainUseCache && useCache |
| | | return |
| | | } |
| | | |
| | | refreshInProgress = true |
| | | DispatchQueue.global(qos: .userInitiated).async { |
| | | let result = AppLibraryController.refresh() |
| | | let result = AppLibraryController.refresh(useCache: useCache) |
| | | DispatchQueue.main.async { |
| | | applyAppLibrarySnapshot(result.snapshot) |
| | | handleSmartStartRunResult(result.smartStartResult) |
| | |
| | | refreshInProgress = false |
| | | if refreshAgainAfterCurrent { |
| | | let shouldForceLayout = refreshAgainForceLayout |
| | | let shouldUseCache = refreshAgainUseCache |
| | | refreshAgainAfterCurrent = false |
| | | refreshAgainForceLayout = false |
| | | refreshApps(forceLayoutRefresh: shouldForceLayout) |
| | | refreshAgainUseCache = true |
| | | refreshApps(forceLayoutRefresh: shouldForceLayout, useCache: shouldUseCache) |
| | | } |
| | | } |
| | | } |
| | |
| | | ) { |
| | | appGridInteraction.appDragModeActive = false |
| | | endTagNavReorder() |
| | | guard FileManager.default.fileExists(atPath: app.path.path) else { |
| | | AppIndexer.invalidateScanCache() |
| | | refreshApps() |
| | | onFailure?() |
| | | return |
| | | } |
| | | |
| | | let closeQuickSearchAndOverlayBeforeOpening = closeQuickSearchOnSuccess |
| | | && closeOverlayOnSuccess |
| | | && (quickSearchCloseHidesOverlay || quickSearchOnlySession) |