Ariver
2026-06-28 71a520840eb3debe46173c1f73bc85bbea0b1aa6
src/Apptag/PreferencesView.swift
@@ -1,11 +1,15 @@
import SwiftUI
import AppKit
import Carbon
// MARK: - Preferences View
private let themePreviewCountdownTimer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
private enum SettingsTab: String, CaseIterable, Identifiable {
    case language
    case general
    case theme
    case hotkeys
    case tags
    case data
@@ -17,6 +21,7 @@
        switch self {
        case .language: return "settings.language"
        case .general: return "settings.general"
        case .theme: return "settings.theme"
        case .hotkeys: return "quickSearch.hotkeys"
        case .tags: return "settings.tags"
        case .data: return "settings.data"
@@ -28,6 +33,7 @@
        switch self {
        case .language: return "globe"
        case .general: return "gearshape"
        case .theme: return "paintpalette.fill"
        case .hotkeys: return "keyboard"
        case .tags: return "tag.fill"
        case .data: return "externaldrive.fill"
@@ -63,8 +69,12 @@
    @AppStorage("launchAtLogin") private var launchAtLogin = AppDefaults.launchAtLogin
    @AppStorage("showUncommonAppBubbles") private var showUncommonAppBubbles = AppDefaults.showUncommonAppBubbles
    @AppStorage("hideUsageTips") private var hideUsageTips = AppDefaults.hideUsageTips
    @AppStorage(AppGridTheme.storageKey) private var appGridThemeID = AppDefaults.appGridThemeID
    @AppStorage(AppGridTheme.deepBlueTuningStorageKey) private var deepBlueThemeTuning = AppGridTheme.deepBlue.defaultColorTuning
    @AppStorage(AppGridTheme.colorfulTuningStorageKey) private var colorfulThemeTuning = AppGridTheme.colorful.defaultColorTuning
    @AppStorage("mainHotkeyRegistrationState") private var mainHotkeyRegistrationState = LauncherHotkeyRegistrationState.active.rawValue
    @AppStorage("quickSearchHotkeyRegistrationState") private var quickSearchHotkeyRegistrationState = LauncherHotkeyRegistrationState.active.rawValue
    @ObservedObject private var proEntitlement = ProEntitlementCenter.shared
    @State private var selectedLanguage = L10n.selectedLanguageCode
    @State private var isRefreshingLanguage = false
    @State private var allApps: [AppInfo] = []
@@ -77,8 +87,23 @@
    @State private var isDataFilePanelPresented = false
    @State private var hotkeyStatusToast: String? = nil
    @State private var hotkeyStatusToastToken: UUID? = nil
    @State private var recordingHotkeyKind: LauncherHotkeyKind? = nil
    @State private var hotkeyRecorderMonitor: Any? = nil
    @State private var hotkeySettingsRefreshToken = UUID()
    @State private var selectedTab: SettingsTab = .general
    @State private var selectedInitialLayoutMode: InitialLayoutMode = .smart
    @State private var settingsProPromptFeature: ProFeature? = nil
    @State private var themePreviewNow = Date()
    init(initialTabRawValue: String? = nil) {
        let initialTab = initialTabRawValue.flatMap(SettingsTab.init(rawValue:)) ?? .general
        _selectedTab = State(initialValue: initialTab)
    }
    private func selectTab(rawValue: String?) {
        guard let rawValue, let tab = SettingsTab(rawValue: rawValue) else { return }
        selectedTab = tab
    }
    private func scanApps() {
        DispatchQueue.global(qos: .userInitiated).async {
@@ -99,6 +124,10 @@
    }
    private func exportTags() {
        guard proEntitlement.isUnlocked else {
            presentSettingsProPrompt(for: .layoutExport)
            return
        }
        guard prepareDataFilePanelPresentation() else { return }
        DispatchQueue.main.async {
            TagDatabase.flushPendingCategorySchemeBackupBatch()
@@ -115,6 +144,10 @@
                guard response == .OK, let url = panel.url else { return }
                do {
                    try TagDatabase.exportTo(url)
                } catch let error as ProEntitlementError {
                    if let feature = error.feature {
                        presentSettingsProPrompt(for: feature)
                    }
                } catch {
                    fputs("[TagLauncher] Export failed: \(error)\n", stderr)
                    showDataAlert(title: tr("settings.exportFailed"), message: error.localizedDescription)
@@ -124,6 +157,10 @@
    }
    private func importTags() {
        guard proEntitlement.isUnlocked else {
            presentSettingsProPrompt(for: .layoutImport)
            return
        }
        guard prepareDataFilePanelPresentation() else { return }
        DispatchQueue.main.async {
            let panel = NSOpenPanel()
@@ -140,6 +177,10 @@
                    scanApps()
                    refreshDataState()
                    notifyDataChanged()
                } catch let error as ProEntitlementError {
                    if let feature = error.feature {
                        presentSettingsProPrompt(for: feature)
                    }
                } catch {
                    fputs("[TagLauncher] Import failed: \(error)\n", stderr)
                    showDataAlert(title: tr("settings.importFailed"), message: error.localizedDescription)
@@ -268,8 +309,78 @@
        let status = LauncherHotkeyRegistrationStore.failureCode(for: kind)
            .map(String.init) ?? "-"
        return tr(key)
            .replacingOccurrences(of: "%shortcut%", with: kind.hotkey.displayString)
            .replacingOccurrences(of: "%shortcut%", with: LauncherHotkeySettings.effectiveHotkey(for: kind).displayString)
            .replacingOccurrences(of: "%status%", with: status)
    }
    private func startHotkeyRecording(for kind: LauncherHotkeyKind) {
        guard ProEntitlementPolicy.isUnlocked(.customHotkeys) else {
            presentSettingsProPrompt(for: .customHotkeys)
            return
        }
        stopHotkeyRecording(showCancelledToast: false)
        recordingHotkeyKind = kind
        showHotkeyStatusToast(tr("hotkeys.recording"))
        hotkeyRecorderMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in
            DispatchQueue.main.async {
                self.captureHotkeyEvent(event)
            }
            return nil
        }
    }
    private func captureHotkeyEvent(_ event: NSEvent) {
        guard let kind = recordingHotkeyKind else { return }
        if Int(event.keyCode) == kVK_Escape {
            stopHotkeyRecording(showCancelledToast: true)
            return
        }
        let candidate = LauncherHotkeySettings.candidate(from: event)
        let result = (NSApp.delegate as? AppDelegate)?
            .applyCustomHotkey(candidate, for: kind)
            ?? .registrationFailed(-1)
        stopHotkeyRecording(showCancelledToast: false)
        handleHotkeyCustomizationResult(result)
    }
    private func restoreDefaultHotkey(for kind: LauncherHotkeyKind) {
        guard ProEntitlementPolicy.isUnlocked(.customHotkeys) else {
            presentSettingsProPrompt(for: .customHotkeys)
            return
        }
        let result = (NSApp.delegate as? AppDelegate)?
            .restoreDefaultHotkey(for: kind)
            ?? .registrationFailed(-1)
        handleHotkeyCustomizationResult(result)
    }
    private func stopHotkeyRecording(showCancelledToast: Bool = false) {
        if let hotkeyRecorderMonitor {
            NSEvent.removeMonitor(hotkeyRecorderMonitor)
        }
        hotkeyRecorderMonitor = nil
        recordingHotkeyKind = nil
        if showCancelledToast {
            showHotkeyStatusToast(tr("hotkeys.recordingCancelled"))
        }
    }
    private func handleHotkeyCustomizationResult(_ result: LauncherHotkeyCustomizationResult) {
        if case .locked = result {
            presentSettingsProPrompt(for: .customHotkeys)
            return
        }
        hotkeySettingsRefreshToken = UUID()
        showHotkeyStatusToast(hotkeyCustomizationMessage(for: result))
    }
    private func hotkeyCustomizationMessage(for result: LauncherHotkeyCustomizationResult) -> String {
        switch result {
        case .registrationFailed(let status):
            return tr(result.messageKey).replacingOccurrences(of: "%status%", with: String(status))
        default:
            return tr(result.messageKey)
        }
    }
    private func showHotkeyStatusToast(_ message: String) {
@@ -514,6 +625,12 @@
            GridItem(.flexible(minimum: 220), spacing: 10, alignment: .top),
        ]
    }
    private var themeColumns: [GridItem] {
        [
            GridItem(.flexible(minimum: 220), spacing: 12, alignment: .top),
            GridItem(.flexible(minimum: 220), spacing: 12, alignment: .top),
        ]
    }
    private var displayModeOptions: [(id: String, title: String)] {
        [
            ("flat", tr("settings.flat")),
@@ -525,6 +642,226 @@
    }
    private var containerDisplayModeOptions: [(id: String, title: String)] {
        Array(displayModeOptions.dropFirst())
    }
    private var selectedAppGridTheme: AppGridTheme {
        AppGridTheme(storedID: appGridThemeID)
    }
    private var effectiveAppGridTheme: AppGridTheme {
        ProEntitlementPolicy.effectiveTheme(for: selectedAppGridTheme)
    }
    private var proStatusPillStyle: ProStatusPillStyle {
        if proEntitlement.isPreviewingTheme {
            return .preview
        }
        switch proEntitlement.accessState {
        case .free:
            return .neutral
        case .purchased:
            return .unlocked
        case .legacy:
            return .legacy
        }
    }
    private var proCardTitle: String {
        switch proEntitlement.accessState {
        case .free:
            return tr("pro.card.title.free")
        case .purchased:
            return tr("pro.card.title.unlocked")
        case .legacy:
            return tr("pro.card.title.legacy")
        }
    }
    private var proCardSummary: String {
        switch proEntitlement.accessState {
        case .free:
            return tr("pro.card.summary.free")
        case .purchased:
            return tr("pro.card.summary.unlocked")
        case .legacy:
            return tr("pro.card.summary.legacy")
        }
    }
    private var themeStatusSummary: String {
        if proEntitlement.isPreviewingTheme {
            if let countdown = themePreviewCountdownText {
                return tr("pro.theme.status.previewCountdown")
                    .replacingOccurrences(of: "%time%", with: countdown)
            }
            return tr("pro.theme.status.preview")
        }
        switch proEntitlement.accessState {
        case .free:
            return tr("pro.theme.status.free")
        case .purchased, .legacy:
            return tr("pro.theme.status.unlocked")
        }
    }
    private func unlockButtonTitle() -> String {
        tr("pro.card.unlock")
    }
    private func handleThemeSelection(_ theme: AppGridTheme) {
        if theme.isFreeTheme || proEntitlement.isUnlocked {
            proEntitlement.stopThemePreview()
            appGridThemeID = theme.rawValue
            return
        }
        proEntitlement.startThemePreview(for: theme, tuning: currentThemeTuning(for: theme))
    }
    private var activeColorTuningTheme: AppGridTheme? {
        let theme = effectiveAppGridTheme
        return theme.supportsColorTuning ? theme : nil
    }
    private func currentThemeTuning(for theme: AppGridTheme) -> Double {
        if let preview = proEntitlement.themePreviewState,
           preview.theme == theme {
            return theme.normalizedTuning(preview.themeTuning)
        }
        switch theme {
        case .deepBlue:
            return theme.normalizedTuning(deepBlueThemeTuning)
        case .colorful:
            return theme.normalizedTuning(colorfulThemeTuning)
        case .defaultLight, .black, .pink, .purple, .green, .blue:
            return theme.defaultColorTuning
        }
    }
    private func persistThemeTuning(_ tuning: Double?, for theme: AppGridTheme) {
        let normalized = theme.normalizedTuning(tuning)
        switch theme {
        case .deepBlue:
            deepBlueThemeTuning = normalized
        case .colorful:
            colorfulThemeTuning = normalized
        case .defaultLight, .black, .pink, .purple, .green, .blue:
            break
        }
    }
    private func updateThemeTuning(_ value: Double, for theme: AppGridTheme) {
        let normalized = theme.normalizedTuning(value)
        if proEntitlement.isUnlocked || theme.isFreeTheme {
            persistThemeTuning(normalized, for: theme)
            return
        }
        if proEntitlement.themePreviewState?.theme == theme {
            proEntitlement.updateThemePreviewTuning(normalized, for: theme)
        } else {
            proEntitlement.startThemePreview(for: theme, tuning: normalized)
        }
    }
    private func themeTuningBinding(for theme: AppGridTheme) -> Binding<Double> {
        Binding(
            get: { currentThemeTuning(for: theme) },
            set: { updateThemeTuning($0, for: theme) }
        )
    }
    private func themeOptionAccessory(for theme: AppGridTheme) -> ThemeOptionAccessory {
        if let preview = proEntitlement.themePreviewState?.theme, preview == theme {
            return .countdown(text: themePreviewCountdownText ?? "00:00")
        }
        if !proEntitlement.isUnlocked && theme.requiresPro {
            return .pill(text: tr("pro.card.badge"), style: .locked)
        }
        return effectiveAppGridTheme == theme ? .checkmark : .circle
    }
    private func presentSettingsProPrompt(for feature: ProFeature) {
        proEntitlement.clearTransientOperationState()
        withAnimation(.spring(response: 0.22, dampingFraction: 0.84)) {
            settingsProPromptFeature = feature
        }
    }
    private var themePreviewCountdownText: String? {
        guard let preview = proEntitlement.themePreviewState else { return nil }
        return Self.formatThemePreviewCountdown(seconds: preview.remainingSeconds(at: themePreviewNow))
    }
    private static func formatThemePreviewCountdown(seconds: Int) -> String {
        let clamped = max(0, seconds)
        return String(format: "%02d:%02d", clamped / 60, clamped % 60)
    }
    private func refreshThemePreviewCountdown(now: Date = Date()) {
        themePreviewNow = now
        guard let preview = proEntitlement.themePreviewState else { return }
        if preview.remainingSeconds(at: now) <= 0 {
            proEntitlement.stopThemePreview()
        }
    }
    private func dismissSettingsProPrompt() {
        proEntitlement.clearTransientOperationState()
        withAnimation(.easeOut(duration: 0.18)) {
            settingsProPromptFeature = nil
        }
    }
    private func handleProAccessStateChange(_ newState: ProAccessState) {
        guard newState.isUnlocked else { return }
        if let preview = proEntitlement.themePreviewState {
            appGridThemeID = preview.theme.rawValue
            persistThemeTuning(preview.themeTuning, for: preview.theme)
            proEntitlement.stopThemePreview()
        }
        if settingsProPromptFeature != nil {
            dismissSettingsProPrompt()
        }
    }
    @ViewBuilder
    private var themeColorTuningSection: some View {
        if let theme = activeColorTuningTheme {
            VStack(alignment: .leading, spacing: 8) {
                HStack(alignment: .firstTextBaseline, spacing: 10) {
                    Label(
                        tr(theme == .deepBlue ? "theme.tuning.dark" : "theme.tuning.light"),
                        systemImage: "slider.horizontal.3"
                    )
                    .font(.system(size: 13, weight: .semibold))
                    .foregroundStyle(.primary)
                    Spacer(minLength: 12)
                    Text("\(Int(round(currentThemeTuning(for: theme) * 100)))")
                        .font(.system(size: 12, weight: .semibold, design: .monospaced))
                        .foregroundStyle(.secondary)
                }
                Slider(value: themeTuningBinding(for: theme), in: 0...1)
                    .controlSize(.regular)
                    .accessibilityLabel(tr(theme == .deepBlue ? "theme.tuning.dark" : "theme.tuning.light"))
                Text(tr("theme.tuning.desc"))
                    .font(.caption)
                    .foregroundStyle(.secondary)
                    .fixedSize(horizontal: false, vertical: true)
            }
            .padding(14)
            .frame(maxWidth: .infinity, alignment: .leading)
            .background(
                RoundedRectangle(cornerRadius: 10, style: .continuous)
                    .fill(Color(nsColor: .controlBackgroundColor).opacity(0.82))
            )
            .overlay(
                RoundedRectangle(cornerRadius: 10, style: .continuous)
                    .stroke(Color.secondary.opacity(0.18), lineWidth: 1)
            )
            .transition(.opacity.combined(with: .move(edge: .top)))
        }
    }
    private func generalSettingRow<Control: View>(
@@ -598,12 +935,18 @@
                .font(.system(size: 13, weight: .semibold))
                .foregroundStyle(.secondary)
            StaticHotkeyInfoRow(
            CustomizableHotkeyInfoRow(
                title: tr("quickSearch.mainHotkey"),
                description: tr("quickSearch.mainHotkeyDesc"),
                displayText: LauncherHotkey.main.displayString,
                displayText: LauncherHotkeySettings.effectiveHotkey(for: .main).displayString,
                statusText: hotkeyStatusText(for: .main),
                statusTone: hotkeyStatusTone(for: .main)
                statusTone: hotkeyStatusTone(for: .main),
                customizeTitle: proEntitlement.isUnlocked ? tr("hotkeys.customize") : tr("pro.card.badge"),
                restoreTitle: tr("hotkeys.restoreDefault"),
                isRecording: recordingHotkeyKind == .main,
                canRestore: proEntitlement.isUnlocked && LauncherHotkeySettings.hasCustomHotkey(for: .main),
                onCustomize: { startHotkeyRecording(for: .main) },
                onRestore: { restoreDefaultHotkey(for: .main) }
            )
            StaticHotkeyInfoRow(
@@ -614,14 +957,123 @@
                statusTone: .neutral
            )
            StaticHotkeyInfoRow(
            CustomizableHotkeyInfoRow(
                title: tr("quickSearch.globalHotkey"),
                description: tr("quickSearch.globalHotkeyDesc"),
                displayText: LauncherHotkey.quickSearch.displayString,
                displayText: LauncherHotkeySettings.effectiveHotkey(for: .quickSearch).displayString,
                statusText: hotkeyStatusText(for: .quickSearch),
                statusTone: hotkeyStatusTone(for: .quickSearch)
                statusTone: hotkeyStatusTone(for: .quickSearch),
                customizeTitle: proEntitlement.isUnlocked ? tr("hotkeys.customize") : tr("pro.card.badge"),
                restoreTitle: tr("hotkeys.restoreDefault"),
                isRecording: recordingHotkeyKind == .quickSearch,
                canRestore: proEntitlement.isUnlocked && LauncherHotkeySettings.hasCustomHotkey(for: .quickSearch),
                onCustomize: { startHotkeyRecording(for: .quickSearch) },
                onRestore: { restoreDefaultHotkey(for: .quickSearch) }
            )
            StaticHotkeyInfoRow(
                title: tr("trackpadGesture.title"),
                description: tr("trackpadGesture.description"),
                displayText: "taglauncher://show",
                statusText: tr("trackpadGesture.status"),
                statusTone: .neutral
            )
        }
        .id(hotkeySettingsRefreshToken)
    }
    private var themeProStatusRow: some View {
        HStack(spacing: 12) {
            ProStatusPill(
                text: tr(proEntitlement.compactStatusTextKey),
                style: proStatusPillStyle
            )
            Text(themeStatusSummary)
                .font(.system(size: 13, weight: .medium))
                .foregroundStyle(.secondary)
                .fixedSize(horizontal: false, vertical: true)
            Spacer(minLength: 0)
            if !proEntitlement.isUnlocked {
                Button(unlockButtonTitle()) {
                    presentSettingsProPrompt(for: .premiumThemes)
                }
                .buttonStyle(.borderedProminent)
                Button(tr("pro.card.restore")) {
                    proEntitlement.restorePurchases()
                }
                .buttonStyle(.bordered)
            }
        }
        .padding(.horizontal, 16)
        .padding(.vertical, 14)
        .background(
            RoundedRectangle(cornerRadius: 10, style: .continuous)
                .fill(Color(nsColor: .controlBackgroundColor))
        )
        .overlay(
            RoundedRectangle(cornerRadius: 10, style: .continuous)
                .stroke(Color.secondary.opacity(0.16), lineWidth: 1)
        )
    }
    private var proStatusCard: some View {
        HStack(alignment: .top, spacing: 18) {
            VStack(alignment: .leading, spacing: 10) {
                HStack(spacing: 10) {
                    Text(proCardTitle)
                        .font(.system(size: 20, weight: .bold))
                    ProStatusPill(
                        text: tr(proEntitlement.compactStatusTextKey),
                        style: proStatusPillStyle
                    )
                }
                Text(proCardSummary)
                    .font(.system(size: 13, weight: .medium))
                    .foregroundStyle(.secondary)
                    .lineSpacing(2)
                    .fixedSize(horizontal: false, vertical: true)
            }
            Spacer(minLength: 16)
            VStack(alignment: .trailing, spacing: 10) {
                if !proEntitlement.isUnlocked {
                    Button(unlockButtonTitle()) {
                        proEntitlement.purchasePro()
                    }
                    .buttonStyle(.borderedProminent)
                }
                Button(tr("pro.card.restore")) {
                    proEntitlement.restorePurchases()
                }
                .buttonStyle(.bordered)
                if let statusKey = proEntitlement.operationState.statusMessageKey {
                    Text(tr(statusKey))
                        .font(.caption)
                        .foregroundStyle(.secondary)
                        .multilineTextAlignment(.trailing)
                }
            }
        }
        .padding(.horizontal, 20)
        .padding(.vertical, 18)
        .frame(width: dataPanelWidth, alignment: .leading)
        .background(
            RoundedRectangle(cornerRadius: 12, style: .continuous)
                .fill(Color(nsColor: .controlBackgroundColor))
        )
        .overlay(
            RoundedRectangle(cornerRadius: 12, style: .continuous)
                .stroke(Color.secondary.opacity(0.18), lineWidth: 1)
        )
    }
    private var settingsTabBar: some View {
@@ -834,6 +1286,33 @@
                    .padding(.bottom)
                }
                    case .theme:
            ScrollView(.vertical, showsIndicators: true) {
                VStack(alignment: .leading, spacing: 18) {
                    themeProStatusRow
                    LazyVGrid(columns: themeColumns, alignment: .leading, spacing: 12) {
                        ForEach(AppGridTheme.settingsDisplayOrder) { theme in
                            ThemeOptionButton(
                                theme: theme,
                                title: tr(theme.titleKey),
                                isSelected: effectiveAppGridTheme == theme,
                                previewTuning: currentThemeTuning(for: theme),
                                accessory: themeOptionAccessory(for: theme)
                            ) {
                                handleThemeSelection(theme)
                            }
                        }
                    }
                    themeColorTuningSection
                }
                .frame(maxWidth: generalContentWidth, alignment: .leading)
                .padding(.horizontal)
                .padding(.top, 28)
                .padding(.bottom)
            }
                    case .hotkeys:
            // Tab 3: Hotkeys
            ScrollView(.vertical, showsIndicators: true) {
@@ -929,10 +1408,28 @@
                                VStack(alignment: .center, spacing: 8) {
                                    HStack(spacing: 12) {
                                        Button(tr("settings.export")) { exportTags() }
                                        Button {
                                            exportTags()
                                        } label: {
                                            HStack(spacing: 8) {
                                                Text(tr("settings.export"))
                                                if !proEntitlement.isUnlocked {
                                                    ProStatusPill(text: tr("pro.card.badge"), style: .locked, compact: true)
                                                }
                                            }
                                        }
                                            .buttonStyle(.bordered)
                                            .disabled(isDataFilePanelPresented)
                                        Button(tr("settings.import")) { importTags() }
                                        Button {
                                            importTags()
                                        } label: {
                                            HStack(spacing: 8) {
                                                Text(tr("settings.import"))
                                                if !proEntitlement.isUnlocked {
                                                    ProStatusPill(text: tr("pro.card.badge"), style: .locked, compact: true)
                                                }
                                            }
                                        }
                                            .buttonStyle(.bordered)
                                            .disabled(isDataFilePanelPresented)
                                    }
@@ -994,62 +1491,67 @@
                    case .about:
            // Tab 6: About
            VStack(spacing: 0) {
                Spacer(minLength: 72)
                Spacer(minLength: 44)
                HStack {
                    if let icon = NSImage(named: NSImage.applicationIconName) {
                        Image(nsImage: icon)
                            .resizable()
                            .frame(width: 128, height: 128)
                    }
                    VStack(alignment: .leading, spacing: 4) {
                        Text("TagLauncher")
                            .font(.title2)
                            .fontWeight(.semibold)
                        Text(tr("app.description"))
                            .font(.body)
                            .foregroundStyle(.secondary)
                        Text("\(tr("app.version")) \(appVersion) (\(tr("app.build")) \(buildVersion))")
                            .font(.callout)
                            .foregroundStyle(.tertiary)
                VStack(alignment: .center, spacing: 24) {
                    proStatusCard
                        Divider()
                            .padding(.vertical, 4)
                        HStack(spacing: 8) {
                            Button {
                                NSWorkspace.shared.open(helpPDFURL)
                            } label: {
                                Label(tr("help.openPDF"), systemImage: "questionmark.circle")
                            }
                            .buttonStyle(.borderedProminent)
                            .controlSize(.regular)
                            Button {
                                NSPasteboard.general.clearContents()
                                NSPasteboard.general.setString(helpPDFURL.absoluteString, forType: .string)
                            } label: {
                                Image(systemName: "link")
                            }
                            .buttonStyle(.bordered)
                            .controlSize(.regular)
                            .help(tr("help.copyLink"))
                    HStack(alignment: .center, spacing: 24) {
                        if let icon = NSImage(named: NSImage.applicationIconName) {
                            Image(nsImage: icon)
                                .resizable()
                                .frame(width: 112, height: 112)
                        }
                        VStack(alignment: .leading, spacing: 4) {
                            Text("TagLauncher")
                                .font(.title2)
                                .fontWeight(.semibold)
                            Text(tr("app.description"))
                                .font(.body)
                                .foregroundStyle(.secondary)
                            Text("\(tr("app.version")) \(appVersion) (\(tr("app.build")) \(buildVersion))")
                                .font(.callout)
                                .foregroundStyle(.tertiary)
                        Text(tr("help.currentLanguage"))
                            .font(.caption)
                            .foregroundStyle(.secondary)
                            .padding(.bottom, 2)
                            Divider()
                                .padding(.vertical, 4)
                        Text("万物之中,希望最美")
                            .font(.caption)
                            .foregroundStyle(.secondary)
                        Text("永桔@shanghai3168@gmail.com")
                            .font(.caption)
                            .foregroundStyle(.secondary)
                            HStack(spacing: 8) {
                                Button {
                                    NSWorkspace.shared.open(helpPDFURL)
                                } label: {
                                    Label(tr("help.openPDF"), systemImage: "questionmark.circle")
                                }
                                .buttonStyle(.borderedProminent)
                                .controlSize(.regular)
                                Button {
                                    NSPasteboard.general.clearContents()
                                    NSPasteboard.general.setString(helpPDFURL.absoluteString, forType: .string)
                                } label: {
                                    Image(systemName: "link")
                                }
                                .buttonStyle(.bordered)
                                .controlSize(.regular)
                                .help(tr("help.copyLink"))
                            }
                            Text(tr("help.currentLanguage"))
                                .font(.caption)
                                .foregroundStyle(.secondary)
                                .padding(.bottom, 2)
                            Text("万物之中,希望最美")
                                .font(.caption)
                                .foregroundStyle(.secondary)
                            Text("永桔@shanghai3168@gmail.com")
                                .font(.caption)
                                .foregroundStyle(.secondary)
                        }
                    }
                    .frame(width: dataPanelWidth, alignment: .leading)
                }
                .frame(width: 560, alignment: .leading)
                .frame(width: dataPanelWidth, alignment: .center)
                Spacer(minLength: 30)
                Spacer(minLength: 18)
@@ -1074,6 +1576,9 @@
            }
            .onReceive(NotificationCenter.default.publisher(for: .tagLauncherDataDidChange)) { _ in
                refreshDataState()
            }
            .onChange(of: proEntitlement.accessState) { _, newState in
                handleProAccessStateChange(newState)
            }
            if isRefreshingLanguage {
@@ -1122,6 +1627,28 @@
                .transition(.opacity)
            }
            if let feature = settingsProPromptFeature {
                ZStack {
                    Color.black.opacity(0.16)
                        .ignoresSafeArea()
                    ProUpgradePromptView(
                        title: tr(feature.titleKey),
                        message: tr(feature.promptMessageKey),
                        benefitText: tr(feature.benefitKey),
                        operationText: proEntitlement.operationState.statusMessageKey.map(tr),
                        unlockTitle: unlockButtonTitle(),
                        restoreTitle: tr("pro.card.restore"),
                        isBusy: proEntitlement.operationState.isBusy,
                        onClose: dismissSettingsProPrompt,
                        onUnlock: { proEntitlement.purchasePro() },
                        onRestore: { proEntitlement.restorePurchases() }
                    )
                }
                .zIndex(4)
                .transition(.opacity)
            }
            if let hotkeyStatusToast {
                VStack {
                    Spacer()
@@ -1140,7 +1667,7 @@
                        .frame(maxWidth: 620)
                        .padding(.bottom, 22)
                }
                .zIndex(4)
                .zIndex(5)
                .transition(.opacity.combined(with: .move(edge: .bottom)))
            }
        }
@@ -1148,9 +1675,20 @@
        .onAppear {
            syncSelectedLanguage()
            showPendingHotkeyWarningIfNeeded()
            refreshThemePreviewCountdown()
        }
        .onDisappear {
            stopHotkeyRecording()
        }
        .onReceive(themePreviewCountdownTimer) { now in
            refreshThemePreviewCountdown(now: now)
        }
        .onReceive(NotificationCenter.default.publisher(for: .tagLauncherHotkeyRegistrationChanged)) { _ in
            hotkeySettingsRefreshToken = UUID()
            showPendingHotkeyWarningIfNeeded()
        }
        .onReceive(NotificationCenter.default.publisher(for: .tagLauncherPreferencesTabRequested)) { notification in
            selectTab(rawValue: notification.userInfo?[SettingsTabTarget.userInfoKey] as? String)
        }
    }
@@ -1215,6 +1753,79 @@
                        .background(Capsule().fill(statusTone.background))
                }
                .frame(width: 180, alignment: .leading)
            }
        }
        .padding(12)
        .background(
            RoundedRectangle(cornerRadius: 8, style: .continuous)
                .fill(Color(nsColor: .controlBackgroundColor))
        )
        .overlay(
            RoundedRectangle(cornerRadius: 8, style: .continuous)
                .stroke(Color.secondary.opacity(0.14), lineWidth: 1)
        )
    }
}
private struct CustomizableHotkeyInfoRow: View {
    let title: String
    let description: String
    let displayText: String
    let statusText: String
    let statusTone: HotkeyStatusTone
    let customizeTitle: String
    let restoreTitle: String
    let isRecording: Bool
    let canRestore: Bool
    let onCustomize: () -> Void
    let onRestore: () -> Void
    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            HStack(alignment: .top, spacing: 12) {
                VStack(alignment: .leading, spacing: 3) {
                    Text(title)
                        .font(.system(size: 13, weight: .semibold))
                    Text(description)
                        .font(.caption)
                        .foregroundStyle(.secondary)
                        .fixedSize(horizontal: false, vertical: true)
                }
                .frame(maxWidth: .infinity, alignment: .leading)
                VStack(alignment: .leading, spacing: 7) {
                    Text(isRecording ? "…" : displayText)
                        .font(.system(size: 15, weight: .semibold))
                        .lineLimit(1)
                        .minimumScaleFactor(0.85)
                    HStack(spacing: 6) {
                        Text(statusText)
                            .font(.system(size: 11, weight: .semibold))
                            .foregroundStyle(statusTone.foreground)
                            .padding(.horizontal, 8)
                            .padding(.vertical, 3)
                            .background(Capsule().fill(statusTone.background))
                        if isRecording {
                            Text(tr("hotkeys.recordingInline"))
                                .font(.system(size: 11, weight: .semibold))
                                .foregroundStyle(.blue)
                        }
                    }
                    HStack(spacing: 8) {
                        Button(customizeTitle, action: onCustomize)
                            .buttonStyle(.borderedProminent)
                            .controlSize(.small)
                        Button(restoreTitle, action: onRestore)
                            .buttonStyle(.bordered)
                            .controlSize(.small)
                            .disabled(!canRestore)
                    }
                }
                .frame(width: 230, alignment: .leading)
            }
        }
        .padding(12)
@@ -1331,6 +1942,110 @@
    }
}
private enum ThemeOptionAccessory {
    case checkmark
    case circle
    case countdown(text: String)
    case pill(text: String, style: ProStatusPillStyle)
}
private struct ThemeOptionButton: View {
    let theme: AppGridTheme
    let title: String
    let isSelected: Bool
    let previewTuning: Double
    let accessory: ThemeOptionAccessory
    let action: () -> Void
    var body: some View {
        Button(action: action) {
            HStack(spacing: 12) {
                RoundedRectangle(cornerRadius: 8, style: .continuous)
                    .fill(
                        LinearGradient(
                            colors: theme.previewColors(tuning: previewTuning),
                            startPoint: .topLeading,
                            endPoint: .bottomTrailing
                        )
                    )
                    .frame(width: 70, height: 42)
                    .overlay(
                        RoundedRectangle(cornerRadius: 8, style: .continuous)
                            .stroke(previewStrokeColor, lineWidth: 1)
                    )
                    .shadow(
                        color: isSelected ? Color.accentColor.opacity(0.22) : Color.clear,
                        radius: 10,
                        x: 0,
                        y: 4
                    )
                Text(title)
                    .font(.system(size: 13, weight: .semibold))
                    .foregroundStyle(.primary)
                    .lineLimit(1)
                    .minimumScaleFactor(0.82)
                Spacer(minLength: 0)
                accessoryView
            }
            .padding(10)
            .frame(maxWidth: .infinity, minHeight: 64)
            .background(
                RoundedRectangle(cornerRadius: 8, style: .continuous)
                    .fill(isSelected ? Color.accentColor.opacity(0.10) : Color(nsColor: .controlBackgroundColor))
            )
            .overlay(
                RoundedRectangle(cornerRadius: 8, style: .continuous)
                    .stroke(isSelected ? Color.accentColor.opacity(0.32) : Color.secondary.opacity(0.16), lineWidth: 1)
            )
            .contentShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
        }
        .buttonStyle(.plain)
        .accessibilityLabel(title)
        .accessibilityIdentifier("theme-option-\(theme.rawValue)")
    }
    private var previewStrokeColor: Color {
        theme.isDefaultLight
            ? Color.secondary.opacity(0.26)
            : Color.white.opacity(0.24)
    }
    @ViewBuilder
    private var accessoryView: some View {
        switch accessory {
        case .checkmark:
            Image(systemName: "checkmark.circle.fill")
                .font(.system(size: 16, weight: .semibold))
                .foregroundStyle(Color.accentColor)
        case .circle:
            Image(systemName: "circle")
                .font(.system(size: 16, weight: .semibold))
                .foregroundStyle(Color.secondary.opacity(0.42))
        case .countdown(let text):
            Text(text)
                .font(.system(size: 10, weight: .semibold, design: .monospaced))
                .foregroundStyle(Color(red: 0.30, green: 0.22, blue: 0.08))
                .lineLimit(1)
                .frame(minWidth: 42)
                .padding(.horizontal, 8)
                .padding(.vertical, 4)
                .background(
                    Capsule(style: .continuous)
                        .fill(Color.orange.opacity(0.14))
                )
                .overlay(
                    Capsule(style: .continuous)
                        .stroke(Color.orange.opacity(0.28), lineWidth: 1)
                )
        case .pill(let text, let style):
            ProStatusPill(text: text, style: style, compact: true)
        }
    }
}
private struct DisplayModeOptionButton: View {
    let mode: String
    let title: String