| | |
| | | let colorIndex: Int |
| | | var dragModeActive: Bool = false |
| | | var isDragging: Bool = false |
| | | var dragResetToken: Int = 0 |
| | | let action: () -> Void |
| | | |
| | | private var bgColor: Color { |
| | |
| | | .opacity(dragModeActive ? (isDragging ? 1.0 : 0.62) : 1.0) |
| | | .animation(.easeOut(duration: 0.08), value: isDragging) |
| | | .animation(.easeOut(duration: 0.08), value: dragModeActive) |
| | | .id("\(name)|reset-\(dragResetToken)") |
| | | .contentShape(RoundedRectangle(cornerRadius: 7)) |
| | | .onTapGesture { |
| | | action() |
| | |
| | | let colorIndex: Int |
| | | var dragModeActive: Bool = false |
| | | var isDragging: Bool = false |
| | | var dragResetToken: Int = 0 |
| | | let action: () -> Void |
| | | |
| | | private var bgColor: Color { |
| | |
| | | .opacity(dragModeActive ? (isDragging ? 1.0 : 0.62) : 1.0) |
| | | .animation(.easeOut(duration: 0.08), value: isDragging) |
| | | .animation(.easeOut(duration: 0.08), value: dragModeActive) |
| | | .id("\(name)|reset-\(dragResetToken)") |
| | | .contentShape(RoundedRectangle(cornerRadius: 6)) |
| | | .onTapGesture { |
| | | action() |
| | |
| | | let hideOverlay: () -> Void |
| | | private let initialQuickSearchSource: String? |
| | | |
| | | @Environment(\.colorScheme) private var colorScheme |
| | | @State private var allApps: [AppInfo] = [] |
| | | @State private var displayGroups: [TagGroup] = [] |
| | | @State private var tagColors: [String: Int] = [:] |
| | |
| | | @State private var groupLayoutVersion = 0 |
| | | @State private var cachedGridContainerRowsKey: GridContainerRowsKey? = nil |
| | | @State private var cachedGridContainerRows: [GridContainerLayoutRow] = [] |
| | | @State private var appGridScrollTargetID: String? = nil |
| | | @State private var appGridScrollRequestToken = 0 |
| | | |
| | | // Edit mode |
| | | @State private var editPhase: EditPhase = .none |
| | |
| | | @State private var tagReorderFrames: [String: CGRect] = [:] |
| | | @State private var tagNavDragModeActive = false |
| | | @State private var tagNavDragItem: String? = nil |
| | | @State private var tagNavDragResetToken = 0 |
| | | @State private var tagNavReorderFrames: [String: CGRect] = [:] |
| | | @State private var tagNavReorderDidMove = false |
| | | @State private var hoveredContainer: String? = nil // colored container lift |
| | |
| | | @State private var refreshInProgress = false |
| | | @State private var refreshAgainAfterCurrent = false |
| | | @State private var refreshAgainForceLayout = false |
| | | @State private var hoveredAppItemID: String? = nil |
| | | @State private var hoveredBubble: AppBubbleContext? = nil |
| | | @State private var editingBubble: AppBubbleContext? = nil |
| | | @State private var pendingUncategorizedDrop: PendingUncategorizedDrop? = nil |
| | |
| | | @State private var quickSearchSelectedID: URL? = nil |
| | | @State private var quickSearchManualSelection = false |
| | | @State private var quickSearchFocusToken = 0 |
| | | @State private var quickSearchSelectionScrollToken = 0 |
| | | @State private var quickSearchCloseHidesOverlay = false |
| | | @State private var quickSearchErrorMessage: String? = nil |
| | | @State private var initialQuickSearchConsumed = false |
| | |
| | | @State private var notchHeight: CGFloat = 0 |
| | | @AppStorage("displayMode") private var displayMode = AppDefaults.displayMode |
| | | @AppStorage("hideAppNames") private var hideAppNames = AppDefaults.hideAppNames |
| | | @AppStorage("showUncommonAppBubbles") private var showUncommonAppBubbles = AppDefaults.showUncommonAppBubbles |
| | | |
| | | private let editSidebarWidth: CGFloat = 188 |
| | | private let editSidebarHorizontalInset: CGFloat = 12 |
| | |
| | | appDragModeActive || pendingUncategorizedDrop != nil || scrollInteractionState.isFrozen |
| | | } |
| | | private let rightSidebarFloatingClearance: CGFloat = 44 |
| | | |
| | | private var cardSurfaceColor: Color { |
| | | colorScheme == .dark |
| | | ? Color.white.opacity(0.055) |
| | | : Color.white.opacity(0.62) |
| | | } |
| | | |
| | | private var floatingButtonSurfaceColor: Color { |
| | | colorScheme == .dark |
| | | ? Color.white.opacity(0.10) |
| | | : Color.white.opacity(0.78) |
| | | } |
| | | |
| | | private var isSideLayout: Bool { |
| | | tagPosition == "left" || tagPosition == "right" |
| | |
| | | displayMode == "coloredContainer" || displayMode == "coloredGridContainer" |
| | | } |
| | | |
| | | private var quickSearchOnlyMode: Bool { |
| | | quickSearchVisible && quickSearchCloseHidesOverlay |
| | | private var usesAppKitContainerGrid: Bool { |
| | | displayMode == "gridContainer" || displayMode == "coloredGridContainer" |
| | | } |
| | | |
| | | var body: some View { |
| | | ZStack { |
| | | if !quickSearchOnlyMode { |
| | | if !quickSearchVisible { |
| | | VisualEffectView(material: .hudWindow, blendingMode: .behindWindow) |
| | | .ignoresSafeArea() |
| | | .allowsHitTesting(false) |
| | | } |
| | | |
| | | if !quickSearchOnlyMode { |
| | | if !quickSearchVisible { |
| | | if notchHeight > 0 { |
| | | VStack { |
| | | Rectangle().fill(.black) |
| | |
| | | |
| | | quickSearchOverlay |
| | | |
| | | if !quickSearchOnlyMode, let message = dropWarningToast { |
| | | if !quickSearchVisible, let message = dropWarningToast { |
| | | Text(message) |
| | | .font(.system(size: 16, weight: .semibold)) |
| | | .foregroundStyle(.primary) |
| | |
| | | .allowsHitTesting(false) |
| | | } |
| | | |
| | | if !quickSearchOnlyMode && dropRefreshVisible { |
| | | if !quickSearchVisible && dropRefreshVisible { |
| | | Color.black.opacity(0.08) |
| | | .ignoresSafeArea() |
| | | .transition(.opacity) |
| | |
| | | if let initialQuickSearchSource, !initialQuickSearchConsumed { |
| | | initialQuickSearchConsumed = true |
| | | quickSearchCloseHidesOverlay = initialQuickSearchSource == QuickSearchOpenSource.globalHidden |
| | | quickSearchVisible = true |
| | | quickSearchFocusToken &+= 1 |
| | | if !quickSearchVisible { |
| | | quickSearchVisible = true |
| | | quickSearchFocusToken &+= 1 |
| | | } |
| | | refreshQuickSearchResults() |
| | | NotificationCenter.default.post( |
| | | name: .tagLauncherQuickSearchVisibilityChanged, |
| | | object: nil, |
| | |
| | | .onReceive(NotificationCenter.default.publisher(for: .tagLauncherOverlayDidShow)) { _ in |
| | | resetTransientDragState() |
| | | refreshNotchHeight() |
| | | if quickSearchVisible { |
| | | refreshAppsIfNeeded() |
| | | } else { |
| | | refreshApps() |
| | | } |
| | | refreshAppsIfNeeded() |
| | | } |
| | | .onReceive(NotificationCenter.default.publisher(for: .tagLauncherOverlayDidHide)) { _ in |
| | | resetTransientDragState() |
| | |
| | | results: quickSearchResults, |
| | | selectedID: quickSearchSelectedID, |
| | | focusToken: quickSearchFocusToken, |
| | | selectionScrollToken: quickSearchSelectionScrollToken, |
| | | isLoading: quickSearchDocuments.isEmpty && refreshInProgress, |
| | | maxVisibleRows: quickSearchMaxVisibleRows(in: proxy.size), |
| | | errorMessage: quickSearchErrorMessage, |
| | |
| | | let nextIndex = min(max(currentIndex + delta, 0), quickSearchResults.count - 1) |
| | | quickSearchSelectedID = quickSearchResults[nextIndex].id |
| | | quickSearchManualSelection = true |
| | | quickSearchSelectionScrollToken &+= 1 |
| | | } |
| | | |
| | | private func selectQuickSearchResult(_ result: QuickSearchResult) { |
| | | guard quickSearchSelectedID != result.id || !quickSearchManualSelection else { return } |
| | | quickSearchSelectedID = result.id |
| | | quickSearchManualSelection = true |
| | | } |
| | |
| | | ) -> some View { |
| | | NativeFloatingIconButton(systemImage: systemImage, action: action) |
| | | .frame(width: 36, height: 36) |
| | | .background(Circle().fill(.ultraThinMaterial)) |
| | | .background(Circle().fill(floatingButtonSurfaceColor)) |
| | | } |
| | | |
| | | // MARK: - Top / Side Layouts |
| | |
| | | TagPill(name: tag.name, colorIndex: tag.colorIndex, |
| | | dragModeActive: tagNavDragModeActive && canReorderTag(tag.name), |
| | | isDragging: tagNavDragItem == tag.name, |
| | | dragResetToken: tagNavDragResetToken, |
| | | action: { |
| | | activateTagNavigation(tag.id) |
| | | }) |
| | |
| | | SideTagPill(name: tag.name, colorIndex: tag.colorIndex, |
| | | dragModeActive: tagNavDragModeActive && canReorderTag(tag.name), |
| | | isDragging: tagNavDragItem == tag.name, |
| | | dragResetToken: tagNavDragResetToken, |
| | | action: { |
| | | activateTagNavigation(tag.id) |
| | | }) |
| | |
| | | Spacer() |
| | | ProgressView().scaleEffect(0.8) |
| | | Spacer() |
| | | } else if displayMode == "gridContainer" || displayMode == "coloredGridContainer" { |
| | | gridContainerGrid |
| | | } else if usesAppKitContainerGrid { |
| | | AppGridCollectionView( |
| | | groups: displayGroups, |
| | | tagColors: tagColors, |
| | | displayMode: displayMode, |
| | | iconSize: iconSize, |
| | | showNames: !hideAppNames, |
| | | bubbleDisabled: appBubbleDisabled, |
| | | showUncommonAppBubbles: showUncommonAppBubbles, |
| | | highlightedGroupName: filledColorlessContainer, |
| | | contentRevision: groupLayoutVersion, |
| | | scrollTargetID: appGridScrollTargetID, |
| | | scrollRequestToken: appGridScrollRequestToken, |
| | | onSelectApp: { app in openApp(app) }, |
| | | onBubbleHover: handleBubbleHover, |
| | | onEditNote: beginEditingBubbleNote, |
| | | onDropApp: { path, source, target, copy in |
| | | dropApp(path: path, sourceTag: source, targetTag: target, copy: copy) |
| | | }, |
| | | onGroupActivate: { groupName in |
| | | if displayMode == "gridContainer" { |
| | | toggleColorlessFill(groupName) |
| | | } |
| | | }, |
| | | onScrollActivity: handleAppGridScrollActivity, |
| | | onDragModeChange: { setAppDragMode($0) } |
| | | ) |
| | | } else if displayMode == "container" || displayMode == "coloredContainer" { |
| | | containerGrid |
| | | } else { |
| | |
| | | onBubbleHover: handleBubbleHover, |
| | | onEditNote: beginEditingBubbleNote, |
| | | bubbleDisabled: appBubbleDisabled, |
| | | showUncommonAppBubbles: showUncommonAppBubbles, |
| | | dragResetToken: appDragResetToken, |
| | | hoveredAppItemID: $hoveredAppItemID, |
| | | onDropApp: { path, source, copy in |
| | | dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy) |
| | | } |
| | |
| | | onBubbleHover: handleBubbleHover, |
| | | onEditNote: beginEditingBubbleNote, |
| | | bubbleDisabled: appBubbleDisabled, |
| | | showUncommonAppBubbles: showUncommonAppBubbles, |
| | | itemID: "\(group.name)|\(app.path.path)", |
| | | dragResetToken: appDragResetToken, |
| | | hoveredAppItemID: $hoveredAppItemID, |
| | | onSelect: { openApp(app) } |
| | | ) |
| | | } |
| | |
| | | .fill((isColored || isColorlessActive) ? tagColor.opacity(0.30) : Color.clear) |
| | | .background( |
| | | RoundedRectangle(cornerRadius: 14) |
| | | .fill(.ultraThinMaterial) |
| | | .fill(cardSurfaceColor) |
| | | ) |
| | | ) |
| | | .overlay( |
| | |
| | | .stroke(Color.primary.opacity(0.08), lineWidth: 1) |
| | | ) |
| | | .overlay { |
| | | AppDropTargetView(targetTag: group.name) { path, source, copy in |
| | | dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy) |
| | | if appDragModeActive { |
| | | AppDropTargetView(targetTag: group.name) { path, source, copy in |
| | | dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy) |
| | | } |
| | | .allowsHitTesting(false) |
| | | } |
| | | .allowsHitTesting(false) |
| | | } |
| | | .shadow(color: .black.opacity((isColored && isHovered) || isColorlessActive ? 0.22 : 0), |
| | | radius: (isColored && isHovered) || isColorlessActive ? 8 : 0, |
| | |
| | | .zIndex(isHovered ? 50 : 0) |
| | | .animation(.easeOut(duration: 0.045), value: isHovered) |
| | | .animation(.easeOut(duration: 0.08), value: isColorlessFilled) |
| | | .onHover { hovering in |
| | | .background(AppHoverTrackingView { hovering, _ in |
| | | guard !scrollInteractionState.isFrozen else { |
| | | if !hovering && hoveredContainer == group.name { |
| | | hoveredContainer = nil |
| | |
| | | if isColored || isColorless { |
| | | hoveredContainer = hovering ? group.name : nil |
| | | } |
| | | } |
| | | }) |
| | | .contentShape(RoundedRectangle(cornerRadius: 14)) |
| | | .onTapGesture { |
| | | if isColorless { |
| | |
| | | onBubbleHover: handleBubbleHover, |
| | | onEditNote: beginEditingBubbleNote, |
| | | bubbleDisabled: appBubbleDisabled, |
| | | showUncommonAppBubbles: showUncommonAppBubbles, |
| | | itemID: "\(group.name)|\(app.path.path)", |
| | | dragResetToken: appDragResetToken, |
| | | hoveredAppItemID: $hoveredAppItemID, |
| | | onSelect: { openApp(app) } |
| | | ) |
| | | .frame(width: cellWidth) |
| | |
| | | .fill((isColored || isColorlessGridActive) ? tagColor.opacity(0.30) : Color.clear) |
| | | .background( |
| | | RoundedRectangle(cornerRadius: 14) |
| | | .fill(.ultraThinMaterial) |
| | | .fill(cardSurfaceColor) |
| | | ) |
| | | ) |
| | | .overlay( |
| | |
| | | .stroke(Color.primary.opacity(0.08), lineWidth: 1) |
| | | ) |
| | | .overlay { |
| | | AppDropTargetView(targetTag: group.name) { path, source, copy in |
| | | dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy) |
| | | if appDragModeActive { |
| | | AppDropTargetView(targetTag: group.name) { path, source, copy in |
| | | dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy) |
| | | } |
| | | .allowsHitTesting(false) |
| | | } |
| | | .allowsHitTesting(false) |
| | | } |
| | | .shadow(color: .black.opacity((isColored && isHovered) || isColorlessGridActive ? 0.22 : 0), |
| | | radius: (isColored && isHovered) || isColorlessGridActive ? 8 : 0, |
| | |
| | | .zIndex(isHovered ? 50 : 0) |
| | | .animation(.easeOut(duration: 0.045), value: isHovered) |
| | | .animation(.easeOut(duration: 0.08), value: isColorlessFilled) |
| | | .onHover { hovering in |
| | | .background(AppHoverTrackingView { hovering, _ in |
| | | guard !scrollInteractionState.isFrozen else { |
| | | if !hovering && hoveredContainer == group.name { |
| | | hoveredContainer = nil |
| | |
| | | } else if hovering { |
| | | fillColorlessContainer(group.name) |
| | | } |
| | | } |
| | | }) |
| | | .contentShape(RoundedRectangle(cornerRadius: 14)) |
| | | .onTapGesture { |
| | | if isColorlessGrid { |
| | |
| | | |
| | | private func handleAppGridScrollActivity() { |
| | | if !scrollInteractionState.isFrozen { |
| | | hoveredAppItemID = nil |
| | | hoveredBubble = nil |
| | | hoveredContainer = nil |
| | | } |
| | |
| | | } |
| | | |
| | | private func clearAppBubbleState() { |
| | | hoveredAppItemID = nil |
| | | hoveredBubble = nil |
| | | if hoveredBubble != nil { |
| | | hoveredBubble = nil |
| | | } |
| | | if editingBubble != nil { |
| | | notifyAppNoteEditing(active: false) |
| | | editingBubble = nil |
| | | } |
| | | editingBubble = nil |
| | | bubbleNoteFocused = false |
| | | if bubbleNoteFocused { |
| | | bubbleNoteFocused = false |
| | | } |
| | | } |
| | | |
| | | private func notifyAppNoteEditing(active: Bool) { |
| | |
| | | } |
| | | |
| | | func scrollTo(_ id: String) { |
| | | withAnimation(.easeInOut(duration: 0.25)) { scrollProxy?.scrollTo(id, anchor: .top) } |
| | | if usesAppKitContainerGrid { |
| | | appGridScrollTargetID = id |
| | | appGridScrollRequestToken &+= 1 |
| | | } else { |
| | | withAnimation(.easeInOut(duration: 0.25)) { scrollProxy?.scrollTo(id, anchor: .top) } |
| | | } |
| | | } |
| | | |
| | | private func activateTagNavigation(_ id: String) { |
| | |
| | | } |
| | | |
| | | private func endTagNavReorder() { |
| | | let hadDragState = tagNavDragModeActive || tagNavDragItem != nil |
| | | guard hadDragState else { return } |
| | | if tagNavDragModeActive && tagNavReorderDidMove { |
| | | TagEditor.reorderTags(draggedTagNames) |
| | | } |
| | | tagNavDragModeActive = false |
| | | tagNavDragItem = nil |
| | | tagNavReorderDidMove = false |
| | | tagNavDragResetToken &+= 1 |
| | | } |
| | | |
| | | private func cancelTagNavReorderVisualState() { |
| | |
| | | tagNavDragModeActive = false |
| | | tagNavDragItem = nil |
| | | tagNavReorderDidMove = false |
| | | tagNavDragResetToken &+= 1 |
| | | } |
| | | |
| | | private func reorderTagNavItem(at location: CGPoint) { |
| | |
| | | } |
| | | |
| | | private func setAppDragMode(_ active: Bool) { |
| | | guard appDragModeActive != active else { return } |
| | | if active { |
| | | endTagNavReorder() |
| | | clearAppBubbleState() |
| | |
| | | appDragModeActive = active |
| | | if active { |
| | | DispatchQueue.main.asyncAfter(deadline: .now() + 8) { |
| | | if appDragModeActive { |
| | | if appDragModeActive && !AppDragCoordinator.shared.hasActiveDrag { |
| | | appDragModeActive = false |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | private func resetTransientDragState(keepingPendingUncategorizedDrop: Bool = false) { |
| | | let hadAppDragState = appDragModeActive |
| | | AppDragCoordinator.shared.cancelDrag() |
| | | scrollInteractionState.reset() |
| | | appDragModeActive = false |
| | | appDragResetToken &+= 1 |
| | | tagNavDragModeActive = false |
| | | tagNavDragItem = nil |
| | | tagNavReorderDidMove = false |
| | | tagNavDragResetToken &+= 1 |
| | | dragItem = nil |
| | | hoveredAppItemID = nil |
| | | hoveredContainer = nil |
| | | if appDragModeActive { |
| | | appDragModeActive = false |
| | | } |
| | | if hadAppDragState { |
| | | appDragResetToken &+= 1 |
| | | } |
| | | if tagNavDragModeActive { |
| | | tagNavDragModeActive = false |
| | | } |
| | | if tagNavDragItem != nil { |
| | | tagNavDragItem = nil |
| | | } |
| | | if tagNavReorderDidMove { |
| | | tagNavReorderDidMove = false |
| | | } |
| | | if dragItem != nil { |
| | | dragItem = nil |
| | | } |
| | | if hoveredContainer != nil { |
| | | hoveredContainer = nil |
| | | } |
| | | clearAppBubbleState() |
| | | if !keepingPendingUncategorizedDrop { |
| | | if !keepingPendingUncategorizedDrop, pendingUncategorizedDrop != nil { |
| | | pendingUncategorizedDrop = nil |
| | | } |
| | | } |
| | |
| | | } |
| | | unfreezeWorkItem?.cancel() |
| | | let workItem = DispatchWorkItem { [weak self] in |
| | | self?.isFrozen = false |
| | | guard let self, self.isFrozen else { return } |
| | | self.isFrozen = false |
| | | } |
| | | unfreezeWorkItem = workItem |
| | | DispatchQueue.main.asyncAfter(deadline: .now() + 0.18, execute: workItem) |
| | |
| | | func reset() { |
| | | unfreezeWorkItem?.cancel() |
| | | unfreezeWorkItem = nil |
| | | isFrozen = false |
| | | if isFrozen { |
| | | isFrozen = false |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | func updateNSView(_ view: ScrollActivityNSView, context: Context) { |
| | | context.coordinator.onScroll = onScroll |
| | | view.coordinator = context.coordinator |
| | | view.installObserverIfPossible() |
| | | } |
| | | |
| | | final class Coordinator { |
| | | var onScroll: () -> Void |
| | | private weak var observedClipView: NSClipView? |
| | | private var observer: NSObjectProtocol? |
| | | private var lastReportedBoundsOrigin: NSPoint? |
| | | |
| | | init(onScroll: @escaping () -> Void) { |
| | | self.onScroll = onScroll |
| | |
| | | guard observedClipView !== clipView else { return } |
| | | removeObserver() |
| | | observedClipView = clipView |
| | | lastReportedBoundsOrigin = clipView.bounds.origin |
| | | clipView.postsBoundsChangedNotifications = true |
| | | observer = NotificationCenter.default.addObserver( |
| | | forName: NSView.boundsDidChangeNotification, |
| | | object: clipView, |
| | | queue: .main |
| | | ) { [weak self] _ in |
| | | self?.onScroll() |
| | | ) { [weak self, weak clipView] _ in |
| | | guard let self, |
| | | let clipView, |
| | | self.recordScrollIfNeeded(from: clipView) |
| | | else { return } |
| | | self.onScroll() |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | observer = nil |
| | | observedClipView = nil |
| | | lastReportedBoundsOrigin = nil |
| | | } |
| | | |
| | | private func recordScrollIfNeeded(from clipView: NSClipView) -> Bool { |
| | | let origin = clipView.bounds.origin |
| | | guard let last = lastReportedBoundsOrigin else { |
| | | lastReportedBoundsOrigin = origin |
| | | return false |
| | | } |
| | | let didScroll = abs(origin.x - last.x) > 0.5 |
| | | || abs(origin.y - last.y) > 0.5 |
| | | if didScroll { |
| | | lastReportedBoundsOrigin = origin |
| | | } |
| | | return didScroll |
| | | } |
| | | |
| | | deinit { |
| | |
| | | |
| | | final class ScrollActivityNSView: NSView { |
| | | weak var coordinator: Coordinator? |
| | | private var installScheduled = false |
| | | |
| | | override func viewDidMoveToWindow() { |
| | | super.viewDidMoveToWindow() |
| | |
| | | } |
| | | |
| | | func installObserverIfPossible() { |
| | | guard !installScheduled else { return } |
| | | installScheduled = true |
| | | DispatchQueue.main.async { [weak self] in |
| | | guard let self else { return } |
| | | installScheduled = false |
| | | coordinator?.install(from: self) |
| | | } |
| | | } |