Refactor profile management

This commit is contained in:
世界
2025-12-03 11:15:56 +08:00
parent adf4e5c75c
commit 727136f187
22 changed files with 1635 additions and 787 deletions
+16
View File
@@ -95,4 +95,20 @@ public enum ProfileManager {
try UInt32(Profile.fetchCount(db))
}
}
public nonisolated static func uniqueName(_ baseName: String) async throws -> String {
let profiles = try await list()
let existingNames = Set(profiles.map(\.name))
if !existingNames.contains(baseName) {
return baseName
}
var counter = 1
while true {
let candidate = "\(baseName) (\(counter))"
if !existingNames.contains(candidate) {
return candidate
}
counter += 1
}
}
}