From 7db2326a984e1eaf10e1ee52e8ca057a0f4bc469 Mon Sep 17 00:00:00 2001
From: Ariver <ar@MacBook-Air.local>
Date: Wed, 06 May 2026 16:33:22 +0800
Subject: [PATCH] checkpoint: v3.0.4 — 修复新建 tag 消失的 bug:addNewTag 写 TagDatabase.createTag 持久化
---
Apptag/TagEditorView.swift | 5 ++---
X-screencap/SCR-20260506-okgg.jpeg | 0
Apptag/DataLayer.swift | 9 +++++++++
X-screencap/SCR-20260505-qwvz.png | 0
X-screencap/SCR-20260505-shyg.png | 0
X-screencap/SCR-20260505-tmjo.png | 0
X-screencap/SCR-20260506-ohtf.jpeg | 0
7 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/Apptag/DataLayer.swift b/Apptag/DataLayer.swift
index 7dc2cbd..4f2248f 100644
--- a/Apptag/DataLayer.swift
+++ b/Apptag/DataLayer.swift
@@ -299,6 +299,15 @@
TagDatabase.save(store)
}
+ /// Create a new tag definition (no app assignments yet).
+ static func createTag(_ name: String, color: Int) {
+ var store = TagDatabase.load()
+ guard store.tags[name] == nil else { return }
+ store.tags[name] = TagDatabase.TagDef(color: color)
+ if !store.tagOrder.contains(name) { store.tagOrder.append(name) }
+ TagDatabase.save(store)
+ }
+
/// Annotate scanned apps with tags from the database.
static func annotate(apps: [AppInfo]) -> [AppInfo] {
let store = TagDatabase.load()
diff --git a/Apptag/TagEditorView.swift b/Apptag/TagEditorView.swift
index 96e839d..4661760 100644
--- a/Apptag/TagEditorView.swift
+++ b/Apptag/TagEditorView.swift
@@ -147,13 +147,12 @@
// SIP-protected apps where xattr write silently fails.
}
- /// Add a new tag name+color to the local registry only (no xattr write until
- /// the tag is assigned to apps via "Edit App Categories").
- /// Does NOT call onRefresh — would overwrite tagColors with scan results.
+ /// Add a new tag name+color and persist to the database.
private func addNewTag() {
let name = newTagNameText.trimmingCharacters(in: .whitespaces)
guard !name.isEmpty else { return }
tagColors[name] = newTagColorIndex
+ TagEditor.createTag(name, color: newTagColorIndex)
addingNewTag = false
newTagNameText = ""
}
diff --git a/X-screencap/SCR-20260505-qwvz.png b/X-screencap/SCR-20260505-qwvz.png
new file mode 100644
index 0000000..2a3dd74
--- /dev/null
+++ b/X-screencap/SCR-20260505-qwvz.png
Binary files differ
diff --git a/X-screencap/SCR-20260505-shyg.png b/X-screencap/SCR-20260505-shyg.png
new file mode 100644
index 0000000..ee9bde5
--- /dev/null
+++ b/X-screencap/SCR-20260505-shyg.png
Binary files differ
diff --git a/X-screencap/SCR-20260505-tmjo.png b/X-screencap/SCR-20260505-tmjo.png
new file mode 100644
index 0000000..525264a
--- /dev/null
+++ b/X-screencap/SCR-20260505-tmjo.png
Binary files differ
diff --git a/X-screencap/SCR-20260506-ohtf.jpeg b/X-screencap/SCR-20260506-ohtf.jpeg
new file mode 100644
index 0000000..b3cc5de
--- /dev/null
+++ b/X-screencap/SCR-20260506-ohtf.jpeg
Binary files differ
diff --git a/X-screencap/SCR-20260506-okgg.jpeg b/X-screencap/SCR-20260506-okgg.jpeg
new file mode 100644
index 0000000..33e341c
--- /dev/null
+++ b/X-screencap/SCR-20260506-okgg.jpeg
Binary files differ
--
Gitblit v1.9.3