From 9c317d89a39d0871f15f8282aec6c7f3dde7768c Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Fri, 26 Jun 2026 22:42:44 +0800
Subject: [PATCH] Polish Pro status UI and app grid layout

---
 src/Apptag/AppLibraryController.swift |   51 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/src/Apptag/AppLibraryController.swift b/src/Apptag/AppLibraryController.swift
index aa2d4db..1f45bf6 100644
--- a/src/Apptag/AppLibraryController.swift
+++ b/src/Apptag/AppLibraryController.swift
@@ -5,6 +5,8 @@
     let quickSearchDocuments: [QuickSearchDocument]
     let tagColors: [String: Int]
     let tagOrder: [String]
+    let tagDefinitions: [String: TagDatabase.TagDef]
+    let containerAppOrder: [String: [String]]
 }
 
 struct AppLibraryRefreshResult {
@@ -22,7 +24,20 @@
     let summary: SmartStartSummary?
 }
 
+struct AppLibraryUncategorizedResetResult {
+    let snapshot: AppLibrarySnapshot
+}
+
 enum AppLibraryController {
+    private static let snapshotCacheLock = NSLock()
+    private static var cachedSnapshot: AppLibrarySnapshot?
+
+    static func lastSnapshot() -> AppLibrarySnapshot? {
+        snapshotCacheLock.lock()
+        defer { snapshotCacheLock.unlock() }
+        return cachedSnapshot
+    }
+
     static func refresh(useCache: Bool = true) -> AppLibraryRefreshResult {
         let scannedApps = AppIndexer.scan(useCache: useCache)
         let reconciledStore = TagEditor.reconcileScannedApps(scannedApps)
@@ -30,8 +45,10 @@
             apps: scannedApps,
             store: reconciledStore
         )
+        let snapshot = makeSnapshot(scannedApps: scannedApps, store: smartStartResult.store)
+        updateLastSnapshot(snapshot)
         return AppLibraryRefreshResult(
-            snapshot: makeSnapshot(scannedApps: scannedApps, store: smartStartResult.store),
+            snapshot: snapshot,
             smartStartResult: smartStartResult
         )
     }
@@ -41,8 +58,10 @@
         scannedApps: [AppInfo]
     ) -> AppLibrarySmartStartApplyResult {
         let result = SmartStartService.applySuggestion(draft)
+        let snapshot = makeSnapshot(scannedApps: scannedApps, store: result.store)
+        updateLastSnapshot(snapshot)
         return AppLibrarySmartStartApplyResult(
-            snapshot: makeSnapshot(scannedApps: scannedApps, store: result.store),
+            snapshot: snapshot,
             summary: result.summary
         )
     }
@@ -50,10 +69,28 @@
     static func applySystemInitialScheme() -> AppLibrarySystemSchemeApplyResult {
         let scannedApps = AppIndexer.scan(useCache: false)
         let result = SmartStartService.applySystemInitialScheme(apps: scannedApps)
+        let snapshot = makeSnapshot(scannedApps: scannedApps, store: result.store)
+        updateLastSnapshot(snapshot)
         return AppLibrarySystemSchemeApplyResult(
-            snapshot: makeSnapshot(scannedApps: scannedApps, store: result.store),
+            snapshot: snapshot,
             summary: result.summary
         )
+    }
+
+    static func resetToUncategorized() -> AppLibraryUncategorizedResetResult {
+        let scannedApps = AppIndexer.scan(useCache: false)
+        let store = TagDatabase.resetAppTagAssignmentsToUncategorized()
+        let snapshot = makeSnapshot(scannedApps: scannedApps, store: store)
+        updateLastSnapshot(snapshot)
+        return AppLibraryUncategorizedResetResult(
+            snapshot: snapshot
+        )
+    }
+
+    private static func updateLastSnapshot(_ snapshot: AppLibrarySnapshot) {
+        snapshotCacheLock.lock()
+        cachedSnapshot = snapshot
+        snapshotCacheLock.unlock()
     }
 
     private static func makeSnapshot(
@@ -65,7 +102,13 @@
             apps: apps,
             quickSearchDocuments: QuickSearchEngine.makeDocuments(apps: apps, store: store),
             tagColors: store.tags.mapValues { $0.color },
-            tagOrder: TagEditor.orderedTagNames()
+            tagOrder: TagEditor.orderedTagNames(in: store),
+            tagDefinitions: store.tags,
+            containerAppOrder: TagDatabase.normalizedContainerAppOrder(
+                store.containerAppOrder,
+                tags: store.tags,
+                appTags: store.appTags
+            )
         )
     }
 }

--
Gitblit v1.9.3