From e1226e6ae5a75388fe5d1a0e1ed008f80fee25ed Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Sun, 17 May 2026 14:21:25 +0800
Subject: [PATCH] Release Apptag 6.0.5 build 610
---
Apptag/ApptagApp.swift | 936 ++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 771 insertions(+), 165 deletions(-)
diff --git a/Apptag/ApptagApp.swift b/Apptag/ApptagApp.swift
index ed8885a..e40b773 100644
--- a/Apptag/ApptagApp.swift
+++ b/Apptag/ApptagApp.swift
@@ -5,14 +5,18 @@
// MARK: - Application Entry Point
@main
-struct ApptagApp: App {
+struct TagLauncherApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
Settings {
PreferencesView()
}
- .defaultSize(width: 660, height: 380)
+ .defaultSize(width: 880, height: 460)
+ .commands {
+ CommandGroup(replacing: .systemServices) { }
+ CommandGroup(replacing: .appVisibility) { }
+ }
}
}
@@ -24,28 +28,40 @@
}
final class AppDelegate: NSObject, NSApplicationDelegate {
- private var statusItem: NSStatusItem!
+ private static let showDockIconKey = "showDockIcon"
+ private static let showAppListMenuItemIdentifier = NSUserInterfaceItemIdentifier("TagLauncherShowAppListMenuItem")
+ private static let showAppListShortcutGlyphs = "⌥⇧␣"
+
+ private var statusItem: NSStatusItem?
private var overlayWindow: NSWindow?
+ private var overlayKeyMonitor: Any?
private var settingsWindow: NSWindow? // Track Settings window to keep it above overlay
private var hotkeyRef: EventHotKeyRef?
private var isInEditMode = false // Suppress auto-dismiss during editing
+ private var isConfiguringApplicationMenu = false
+ private var lastShowDockIcon: Bool?
+
+ static func refreshChromeSettings() {
+ (NSApp.delegate as? AppDelegate)?.syncChromeSettings(force: true)
+ }
func applicationDidFinishLaunching(_ notification: Notification) {
L10n.setup()
migrateDefaultGroupName()
TagDatabase.seedDefaultTags()
- let showDock = UserDefaults.standard.bool(forKey: "showDockIcon")
- NSApp.setActivationPolicy(showDock ? .regular : .accessory)
- setupMenuBar()
+ syncChromeSettings(force: true)
registerHotkey()
observeOtherWindows()
observeSettingsClose()
observeEditMode()
- observeDockSetting()
+ observeApplicationMenuChanges()
+ observeChromeSettings()
+ observeLanguageChanges()
setupLaunchAtLogin()
+ configureApplicationMenuWhenAvailable()
}
- /// Dock icon click → show overlay (same as menubar "Show Apptag")
+ /// Dock icon click → show overlay (same as menubar "Show TagLauncher")
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
showOverlay()
return false // Suppress default "unhide all windows" behavior
@@ -69,20 +85,47 @@
// User has set a custom name — keep it
}
- /// Observe Show in Dock changes so it takes effect immediately.
- private func observeDockSetting() {
+ /// Observe Dock visibility changes so they take effect immediately.
+ private func observeChromeSettings() {
NotificationCenter.default.addObserver(
forName: UserDefaults.didChangeNotification,
object: nil, queue: .main
- ) { _ in
- let show = UserDefaults.standard.bool(forKey: "showDockIcon")
- NSApp.setActivationPolicy(show ? .regular : .accessory)
+ ) { [weak self] _ in
+ self?.syncChromeSettings()
+ }
+ }
+
+ private func syncChromeSettings(force: Bool = false) {
+ let showDock = UserDefaults.standard.bool(forKey: Self.showDockIconKey)
+ let dockChanged = lastShowDockIcon != showDock
+
+ if force || dockChanged {
+ NSApp.setActivationPolicy(showDock ? .regular : .accessory)
+ lastShowDockIcon = showDock
+ }
+
+ if force {
+ setupMenuBar()
+ }
+ }
+
+ /// Keep app chrome in sync when language changes from any entry point.
+ private func observeLanguageChanges() {
+ NotificationCenter.default.addObserver(
+ forName: .appLanguageDidChange,
+ object: nil, queue: .main
+ ) { [weak self] _ in
+ self?.setupMenuBar()
+ self?.configureApplicationMenuWhenAvailable()
}
}
// MARK: - Launch at Login (LaunchAgent, zero permissions)
private static let launchAgentLabel = "com.apptag.launcher"
+ static var supportsLaunchAtLogin: Bool {
+ ProcessInfo.processInfo.environment["APP_SANDBOX_CONTAINER_ID"] == nil
+ }
private static var launchAgentURL: URL {
FileManager.default.homeDirectoryForCurrentUser
@@ -90,6 +133,7 @@
}
static func enableLaunchAtLogin() {
+ guard supportsLaunchAtLogin else { return }
let plist: [String: Any] = [
"Label": Self.launchAgentLabel,
"ProgramArguments": ["open", Bundle.main.bundlePath, "--hide"],
@@ -107,6 +151,7 @@
}
static func disableLaunchAtLogin() {
+ guard supportsLaunchAtLogin else { return }
let uid = getuid()
let task = Process()
task.launchPath = "/bin/launchctl"
@@ -118,6 +163,12 @@
/// On first launch, enable login item by default via LaunchAgent.
/// Does NOT require App Management permission.
private func setupLaunchAtLogin() {
+ guard Self.supportsLaunchAtLogin else {
+ if UserDefaults.standard.object(forKey: "launchAtLogin") == nil {
+ UserDefaults.standard.set(false, forKey: "launchAtLogin")
+ }
+ return
+ }
let key = "launchAtLogin"
if UserDefaults.standard.object(forKey: key) == nil {
UserDefaults.standard.set(true, forKey: key)
@@ -128,30 +179,28 @@
// MARK: - Menu Bar
private func setupMenuBar() {
- // Remove old status item if re-creating (language switch, etc.)
- if let existing = statusItem {
- NSStatusBar.system.removeStatusItem(existing)
- }
- statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
+ removeMenuBarItem()
+ statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
+ guard let statusItem else { return }
+ statusItem.isVisible = true
if let button = statusItem.button {
- button.image = NSImage(
- systemSymbolName: "tag.fill",
- accessibilityDescription: "Apptag"
- )
- button.toolTip = "Apptag — Tag-based app launcher"
+ button.image = makeMenuBarIcon()
+ button.imageScaling = .scaleProportionallyDown
+ button.imagePosition = .imageOnly
+ button.toolTip = "TagLauncher — Tag-based app launcher"
button.action = #selector(toggleOverlay)
button.target = self
}
let menu = NSMenu()
- menu.addItem(
- NSMenuItem(
- title: "\(tr("menu.show")) ⇧⌥Space",
- action: #selector(toggleOverlay),
- keyEquivalent: ""
- )
+ let showItem = NSMenuItem(
+ title: showAppListMenuTitle,
+ action: #selector(toggleOverlay),
+ keyEquivalent: ""
)
+ showItem.target = self
+ menu.addItem(showItem)
menu.addItem(.separator())
// Version display
@@ -199,6 +248,168 @@
statusItem.menu = menu
}
+ private func makeMenuBarIcon() -> NSImage {
+ let image = NSImage(size: NSSize(width: 18, height: 18))
+ image.lockFocus()
+ defer { image.unlockFocus() }
+
+ NSColor.black.setFill()
+
+ let tagBody = NSBezierPath()
+ tagBody.move(to: NSPoint(x: 5.0, y: 2.2))
+ tagBody.line(to: NSPoint(x: 15.6, y: 5.0))
+ tagBody.line(to: NSPoint(x: 12.8, y: 15.8))
+ tagBody.line(to: NSPoint(x: 2.2, y: 13.0))
+ tagBody.close()
+ tagBody.fill()
+
+ NSGraphicsContext.current?.compositingOperation = .clear
+ NSBezierPath(ovalIn: NSRect(x: 10.9, y: 11.2, width: 3.2, height: 3.2)).fill()
+ NSGraphicsContext.current?.compositingOperation = .sourceOver
+
+ image.isTemplate = true
+ image.accessibilityDescription = "TagLauncher"
+ return image
+ }
+
+ private var showAppListMenuTitle: String {
+ "\(tr("menu.showAppList")) \(Self.showAppListShortcutGlyphs)"
+ }
+
+ private func observeApplicationMenuChanges() {
+ NotificationCenter.default.addObserver(
+ forName: NSApplication.didBecomeActiveNotification,
+ object: NSApp, queue: .main
+ ) { [weak self] _ in
+ self?.configureApplicationMenuWhenAvailable(retries: 4)
+ }
+
+ NotificationCenter.default.addObserver(
+ forName: NSMenu.didAddItemNotification,
+ object: nil, queue: .main
+ ) { [weak self] notification in
+ guard let self,
+ !self.isConfiguringApplicationMenu,
+ let menu = notification.object as? NSMenu,
+ menu === NSApp.mainMenu?.items.first?.submenu
+ else { return }
+ self.configureApplicationMenuWhenAvailable(retries: 2)
+ }
+ }
+
+ private func configureApplicationMenuWhenAvailable(retries: Int = 20) {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in
+ guard let self else { return }
+ guard NSApp.mainMenu?.items.first?.submenu != nil else {
+ if retries > 0 {
+ self.configureApplicationMenuWhenAvailable(retries: retries - 1)
+ }
+ return
+ }
+
+ self.configureApplicationMenu()
+ if retries > 0 && self.applicationMenuNeedsCleanup() {
+ self.configureApplicationMenuWhenAvailable(retries: retries - 1)
+ }
+ }
+ }
+
+ private func configureApplicationMenu() {
+ guard !isConfiguringApplicationMenu else { return }
+ guard let appMenu = NSApp.mainMenu?.items.first?.submenu else { return }
+
+ isConfiguringApplicationMenu = true
+ defer { isConfiguringApplicationMenu = false }
+
+ removeUnusedDefaultItems(from: appMenu)
+ upsertShowAppListItem(in: appMenu)
+ normalizeSeparators(in: appMenu)
+ }
+
+ private func applicationMenuNeedsCleanup() -> Bool {
+ guard let appMenu = NSApp.mainMenu?.items.first?.submenu else { return true }
+ let hasUnusedDefaultItems = appMenu.items.contains(where: isUnusedDefaultApplicationMenuItem)
+ let hasShowAppListItem = appMenu.items.contains {
+ $0.identifier == Self.showAppListMenuItemIdentifier
+ }
+ return hasUnusedDefaultItems || !hasShowAppListItem
+ }
+
+ private func removeUnusedDefaultItems(from menu: NSMenu) {
+ for item in menu.items.reversed() where isUnusedDefaultApplicationMenuItem(item) {
+ menu.removeItem(item)
+ }
+ }
+
+ private func isUnusedDefaultApplicationMenuItem(_ item: NSMenuItem) -> Bool {
+ if let servicesMenu = NSApp.servicesMenu, item.submenu === servicesMenu {
+ return true
+ }
+ return item.action == #selector(NSApplication.hide(_:))
+ || item.action == #selector(NSApplication.hideOtherApplications(_:))
+ || item.action == #selector(NSApplication.unhideAllApplications(_:))
+ }
+
+ private func upsertShowAppListItem(in menu: NSMenu) {
+ if let existingItem = menu.items.first(where: { $0.identifier == Self.showAppListMenuItemIdentifier }) {
+ configureShowAppListItem(existingItem)
+ return
+ }
+
+ let item = NSMenuItem()
+ item.identifier = Self.showAppListMenuItemIdentifier
+ configureShowAppListItem(item)
+
+ if let settingsIndex = menu.items.firstIndex(where: { isSettingsMenuItem($0) }) {
+ menu.insertItem(item, at: settingsIndex + 1)
+ } else if let firstSeparatorIndex = menu.items.firstIndex(where: { $0.isSeparatorItem }) {
+ menu.insertItem(item, at: firstSeparatorIndex)
+ } else {
+ menu.addItem(item)
+ }
+ }
+
+ private func configureShowAppListItem(_ item: NSMenuItem) {
+ item.title = showAppListMenuTitle
+ item.action = #selector(toggleOverlay)
+ item.target = self
+ item.keyEquivalent = ""
+ item.keyEquivalentModifierMask = []
+ item.isEnabled = true
+ }
+
+ private func isSettingsMenuItem(_ item: NSMenuItem) -> Bool {
+ item.action == Selector(("showSettingsWindow:"))
+ || item.action == #selector(openPreferences)
+ || item.title == tr("menu.preferences")
+ }
+
+ private func normalizeSeparators(in menu: NSMenu) {
+ var indexesToRemove: [Int] = []
+ var previousWasSeparator = false
+
+ for (index, item) in menu.items.enumerated() {
+ guard item.isSeparatorItem else {
+ previousWasSeparator = false
+ continue
+ }
+ if index == 0 || index == menu.items.count - 1 || previousWasSeparator {
+ indexesToRemove.append(index)
+ }
+ previousWasSeparator = true
+ }
+
+ for index in indexesToRemove.reversed() {
+ menu.removeItem(at: index)
+ }
+ }
+
+ private func removeMenuBarItem() {
+ guard let statusItem else { return }
+ NSStatusBar.system.removeStatusItem(statusItem)
+ self.statusItem = nil
+ }
+
// MARK: - Overlay Window
@objc private func toggleOverlay() {
@@ -221,17 +432,28 @@
overlayWindow?.setFrame(screen.frame, display: true)
overlayWindow?.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.maximumWindow)))
- // Local key monitor: catch Escape while overlay is up
- NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [weak self] event in
+ installOverlayKeyMonitor()
+
+ overlayWindow?.makeKeyAndOrderFront(nil)
+ overlayWindow?.orderFrontRegardless()
+ }
+
+ private func installOverlayKeyMonitor() {
+ guard overlayKeyMonitor == nil else { return }
+ overlayKeyMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [weak self] event in
if event.keyCode == 53 { // Escape
self?.hideOverlay()
return nil
}
return event
}
+ }
- overlayWindow?.makeKeyAndOrderFront(nil)
- overlayWindow?.orderFrontRegardless()
+ private func removeOverlayKeyMonitor() {
+ if let monitor = overlayKeyMonitor {
+ NSEvent.removeMonitor(monitor)
+ overlayKeyMonitor = nil
+ }
}
private func makeOverlayWindow(on screen: NSScreen) -> NSWindow {
@@ -269,7 +491,11 @@
private func hideOverlay(force: Bool = false) {
guard force || !isInEditMode else { return }
+ if let settingsWindow, settingsWindow.parent == overlayWindow {
+ detachSettingsWindow(settingsWindow)
+ }
overlayWindow?.orderOut(nil)
+ removeOverlayKeyMonitor()
if force {
overlayWindow = nil
}
@@ -297,7 +523,7 @@
hotkeyRef = ref
if status != noErr {
- print("[Apptag] Hotkey registration failed: \(status). Falling back to menu bar only.")
+ print("[TagLauncher] Hotkey registration failed: \(status). Falling back to menu bar only.")
return
}
@@ -343,8 +569,8 @@
!self.isInEditMode
else { return }
- // Settings/Preferences window → float it above overlay for real-time preview
- if NSApp.windows.contains(keyWindow) {
+ // Settings/Preferences window -> float it above overlay for real-time preview.
+ if self.isSettingsWindowCandidate(keyWindow) {
self.prepareSettingsWindow(keyWindow)
return
}
@@ -353,18 +579,74 @@
}
}
- /// Settings must always float above the overlay so changes can be previewed live.
+ /// Settings must always appear centered over the current overlay view and float above it.
private func prepareSettingsWindow(_ window: NSWindow) {
- if overlayWindow?.isVisible == true {
- let overlayLevel = overlayWindow?.level.rawValue ?? NSWindow.Level.screenSaver.rawValue
- window.level = NSWindow.Level(rawValue: overlayLevel + 1)
- window.orderFrontRegardless()
+ let settingsSize = NSSize(width: 880, height: 460)
+ window.identifier = NSUserInterfaceItemIdentifier("TagLauncherPreferencesWindow")
+ window.minSize = settingsSize
+ window.maxSize = settingsSize
+ if abs(window.frame.width - settingsSize.width) > 0.5 || abs(window.frame.height - settingsSize.height) > 0.5 {
+ window.setFrame(
+ NSRect(origin: window.frame.origin, size: settingsSize),
+ display: false
+ )
}
- if settingsWindow == nil {
- window.minSize = NSSize(width: 660, height: 380)
- window.maxSize = NSSize(width: 660, height: CGFloat.greatestFiniteMagnitude)
+
+ if let overlayWindow, overlayWindow.isVisible {
+ center(window, over: overlayWindow.frame)
+ attachSettingsWindow(window, to: overlayWindow)
+ window.level = overlayWindow.level
+ } else if let screen = screenUnderMouse() {
+ center(window, over: screen.visibleFrame)
+ window.level = .floating
+ detachSettingsWindow(window)
}
+
+ var behavior = window.collectionBehavior
+ behavior.remove(.canJoinAllSpaces)
+ behavior.formUnion([.fullScreenAuxiliary, .moveToActiveSpace])
+ window.collectionBehavior = behavior
+ window.makeKeyAndOrderFront(nil)
+ window.orderFrontRegardless()
settingsWindow = window
+ }
+
+ private func attachSettingsWindow(_ window: NSWindow, to overlayWindow: NSWindow) {
+ if window.parent != overlayWindow {
+ window.parent?.removeChildWindow(window)
+ overlayWindow.addChildWindow(window, ordered: .above)
+ }
+ }
+
+ private func detachSettingsWindow(_ window: NSWindow) {
+ window.parent?.removeChildWindow(window)
+ }
+
+ private func isSettingsWindowCandidate(_ window: NSWindow) -> Bool {
+ if window == settingsWindow { return true }
+ if window.identifier?.rawValue == "TagLauncherPreferencesWindow" { return true }
+ guard NSApp.windows.contains(window),
+ window != overlayWindow,
+ window.isVisible,
+ !(window is NSPanel)
+ else { return false }
+ return true
+ }
+
+ private func center(_ window: NSWindow, over rect: NSRect) {
+ let frame = window.frame
+ let origin = NSPoint(
+ x: rect.midX - frame.width / 2,
+ y: rect.midY - frame.height / 2
+ )
+ window.setFrameOrigin(origin)
+ }
+
+ private func screenUnderMouse() -> NSScreen? {
+ let mousePoint = NSEvent.mouseLocation
+ return NSScreen.screens.first(where: {
+ NSMouseInRect(mousePoint, $0.frame, false)
+ }) ?? NSScreen.main ?? NSScreen.screens.first
}
/// Clean up settingsWindow reference when the Settings window closes.
@@ -378,6 +660,7 @@
let closingWindow = notification.object as? NSWindow,
closingWindow == self.settingsWindow
else { return }
+ self.detachSettingsWindow(closingWindow)
self.settingsWindow = nil
}
}
@@ -385,7 +668,7 @@
/// Track whether the overlay is in edit mode to suppress auto-dismiss.
private func observeEditMode() {
NotificationCenter.default.addObserver(
- forName: .apptagEditModeChanged,
+ forName: .tagLauncherEditModeChanged,
object: nil,
queue: .main
) { [weak self] notification in
@@ -395,11 +678,23 @@
@objc private func openPreferences() {
// Don't hide overlay — keep it visible for real-time setting preview.
+ if let overlayWindow, overlayWindow.isVisible {
+ overlayWindow.makeKeyAndOrderFront(nil)
+ overlayWindow.orderFrontRegardless()
+ }
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
- DispatchQueue.main.async { [weak self] in
+ prepareSettingsWindowWhenAvailable(retries: 10)
+ }
+
+ private func prepareSettingsWindowWhenAvailable(retries: Int) {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.03) { [weak self] in
guard let self else { return }
- for window in NSApp.windows where window != self.overlayWindow {
- self.prepareSettingsWindow(window)
+ let candidates = NSApp.windows.filter { window in
+ self.isSettingsWindowCandidate(window)
+ }
+ candidates.forEach { self.prepareSettingsWindow($0) }
+ if candidates.isEmpty && retries > 0 {
+ self.prepareSettingsWindowWhenAvailable(retries: retries - 1)
}
}
}
@@ -407,8 +702,6 @@
@objc private func switchLanguage(_ sender: NSMenuItem) {
guard let code = sender.representedObject as? String else { return }
L10n.switchTo(code)
- // Rebuild menu to update checkmarks
- setupMenuBar()
}
}
@@ -488,6 +781,13 @@
// MARK: - Preferences View
struct PreferencesView: View {
+ private let settingsWindowWidth: CGFloat = 880
+ private let settingsContentWidth: CGFloat = 820
+ private let generalContentWidth: CGFloat = 720
+ private let generalLabelWidth: CGFloat = 190
+ private let generalControlWidth: CGFloat = 500
+ private let compactPickerWidth: CGFloat = 320
+
@AppStorage("tagFontSize") private var tagFontSize: Double = 18
@AppStorage("iconSize") private var iconSize: Double = 56
@AppStorage("tagPosition") private var tagPosition = "left"
@@ -496,6 +796,9 @@
@AppStorage("hideAppNames") private var hideAppNames = false
@AppStorage("showDockIcon") private var showDockIcon = false
@AppStorage("launchAtLogin") private var launchAtLogin = true
+ @AppStorage("showUncommonAppBubbles") private var showUncommonAppBubbles = true
+ @State private var selectedLanguage = L10n.currentCode
+ @State private var isRefreshingLanguage = false
@State private var allApps: [AppInfo] = []
@State private var tagColors: [String: Int] = [:]
@@ -515,14 +818,15 @@
private func exportTags() {
let panel = NSSavePanel()
panel.title = tr("settings.export")
- panel.nameFieldStringValue = "Apptag-tags.json"
+ panel.nameFieldStringValue = "TagLauncher-tags.json"
panel.allowedContentTypes = [.json]
panel.begin { response in
guard response == .OK, let url = panel.url else { return }
do {
try TagDatabase.exportTo(url)
} catch {
- fputs("[Apptag] Export failed: \(error)\n", stderr)
+ fputs("[TagLauncher] Export failed: \(error)\n", stderr)
+ showDataAlert(title: tr("settings.exportFailed"), message: error.localizedDescription)
}
}
}
@@ -538,15 +842,18 @@
_ = try TagDatabase.importFrom(url)
scanApps()
} catch {
- fputs("[Apptag] Import failed: \(error)\n", stderr)
- // Show alert on failure
- let alert = NSAlert()
- alert.messageText = tr("settings.importFailed")
- alert.informativeText = error.localizedDescription
- alert.alertStyle = .warning
- alert.runModal()
+ fputs("[TagLauncher] Import failed: \(error)\n", stderr)
+ showDataAlert(title: tr("settings.importFailed"), message: error.localizedDescription)
}
}
+ }
+
+ private func showDataAlert(title: String, message: String) {
+ let alert = NSAlert()
+ alert.messageText = title
+ alert.informativeText = message
+ alert.alertStyle = .warning
+ alert.runModal()
}
private var appVersion: String {
@@ -555,22 +862,126 @@
private var buildVersion: String {
Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "?"
}
+ private var languageColumns: [GridItem] {
+ [
+ GridItem(.flexible(minimum: 220), spacing: 18, alignment: .top),
+ GridItem(.flexible(minimum: 220), spacing: 18, alignment: .top),
+ ]
+ }
+ private var displayModeColumns: [GridItem] {
+ [
+ GridItem(.flexible(minimum: 220), spacing: 10, alignment: .top),
+ GridItem(.flexible(minimum: 220), spacing: 10, alignment: .top),
+ ]
+ }
+ private var displayModeOptions: [(id: String, title: String)] {
+ [
+ ("flat", tr("settings.flat")),
+ ("container", tr("settings.container")),
+ ("coloredContainer", tr("settings.coloredContainer")),
+ ("gridContainer", tr("settings.gridContainer")),
+ ("coloredGridContainer", tr("settings.coloredGridContainer")),
+ ]
+ }
+ private var containerDisplayModeOptions: [(id: String, title: String)] {
+ Array(displayModeOptions.dropFirst())
+ }
+
+ private func generalSettingRow<Control: View>(
+ _ label: String,
+ description: String,
+ @ViewBuilder control: () -> Control
+ ) -> some View {
+ HStack(alignment: .top, spacing: 16) {
+ Text(label)
+ .font(.system(size: 14, weight: .semibold))
+ .multilineTextAlignment(.trailing)
+ .lineLimit(2)
+ .minimumScaleFactor(0.86)
+ .frame(width: generalLabelWidth, alignment: .trailing)
+ .padding(.top, 5)
+
+ VStack(alignment: .leading, spacing: 6) {
+ control()
+ .frame(width: generalControlWidth, alignment: .leading)
+ Text(description)
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ .multilineTextAlignment(.leading)
+ .fixedSize(horizontal: false, vertical: true)
+ .frame(width: generalControlWidth, alignment: .leading)
+ }
+ }
+ .frame(width: generalContentWidth, alignment: .leading)
+ }
var body: some View {
- TabView {
- // Tab 1: General
+ ZStack {
+ TabView {
+ // Tab 1: Language
+ VStack(alignment: .leading, spacing: 10) {
+ Text(tr("settings.language"))
+ .font(.headline)
+ Text(tr("settings.languageDesc"))
+ .font(.caption)
+ .foregroundStyle(.secondary)
+
+ ScrollView {
+ LazyVGrid(columns: languageColumns, alignment: .leading, spacing: 6) {
+ ForEach(L10n.supported, id: \.code) { language in
+ Button {
+ selectedLanguage = language.code
+ } label: {
+ HStack(spacing: 8) {
+ Image(systemName: selectedLanguage == language.code ? "checkmark" : "circle")
+ .font(.system(size: 12, weight: .semibold))
+ .foregroundStyle(selectedLanguage == language.code ? Color.accentColor : Color.secondary.opacity(0.28))
+ .frame(width: 16)
+ Text(language.name)
+ .foregroundStyle(.primary)
+ .lineLimit(1)
+ .truncationMode(.tail)
+ Spacer(minLength: 0)
+ }
+ .padding(.horizontal, 8)
+ .padding(.vertical, 5)
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+ .accessibilityLabel("\(tr("settings.languagePicker")) \(language.name)")
+ }
+ }
+ .padding(.vertical, 4)
+ }
+ .frame(maxHeight: 250)
+
+ Spacer(minLength: 0)
+ ShortcutHintView()
+ .frame(maxWidth: .infinity, alignment: .center)
+ .padding(.bottom, 2)
+ }
+ .frame(maxWidth: settingsContentWidth, alignment: .leading)
+ .tabItem { Label(tr("settings.language"), systemImage: "globe") }
+ .padding()
+
+ // Tab 2: General
VStack(alignment: .leading, spacing: 0) {
// Toggle row — centered as a rectangular block
HStack(spacing: 20) {
- Toggle(tr("settings.launchAtLogin"), isOn: $launchAtLogin)
- .onChange(of: launchAtLogin) { _, enabled in
- if enabled {
- AppDelegate.enableLaunchAtLogin()
- } else {
- AppDelegate.disableLaunchAtLogin()
+ if AppDelegate.supportsLaunchAtLogin {
+ Toggle(tr("settings.launchAtLogin"), isOn: $launchAtLogin)
+ .onChange(of: launchAtLogin) { _, enabled in
+ if enabled {
+ AppDelegate.enableLaunchAtLogin()
+ } else {
+ AppDelegate.disableLaunchAtLogin()
+ }
}
- }
+ }
Toggle(tr("settings.showInDock"), isOn: $showDockIcon)
+ .onChange(of: showDockIcon) { _, _ in
+ AppDelegate.refreshChromeSettings()
+ }
Toggle(tr("settings.hideAppNames"), isOn: $hideAppNames)
}
.frame(maxWidth: .infinity, alignment: .center)
@@ -579,79 +990,68 @@
Divider()
.padding(.bottom, 16)
- // Two-column layout: each row label (right-aligned) + controls (left-aligned)
- // All pickers and descriptions share the same left edge
- VStack(spacing: 16) {
- HStack(alignment: .top, spacing: 16) {
- Text(tr("settings.appListStyle"))
- .frame(width: 130, alignment: .trailing)
- VStack(alignment: .leading, spacing: 4) {
- Picker("", selection: $displayMode) {
- Text(tr("settings.flat")).tag("flat")
- Text(tr("settings.container")).tag("container")
- Text(tr("settings.coloredContainer")).tag("coloredContainer")
+ VStack(spacing: 18) {
+ generalSettingRow(tr("settings.appListStyle"), description: tr("settings.flatDesc")) {
+ VStack(spacing: 8) {
+ DisplayModeOptionButton(
+ mode: "flat",
+ title: tr("settings.flat"),
+ isSelected: displayMode == "flat"
+ ) {
+ displayMode = "flat"
}
- .pickerStyle(.segmented)
- .frame(width: 360, alignment: .leading)
- Text(tr("settings.flatDesc"))
- .font(.caption).foregroundStyle(.secondary)
- .fixedSize(horizontal: false, vertical: true)
- }
- }
- HStack(alignment: .top, spacing: 16) {
- Text(tr("settings.tagPosition"))
- .frame(width: 130, alignment: .trailing)
- VStack(alignment: .leading, spacing: 4) {
- Picker("", selection: $tagPosition) {
- Text(tr("settings.left")).tag("left")
- Text(tr("settings.right")).tag("right")
- Text(tr("settings.top")).tag("top")
- }
- .pickerStyle(.segmented)
- .frame(width: 280, alignment: .leading)
- Text(tr("settings.tagPosDesc"))
- .font(.caption).foregroundStyle(.secondary)
- .fixedSize(horizontal: false, vertical: true)
- }
- }
- HStack(alignment: .top, spacing: 16) {
- Text(tr("settings.tagFontSize"))
- .frame(width: 130, alignment: .trailing)
- VStack(alignment: .leading, spacing: 4) {
- Picker("", selection: $tagFontSize) {
- ForEach([16.0, 18.0, 20.0, 22.0, 24.0, 26.0], id: \.self) { size in
- Text("\(Int(size))").tag(size)
+
+ LazyVGrid(columns: displayModeColumns, alignment: .leading, spacing: 8) {
+ ForEach(containerDisplayModeOptions, id: \.id) { option in
+ DisplayModeOptionButton(
+ mode: option.id,
+ title: option.title,
+ isSelected: displayMode == option.id
+ ) {
+ displayMode = option.id
+ }
}
}
- .pickerStyle(.segmented)
- .frame(width: 280, alignment: .leading)
- Text(tr("settings.tagFontDesc"))
- .font(.caption).foregroundStyle(.secondary)
- .fixedSize(horizontal: false, vertical: true)
}
+ .frame(width: generalControlWidth, alignment: .leading)
}
- HStack(alignment: .top, spacing: 16) {
- Text(tr("settings.iconSize"))
- .frame(width: 130, alignment: .trailing)
- VStack(alignment: .leading, spacing: 4) {
- Picker("", selection: $iconSize) {
- ForEach([40.0, 48.0, 56.0, 64.0, 72.0, 80.0], id: \.self) { size in
- Text("\(Int(size))").tag(size)
- }
- }
- .pickerStyle(.segmented)
- .frame(width: 280, alignment: .leading)
- Text(tr("settings.iconSizeDesc"))
- .font(.caption).foregroundStyle(.secondary)
- .fixedSize(horizontal: false, vertical: true)
+
+ generalSettingRow(tr("settings.tagPosition"), description: tr("settings.tagPosDesc")) {
+ Picker("", selection: $tagPosition) {
+ Text(tr("settings.left")).tag("left")
+ Text(tr("settings.right")).tag("right")
+ Text(tr("settings.top")).tag("top")
}
+ .pickerStyle(.segmented)
+ .frame(width: compactPickerWidth, alignment: .leading)
+ }
+
+ generalSettingRow(tr("settings.tagFontSize"), description: tr("settings.tagFontDesc")) {
+ Picker("", selection: $tagFontSize) {
+ ForEach([16.0, 18.0, 20.0, 22.0, 24.0, 26.0], id: \.self) { size in
+ Text("\(Int(size))").tag(size)
+ }
+ }
+ .pickerStyle(.segmented)
+ .frame(width: compactPickerWidth, alignment: .leading)
+ }
+
+ generalSettingRow(tr("settings.iconSize"), description: tr("settings.iconSizeDesc")) {
+ Picker("", selection: $iconSize) {
+ ForEach([40.0, 48.0, 56.0, 64.0, 72.0, 80.0], id: \.self) { size in
+ Text("\(Int(size))").tag(size)
+ }
+ }
+ .pickerStyle(.segmented)
+ .frame(width: compactPickerWidth, alignment: .leading)
}
}
}
+ .frame(maxWidth: generalContentWidth, alignment: .center)
.padding()
.tabItem { Label(tr("settings.general"), systemImage: "gearshape") }
- // Tab 2: Tags
+ // Tab 3: Tags
VStack(spacing: 0) {
TagEditorView(
tagColors: $tagColors,
@@ -663,9 +1063,25 @@
.tabItem { Label(tr("settings.tags"), systemImage: "tag.fill") }
.onAppear { scanApps() }
- // Tab 3: Data
- Form {
- Section {
+ // Tab 4: Data
+ VStack(spacing: 0) {
+ Spacer(minLength: 54)
+
+ VStack(alignment: .leading, spacing: 5) {
+ Toggle(tr("settings.uncommonBubble"), isOn: $showUncommonAppBubbles)
+ .font(.system(size: 13, weight: .medium))
+ Text(tr("settings.uncommonBubbleDesc"))
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ .frame(width: 420, alignment: .leading)
+
+ Spacer(minLength: 28)
+
+ VStack(alignment: .leading, spacing: 8) {
+ Text(tr("settings.backup"))
+ .font(.headline)
HStack(spacing: 12) {
Button(tr("settings.export")) { exportTags() }
.buttonStyle(.bordered)
@@ -675,50 +1091,240 @@
Text(tr("settings.backupDesc"))
.font(.caption)
.foregroundStyle(.secondary)
- } header: {
- Text(tr("settings.backup"))
}
+ .frame(width: 420, alignment: .leading)
+
+ Spacer(minLength: 42)
+ ShortcutHintView()
+ .frame(maxWidth: .infinity, alignment: .center)
+ Spacer(minLength: 18)
}
.tabItem { Label(tr("settings.data"), systemImage: "externaldrive.fill") }
.padding()
- // Tab 4: About
- Form {
- Section {
- HStack {
- if let icon = NSImage(named: NSImage.applicationIconName) {
- Image(nsImage: icon)
- .resizable()
- .frame(width: 128, height: 128)
- }
- VStack(alignment: .leading, spacing: 4) {
- Text("Apptag")
- .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)
+ // Tab 5: About
+ VStack(spacing: 0) {
+ Spacer(minLength: 72)
- Divider()
- .padding(.vertical, 4)
-
- Text("万物之中,希望最美")
- .font(.caption)
- .foregroundStyle(.secondary)
- Text("永桔@2026-18602102518")
- .font(.caption)
- .foregroundStyle(.secondary)
- }
+ HStack {
+ if let icon = NSImage(named: NSImage.applicationIconName) {
+ Image(nsImage: icon)
+ .resizable()
+ .frame(width: 128, height: 128)
}
- .padding(.leading, 100)
+ 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)
+
+ Divider()
+ .padding(.vertical, 4)
+
+ Text("万物之中,希望最美")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ Text("永桔@2026-18602102518")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ }
}
+ .frame(width: 560, alignment: .leading)
+
+ Spacer(minLength: 30)
+ ShortcutHintView()
+ .frame(maxWidth: .infinity, alignment: .center)
+ Spacer(minLength: 18)
}
.tabItem { Label(tr("settings.about"), systemImage: "info.circle") }
.padding()
+ }
+ .onChange(of: selectedLanguage) { _, code in
+ L10n.switchTo(code)
+ }
+ .onReceive(NotificationCenter.default.publisher(for: .appLanguageDidChange)) { notification in
+ if let code = notification.userInfo?["code"] as? String {
+ selectedLanguage = code
+ }
+ showLanguageRefresh()
+ }
+
+ if isRefreshingLanguage {
+ ZStack {
+ Color(nsColor: .windowBackgroundColor)
+ .opacity(0.84)
+ Image(systemName: "arrow.clockwise")
+ .font(.system(size: 30, weight: .regular))
+ .symbolRenderingMode(.hierarchical)
+ .foregroundStyle(.secondary)
+ }
+ .transition(.opacity)
+ }
}
- .frame(minWidth: 660, maxWidth: 660, minHeight: 380)
+ .frame(width: settingsWindowWidth, height: 460)
+ }
+
+ private func showLanguageRefresh() {
+ isRefreshingLanguage = true
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
+ withAnimation(.easeOut(duration: 0.18)) {
+ isRefreshingLanguage = false
+ }
+ }
+ }
+}
+
+private struct DisplayModeOptionButton: View {
+ let mode: String
+ let title: String
+ let isSelected: Bool
+ let action: () -> Void
+
+ var body: some View {
+ Button(action: action) {
+ HStack(spacing: 7) {
+ DisplayModeGlyph(mode: mode, isSelected: isSelected)
+ .frame(width: 24, height: 18)
+ Text(title)
+ .font(.system(size: 13, weight: .semibold))
+ .multilineTextAlignment(.center)
+ .lineLimit(2)
+ .minimumScaleFactor(0.82)
+ .foregroundStyle(isSelected ? Color.white : Color.primary)
+ .frame(maxWidth: .infinity)
+ }
+ .frame(maxWidth: .infinity, minHeight: 34)
+ .padding(.horizontal, 9)
+ .padding(.vertical, 2)
+ .background(
+ RoundedRectangle(cornerRadius: 7, style: .continuous)
+ .fill(isSelected ? Color.accentColor : Color(nsColor: .controlBackgroundColor))
+ )
+ .overlay(
+ RoundedRectangle(cornerRadius: 7, style: .continuous)
+ .stroke(isSelected ? Color.accentColor : Color.secondary.opacity(0.18), lineWidth: 1)
+ )
+ .contentShape(RoundedRectangle(cornerRadius: 7, style: .continuous))
+ }
+ .buttonStyle(.plain)
+ .accessibilityLabel(title)
+ }
+}
+
+private struct DisplayModeGlyph: View {
+ let mode: String
+ let isSelected: Bool
+
+ var body: some View {
+ switch mode {
+ case "flat":
+ HStack(spacing: 2) {
+ cell(index: 0, width: 5, height: 5, colored: false)
+ cell(index: 1, width: 5, height: 5, colored: false)
+ cell(index: 2, width: 5, height: 5, colored: false)
+ }
+ case "gridContainer", "coloredGridContainer":
+ let colored = mode == "coloredGridContainer"
+ VStack(spacing: 2) {
+ HStack(spacing: 2) {
+ cell(index: 0, width: 7, height: 6, colored: colored)
+ cell(index: 1, width: 7, height: 6, colored: colored)
+ }
+ HStack(spacing: 2) {
+ cell(index: 2, width: 7, height: 6, colored: colored)
+ cell(index: 3, width: 7, height: 6, colored: colored)
+ }
+ }
+ default:
+ let colored = mode == "coloredContainer"
+ HStack(alignment: .bottom, spacing: 2) {
+ cell(index: 0, width: 5, height: 8, colored: colored)
+ cell(index: 1, width: 5, height: 14, colored: colored)
+ cell(index: 2, width: 5, height: 10, colored: colored)
+ }
+ }
+ }
+
+ private func cell(index: Int, width: CGFloat, height: CGFloat, colored: Bool) -> some View {
+ let fill = fillColor(index: index, colored: colored)
+ let stroke = isSelected ? Color.white.opacity(0.95) : Color.secondary.opacity(0.35)
+ return RoundedRectangle(cornerRadius: 1.8, style: .continuous)
+ .fill(fill)
+ .overlay(
+ RoundedRectangle(cornerRadius: 1.8, style: .continuous)
+ .stroke(stroke, lineWidth: 0.8)
+ )
+ .frame(width: width, height: height)
+ }
+
+ private func fillColor(index: Int, colored: Bool) -> Color {
+ if isSelected {
+ return Color.white.opacity(colored ? 0.9 : 0.18)
+ }
+ guard colored else {
+ return Color.secondary.opacity(0.12)
+ }
+ let palette: [Color] = [.green, .purple, .blue, .orange]
+ return palette[index % palette.count].opacity(0.78)
+ }
+}
+
+private struct ShortcutHintView: View {
+ var body: some View {
+ HStack(spacing: 12) {
+ ShortcutKeycap(symbol: "⌥")
+ Text("+")
+ .font(.system(size: 22, weight: .semibold))
+ .foregroundStyle(.tertiary)
+ ShortcutKeycap(symbol: "⇧")
+ Text("+")
+ .font(.system(size: 22, weight: .semibold))
+ .foregroundStyle(.tertiary)
+ SpacebarKeycap()
+ }
+ .accessibilityLabel("⌥ ⇧ Space")
+ .allowsHitTesting(false)
+ }
+}
+
+private struct ShortcutKeycap: View {
+ let symbol: String
+
+ var body: some View {
+ Text(symbol)
+ .font(.system(size: 36, weight: .medium))
+ .foregroundStyle(.secondary)
+ .frame(width: 74, height: 58)
+ .background(KeycapBackground())
+ }
+}
+
+private struct SpacebarKeycap: View {
+ var body: some View {
+ ZStack {
+ KeycapBackground()
+ Capsule()
+ .fill(Color.secondary.opacity(0.38))
+ .frame(width: 72, height: 3)
+ .offset(y: 13)
+ }
+ .frame(width: 190, height: 58)
+ }
+}
+
+private struct KeycapBackground: View {
+ var body: some View {
+ RoundedRectangle(cornerRadius: 10, style: .continuous)
+ .fill(Color(nsColor: .controlBackgroundColor))
+ .overlay(
+ RoundedRectangle(cornerRadius: 10, style: .continuous)
+ .stroke(Color.primary.opacity(0.12), lineWidth: 1)
+ )
+ .shadow(color: .black.opacity(0.10), radius: 8, x: 0, y: 3)
}
}
--
Gitblit v1.9.3