From 9ab01e81a56761859344ba43f407d0762107a0dc Mon Sep 17 00:00:00 2001
From: Ariver <ar@MacBook-Air.local>
Date: Wed, 06 May 2026 18:44:09 +0800
Subject: [PATCH] checkpoint: v3.1.3 — 清除 Re-index 功能,已脱离 Finder 无意义

---
 Apptag/ApptagApp.swift |   53 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/Apptag/ApptagApp.swift b/Apptag/ApptagApp.swift
index adc2a53..4e1ad64 100644
--- a/Apptag/ApptagApp.swift
+++ b/Apptag/ApptagApp.swift
@@ -1,6 +1,7 @@
 import SwiftUI
 import AppKit
 import Carbon
+import ServiceManagement
 
 // MARK: - Application Entry Point
 
@@ -31,6 +32,31 @@
         registerHotkey()
         observeOtherWindows()
         observeEditMode()
+        observeDockSetting()
+        setupLaunchAtLogin()
+    }
+
+    /// Observe Show in Dock changes so it takes effect immediately.
+    private func observeDockSetting() {
+        NotificationCenter.default.addObserver(
+            forName: UserDefaults.didChangeNotification,
+            object: nil, queue: .main
+        ) { _ in
+            let show = UserDefaults.standard.bool(forKey: "showDockIcon")
+            NSApp.setActivationPolicy(show ? .regular : .accessory)
+        }
+    }
+
+    /// Enable launch at login by default; prompt user if disabled.
+    private func setupLaunchAtLogin() {
+        let key = "launchAtLogin"
+        if UserDefaults.standard.object(forKey: key) == nil {
+            // First launch: enable by default
+            UserDefaults.standard.set(true, forKey: key)
+            try? SMAppService.mainApp.register()
+        } else if UserDefaults.standard.bool(forKey: key) {
+            try? SMAppService.mainApp.register()
+        }
     }
 
     // MARK: - Menu Bar
@@ -349,6 +375,7 @@
     @AppStorage("displayMode") private var displayMode = "flat"
     @AppStorage("hideAppNames") private var hideAppNames = false
     @AppStorage("showDockIcon") private var showDockIcon = false
+    @AppStorage("launchAtLogin") private var launchAtLogin = true
 
     @State private var allApps: [AppInfo] = []
     @State private var tagColors: [String: Int] = [:]
@@ -414,6 +441,17 @@
         TabView {
             // Tab 1: General
             Form {
+                Section {
+                    Toggle("Launch at login", isOn: $launchAtLogin)
+                        .onChange(of: launchAtLogin) { _, enabled in
+                            if enabled {
+                                try? SMAppService.mainApp.register()
+                            } else {
+                                try? SMAppService.mainApp.unregister()
+                            }
+                        }
+                }
+
                 Section {
                     LabeledContent("App list style:") {
                         Picker("", selection: $displayMode) {
@@ -497,21 +535,6 @@
 
             // Tab 3: Data
             Form {
-                Section {
-                    HStack {
-                        Button("Re-index Now") {
-                            NotificationCenter.default.post(name: .apptagReindex, object: nil)
-                        }
-                        .buttonStyle(.borderedProminent)
-
-                        Text("Re-scan all app directories and refresh the tag database.")
-                            .font(.caption)
-                            .foregroundStyle(.secondary)
-                    }
-                } header: {
-                    Text("Index Management")
-                }
-
                 Section {
                     HStack(spacing: 12) {
                         Button("Export Tags…") { exportTags() }

--
Gitblit v1.9.3