From c8be92c4ca12b53cec27c39977d2139bea3f0fe7 Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Thu, 25 Jun 2026 15:06:28 +0800
Subject: [PATCH] Add remove tag shred preview
---
src/Apptag/ApptagApp.swift | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 112 insertions(+), 8 deletions(-)
diff --git a/src/Apptag/ApptagApp.swift b/src/Apptag/ApptagApp.swift
index c88dc4a..d7b7ee6 100644
--- a/src/Apptag/ApptagApp.swift
+++ b/src/Apptag/ApptagApp.swift
@@ -251,12 +251,15 @@
.combinedSessionState,
eventType: .leftMouseUp
)
- let recentMouseClick = min(lastMouseDown, lastMouseUp) < 1.2
+ let recentMouseClick = min(lastMouseDown, lastMouseUp) < 0.9
return recentMouseClick && isPointerNearDockArea()
}
private func isPointerNearDockArea() -> Bool {
let mouse = NSEvent.mouseLocation
+ let dockOrientation = UserDefaults(suiteName: "com.apple.dock")?
+ .string(forKey: "orientation") ?? "bottom"
+ let hiddenDockEdgeTolerance: CGFloat = 96
return NSScreen.screens.contains { screen in
let frame = screen.frame
let visible = screen.visibleFrame
@@ -270,7 +273,16 @@
let rightDock = visible.maxX < frame.maxX
&& mouse.x <= frame.maxX
&& mouse.x >= visible.maxX - 24
- return bottomDock || leftDock || rightDock
+ let hiddenDockFallback: Bool
+ switch dockOrientation {
+ case "left":
+ hiddenDockFallback = mouse.x <= frame.minX + hiddenDockEdgeTolerance
+ case "right":
+ hiddenDockFallback = mouse.x >= frame.maxX - hiddenDockEdgeTolerance
+ default:
+ hiddenDockFallback = mouse.y <= frame.minY + hiddenDockEdgeTolerance
+ }
+ return bottomDock || leftDock || rightDock || hiddenDockFallback
}
}
@@ -330,11 +342,53 @@
}
}
+ private func foregroundWindowForActivationPolicyRestore() -> NSWindow? {
+ if let settingsWindow, settingsWindow.isVisible {
+ return settingsWindow
+ }
+ if let overlayWindow, overlayWindow.isVisible {
+ return overlayWindow
+ }
+ return NSApp.keyWindow
+ }
+
+ private func setLauncherActivationPolicy(_ desiredPolicy: NSApplication.ActivationPolicy) {
+ guard NSApp.activationPolicy() != desiredPolicy else { return }
+
+ let restoreWindow = desiredPolicy == .accessory && NSApp.isActive
+ ? foregroundWindowForActivationPolicyRestore()
+ : nil
+
+ // Deactivate before switching regular -> accessory; otherwise Dock can
+ // keep a stale running tile until Dock itself restarts.
+ if desiredPolicy == .accessory && NSApp.isActive {
+ NSApp.deactivate()
+ }
+
+ NSApp.setActivationPolicy(desiredPolicy)
+
+ guard desiredPolicy == .accessory,
+ let restoreWindow,
+ restoreWindow.isVisible
+ else { return }
+
+ DispatchQueue.main.async { [weak self, weak restoreWindow] in
+ guard let self,
+ let restoreWindow,
+ restoreWindow.isVisible,
+ self.requiresForegroundOwnership
+ else { return }
+ NSApp.activate(ignoringOtherApps: true)
+ restoreWindow.makeKeyAndOrderFront(nil)
+ restoreWindow.orderFrontRegardless()
+ }
+ }
+
private func beginLauncherForegroundOwnership(activate: Bool = true, keyWindow: NSWindow? = nil) {
let showDock = UserDefaults.standard.bool(forKey: Self.showDockIconKey)
let desiredPolicy: NSApplication.ActivationPolicy = showDock ? .regular : .accessory
if NSApp.activationPolicy() != desiredPolicy {
- NSApp.setActivationPolicy(desiredPolicy)
+ setLauncherActivationPolicy(desiredPolicy)
}
if activate, showDock {
claimLauncherForeground(keyWindow: keyWindow)
@@ -351,7 +405,7 @@
overlayGeneration expectedOverlayGeneration: Int? = nil
) {
if NSApp.activationPolicy() != .regular {
- NSApp.setActivationPolicy(.regular)
+ setLauncherActivationPolicy(.regular)
}
if isOverlayVisible && !NSApp.presentationOptions.contains(.hideDock) {
@@ -413,7 +467,7 @@
? .regular
: (showDock ? .regular : .accessory))))
if NSApp.activationPolicy() != desiredPolicy {
- NSApp.setActivationPolicy(desiredPolicy)
+ setLauncherActivationPolicy(desiredPolicy)
}
let desiredPresentation: NSApplication.PresentationOptions = isOverlayVisible ? [.hideDock] : []
@@ -1613,9 +1667,13 @@
forName: .tagLauncherOpenPreferencesRequested,
object: nil,
queue: .main
- ) { [weak self] _ in
- self?.openPreferences()
+ ) { [weak self] notification in
+ self?.openPreferences(targetTab: Self.preferencesTabTarget(from: notification))
}
+ }
+
+ private static func preferencesTabTarget(from notification: Notification) -> String? {
+ notification.userInfo?[SettingsTabTarget.userInfoKey] as? String
}
private func observeExternalActivationRequests() {
@@ -1637,6 +1695,10 @@
}
@objc private func openPreferences(_ sender: Any? = nil) {
+ openPreferences(targetTab: nil)
+ }
+
+ private func openPreferences(targetTab: String?) {
dismissQuickSearchIfNeeded()
TagDatabase.flushPendingCategorySchemeBackupBatch()
if overlayAvoidsSpaceSwitch {
@@ -1652,6 +1714,7 @@
if let settingsWindow {
prepareSettingsWindow(settingsWindow)
+ requestPreferencesTabSelection(targetTab)
return
}
@@ -1662,10 +1725,19 @@
defer: false
)
window.title = tr("menu.preferences").replacingOccurrences(of: "…", with: "")
- window.contentView = NSHostingView(rootView: PreferencesView())
+ window.contentView = NSHostingView(rootView: PreferencesView(initialTabRawValue: targetTab))
window.isReleasedWhenClosed = false
settingsWindow = window
prepareSettingsWindow(window)
+ }
+
+ private func requestPreferencesTabSelection(_ targetTab: String?) {
+ guard let targetTab else { return }
+ NotificationCenter.default.post(
+ name: .tagLauncherPreferencesTabRequested,
+ object: nil,
+ userInfo: [SettingsTabTarget.userInfoKey: targetTab]
+ )
}
private func dismissQuickSearchIfNeeded() {
@@ -1739,7 +1811,13 @@
super.mouseDown(with: event)
return
}
+ if routeUsageTipsMouseDownIfNeeded(event) {
+ return
+ }
if hit == self {
+ if shouldSwallowUsageTipsBackdropClick(at: location) {
+ return
+ }
if quickSearchSuppressesBackdropDismiss {
NotificationCenter.default.post(
name: .tagLauncherQuickSearchDismissRequested,
@@ -1774,6 +1852,32 @@
super.mouseDown(with: event)
}
+ private func routeUsageTipsMouseDownIfNeeded(_ event: NSEvent) -> Bool {
+ guard let appGridHost = findAppGridCollectionHost(in: self) else { return false }
+ return appGridHost.handleUsageTipsMouseDown(event)
+ }
+
+ private func findAppGridCollectionHost(in view: NSView) -> AppGridCollectionHostView? {
+ if let host = view as? AppGridCollectionHostView {
+ return host
+ }
+ for subview in view.subviews {
+ if let host = findAppGridCollectionHost(in: subview) {
+ return host
+ }
+ }
+ return nil
+ }
+
+ private func shouldSwallowUsageTipsBackdropClick(at location: NSPoint) -> Bool {
+ guard !UserDefaults.standard.bool(forKey: "hideUsageTips") else { return false }
+ let height = min(bounds.height, AppGridUsageTipsMetrics.reservedHeight)
+ guard height > 0 else { return false }
+ let y = isFlipped ? max(0, bounds.height - height) : 0
+ let region = NSRect(x: 0, y: y, width: bounds.width, height: height)
+ return region.contains(location)
+ }
+
private func observeBackdropDismissSuppressionChanges() {
modalInteractionObserver = NotificationCenter.default.addObserver(
forName: .tagLauncherModalInteractionChanged,
--
Gitblit v1.9.3