From 9d6f138e40a5322ee731f8096eaa3332c94a6532 Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Mon, 18 May 2026 17:54:35 +0800
Subject: [PATCH] Speed up repeated app list opens

---
 Apptag/ContentView.swift |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/Apptag/ContentView.swift b/Apptag/ContentView.swift
index 8eae143..16f587e 100644
--- a/Apptag/ContentView.swift
+++ b/Apptag/ContentView.swift
@@ -9,6 +9,7 @@
     static let tagLauncherAppNoteEditingChanged = Notification.Name("TagLauncherAppNoteEditingChanged")
     static let tagLauncherDataDidChange = Notification.Name("TagLauncherDataDidChange")
     static let tagLauncherOpenPreferencesRequested = Notification.Name("TagLauncherOpenPreferencesRequested")
+    static let tagLauncherOverlayDidShow = Notification.Name("TagLauncherOverlayDidShow")
 }
 
 // MARK: - Edit Phase
@@ -483,14 +484,15 @@
             }
         }
         .onAppear {
-            let mousePoint = NSEvent.mouseLocation
-            let activeScreen = NSScreen.screens.first(where: {
-                NSMouseInRect(mousePoint, $0.frame, false)
-            }) ?? NSScreen.main
-            notchHeight = activeScreen?.safeAreaInsets.top ?? 0
+            refreshNotchHeight()
+            refreshApps()
+        }
+        .onReceive(NotificationCenter.default.publisher(for: .tagLauncherOverlayDidShow)) { _ in
+            refreshNotchHeight()
             refreshApps()
         }
         .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
+            guard allApps.isEmpty, !refreshInProgress else { return }
             refreshApps()
         }
         .onReceive(NotificationCenter.default.publisher(for: .tagLauncherDataDidChange)) { _ in
@@ -1853,6 +1855,14 @@
 
     // MARK: - Actions
 
+    private func refreshNotchHeight() {
+        let mousePoint = NSEvent.mouseLocation
+        let activeScreen = NSScreen.screens.first(where: {
+            NSMouseInRect(mousePoint, $0.frame, false)
+        }) ?? NSScreen.main
+        notchHeight = activeScreen?.safeAreaInsets.top ?? 0
+    }
+
     private func handleBubbleHover(app: AppInfo, frame: CGRect, hovering: Bool) {
         guard !appBubbleDisabled else {
             clearAppBubbleState()
@@ -2222,8 +2232,10 @@
 
     func refreshApps(forceLayoutRefresh: Bool = false) {
         guard !refreshInProgress else {
-            refreshAgainAfterCurrent = true
-            refreshAgainForceLayout = refreshAgainForceLayout || forceLayoutRefresh
+            if forceLayoutRefresh {
+                refreshAgainAfterCurrent = true
+                refreshAgainForceLayout = true
+            }
             return
         }
 

--
Gitblit v1.9.3