From b7f869facbb64b6415a31af0b5c46b5b3df14800 Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Fri, 29 May 2026 05:23:24 +0800
Subject: [PATCH] Extract app library refresh pipeline
---
Apptag/ContentView.swift | 84 +++++++++++++++++++-----------------------
1 files changed, 38 insertions(+), 46 deletions(-)
diff --git a/Apptag/ContentView.swift b/Apptag/ContentView.swift
index da98d57..033efcc 100644
--- a/Apptag/ContentView.swift
+++ b/Apptag/ContentView.swift
@@ -664,7 +664,7 @@
}
.zIndex(899)
- QuickSearchOverlayView(
+ QuickSearchPanelPresentationView(
query: $quickSearchQuery,
results: quickSearchResults,
selectedID: quickSearchSelectedID,
@@ -672,16 +672,15 @@
selectionScrollToken: quickSearchSelectionScrollToken,
isLoading: quickSearchDocuments.isEmpty && refreshInProgress,
maxVisibleRows: quickSearchMaxVisibleRows(in: proxy.size),
+ panelTopY: quickSearchPanelTopY(in: proxy.size),
+ panelHeight: quickSearchPanelContentHeight(in: proxy.size),
errorMessage: quickSearchErrorMessage,
onCommand: handleQuickSearchCommand,
onHover: selectQuickSearchResult,
onLaunch: launchQuickSearchResult
)
- .position(
- x: proxy.size.width / 2,
- y: quickSearchPanelCenterY(in: proxy.size)
- )
- .transition(.scale(scale: 0.98).combined(with: .opacity))
+ .frame(width: 0, height: 0)
+ .allowsHitTesting(false)
.zIndex(900)
}
}
@@ -689,10 +688,15 @@
.animation(.easeOut(duration: 0.12), value: quickSearchVisible)
}
- private func quickSearchPanelCenterY(in size: CGSize) -> CGFloat {
- let visibleRows = max(1, min(quickSearchResults.isEmpty ? 1 : quickSearchResults.count, quickSearchMaxVisibleRows(in: size)))
- let estimatedPanelHeight = CGFloat(visibleRows) * 76 + 122
- return quickSearchPanelTopY(in: size) + estimatedPanelHeight / 2
+ private func quickSearchPanelContentHeight(in size: CGSize) -> CGFloat {
+ let hasResultList = !(quickSearchDocuments.isEmpty && refreshInProgress)
+ && quickSearchErrorMessage == nil
+ && !quickSearchResults.isEmpty
+ let visibleRows = min(max(1, quickSearchResults.count), quickSearchMaxVisibleRows(in: size))
+ return QuickSearchPanelMetrics.contentHeight(
+ hasResultList: hasResultList,
+ visibleRows: visibleRows
+ )
}
private func quickSearchPanelTopY(in size: CGSize) -> CGFloat {
@@ -701,8 +705,11 @@
private func quickSearchMaxVisibleRows(in size: CGSize) -> Int {
let bottomClearance: CGFloat = 84
- let chromeHeight: CGFloat = 122
- let rowHeightWithSpacing: CGFloat = 76
+ let chromeHeight = QuickSearchPanelMetrics.headerHeight
+ + QuickSearchPanelMetrics.dividerHeight
+ + QuickSearchPanelMetrics.resultListVerticalInset * 2
+ let rowHeightWithSpacing = QuickSearchPanelMetrics.rowHeight
+ + QuickSearchPanelMetrics.rowSpacing
let availableHeight = max(0, size.height - quickSearchPanelTopY(in: size) - bottomClearance - chromeHeight)
return max(1, min(8, Int(floor(availableHeight / rowHeightWithSpacing))))
}
@@ -1695,23 +1702,14 @@
let scannedApps = allApps
DispatchQueue.global(qos: .userInitiated).async {
- let result = SmartStartService.applySuggestion(draft)
- let store = result.store
- let apps = TagEditor.annotate(apps: scannedApps, store: store)
- let quickSearchDocs = QuickSearchEngine.makeDocuments(apps: apps, store: store)
- let colors = store.tags.mapValues { $0.color }
- let order = TagEditor.orderedTagNames()
+ let result = AppLibraryController.applySmartStartSuggestion(
+ draft,
+ scannedApps: scannedApps
+ )
DispatchQueue.main.async {
pendingSmartStartDraft = nil
- allApps = apps
- quickSearchDocuments = quickSearchDocs
- tagColors = colors
- draggedTagNames = order
- rebuildDisplayGroups(apps: apps, tagOrder: order)
- if quickSearchVisible {
- refreshQuickSearchResults()
- }
+ applyAppLibrarySnapshot(result.snapshot)
if let summary = result.summary {
showSmartStartNotice(mode: .manuallyApplied, summary: summary)
} else {
@@ -2363,27 +2361,10 @@
refreshInProgress = true
DispatchQueue.global(qos: .userInitiated).async {
- let scannedApps = AppIndexer.scan()
- let reconciledStore = TagEditor.reconcileScannedApps(scannedApps)
- let smartStartResult = SmartStartService.runIfNeeded(
- apps: scannedApps,
- store: reconciledStore
- )
- let store = smartStartResult.store
- let apps = TagEditor.annotate(apps: scannedApps, store: store)
- let quickSearchDocs = QuickSearchEngine.makeDocuments(apps: apps, store: store)
- let colors = store.tags.mapValues { $0.color }
- let order = TagEditor.orderedTagNames()
+ let result = AppLibraryController.refresh()
DispatchQueue.main.async {
- allApps = apps
- quickSearchDocuments = quickSearchDocs
- tagColors = colors
- draggedTagNames = order
- rebuildDisplayGroups(apps: apps, tagOrder: order)
- if quickSearchVisible {
- refreshQuickSearchResults()
- }
- handleSmartStartRunResult(smartStartResult)
+ applyAppLibrarySnapshot(result.snapshot)
+ handleSmartStartRunResult(result.smartStartResult)
if forceLayoutRefresh {
finishDropRefreshAfterMinimumDuration()
}
@@ -2398,6 +2379,17 @@
}
}
+ private func applyAppLibrarySnapshot(_ snapshot: AppLibrarySnapshot) {
+ allApps = snapshot.apps
+ quickSearchDocuments = snapshot.quickSearchDocuments
+ tagColors = snapshot.tagColors
+ draggedTagNames = snapshot.tagOrder
+ rebuildDisplayGroups(apps: snapshot.apps, tagOrder: snapshot.tagOrder)
+ if quickSearchVisible {
+ refreshQuickSearchResults()
+ }
+ }
+
private func launchApp(
_ app: AppInfo,
closeQuickSearchOnSuccess: Bool = false,
--
Gitblit v1.9.3