From dc287cff3df23c9988b4441955d54795e7d4702d Mon Sep 17 00:00:00 2001 From: Christophe Vila Date: Sat, 19 Sep 2026 16:53:49 +0200 Subject: [PATCH] feat: add KeePassIconMapper (iconIndex -> SF Symbol) Co-Authored-By: Claude Haiku 4.5 Claude-Session: https://claude.ai/code/session_01WYqycDFsynHH9VnnK7LNSf --- .../MyPassCore/Icons/KeePassIconMapper.swift | 34 +++++++++++++++++++ .../KeePassIconMapperTests.swift | 16 +++++++++ 2 files changed, 50 insertions(+) create mode 100644 MyPassCore/Sources/MyPassCore/Icons/KeePassIconMapper.swift create mode 100644 MyPassCore/Tests/MyPassCoreTests/KeePassIconMapperTests.swift diff --git a/MyPassCore/Sources/MyPassCore/Icons/KeePassIconMapper.swift b/MyPassCore/Sources/MyPassCore/Icons/KeePassIconMapper.swift new file mode 100644 index 0000000..bf72736 --- /dev/null +++ b/MyPassCore/Sources/MyPassCore/Icons/KeePassIconMapper.swift @@ -0,0 +1,34 @@ +import Foundation + +/// Maps KeePass's standard icon palette (indices 0-68) to an approximate SF Symbol. +/// This is a best-effort visual match, not the actual KeePass icon artwork -- MyPass's +/// data model only stores the numeric iconIndex, not custom icon images. +public enum KeePassIconMapper { + private static let symbolsByIndex: [Int: String] = [ + 0: "key.fill", + 1: "globe", + 2: "exclamationmark.triangle.fill", + 3: "server.rack", + 4: "doc.on.clipboard.fill", + 5: "pencil", + 6: "camera.fill", + 7: "wrench.fill", + 8: "person.text.rectangle.fill", + 9: "externaldrive.fill", + 10: "creditcard.fill", + 11: "chevron.left.forwardslash.chevron.right", + 12: "chart.bar.fill", + 13: "gamecontroller.fill", + 14: "envelope.fill", + 15: "folder.fill", + 16: "lock.fill", + 17: "checkmark.circle.fill", + 18: "star.fill", + 19: "house.fill", + 20: "network", + ] + + public static func symbolName(forIconIndex index: Int) -> String { + symbolsByIndex[index] ?? "key.fill" + } +} diff --git a/MyPassCore/Tests/MyPassCoreTests/KeePassIconMapperTests.swift b/MyPassCore/Tests/MyPassCoreTests/KeePassIconMapperTests.swift new file mode 100644 index 0000000..cca77f8 --- /dev/null +++ b/MyPassCore/Tests/MyPassCoreTests/KeePassIconMapperTests.swift @@ -0,0 +1,16 @@ +import XCTest +@testable import MyPassCore + +final class KeePassIconMapperTests: XCTestCase { + func test_knownIndex_returnsMappedSymbol() { + XCTAssertEqual(KeePassIconMapper.symbolName(forIconIndex: 14), "envelope.fill") + } + + func test_indexZero_isKeyFill() { + XCTAssertEqual(KeePassIconMapper.symbolName(forIconIndex: 0), "key.fill") + } + + func test_unmappedIndex_fallsBackToKeyFill() { + XCTAssertEqual(KeePassIconMapper.symbolName(forIconIndex: 999), "key.fill") + } +}