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 | 53 +++++++++++++++++++----------------------------------
1 files changed, 19 insertions(+), 34 deletions(-)
diff --git a/Apptag/ContentView.swift b/Apptag/ContentView.swift
index 900cf4d..033efcc 100644
--- a/Apptag/ContentView.swift
+++ b/Apptag/ContentView.swift
@@ -1702,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 {
@@ -2370,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()
}
@@ -2405,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