Files
voice-cat/clients/apple/macOS/VoiceCatMac/Models/ServerListStore.swift
Talon 33169b01fa feat(macos): VoiceCatMac AppKit client + fix xcodebuild
The previous "shipped" claim was false — xcodebuild had never been run and
the macOS app source was never committed. This commit adds the 17 Swift
source files + xcodeproj and fixes three real defect classes so Debug and
Release both build clean:

1. MainWindowController.swift compile errors:
   - NSAccessibility.post arg order (element:notification:userInfo:)
   - NSAccessibilityPriorityMedium -> NSAccessibilityPriorityLevel.medium
   - StreamSummary.streamId -> .id (Identifiable conformance)
   - drop redundant VoiceCatResult.description extension
2. Linker: add -lc++ to OTHER_LDFLAGS (libvoicecat-fat.a is C++20; pure-Swift
   app target has no .cpp sources so libc++ wasn't pulled in — swift test
   passed because Package.swift testTarget has linkerSettings: c++).
3. Release config: add ONLY_ACTIVE_ARCH=YES (XCFramework only has arm64).

Verified: clean Debug + Release builds, otool -L shows libc++.1.dylib,
nm shows _vc_client_create/_vc_version_string, app launches and runs.
2026-06-18 15:26:47 +02:00

70 lines
2.4 KiB
Swift

import Foundation
import Security
enum ServerListStore {
static var appSupportURL: URL {
let url = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
return url.appendingPathComponent("VoiceCat", isDirectory: true)
}
static var serversURL: URL {
appSupportURL.appendingPathComponent("servers.json")
}
static var tofuStorePath: String {
appSupportURL.appendingPathComponent("tofu_pins.txt").path
}
static func load() -> [SavedServer] {
try? FileManager.default.createDirectory(at: appSupportURL, withIntermediateDirectories: true)
guard let data = try? Data(contentsOf: serversURL),
let list = try? JSONDecoder().decode([SavedServer].self, from: data) else { return [] }
return list
}
static func save(_ servers: [SavedServer]) {
try? FileManager.default.createDirectory(at: appSupportURL, withIntermediateDirectories: true)
if let data = try? JSONEncoder().encode(servers) {
try? data.write(to: serversURL, options: .atomic)
}
}
// MARK: - Keychain
static func savePassword(_ password: String, tag: String) {
guard let data = password.data(using: .utf8) else { return }
deletePassword(tag: tag)
let query: [CFString: Any] = [
kSecClass: kSecClassGenericPassword,
kSecAttrService: "cat.voice.VoiceCatMac",
kSecAttrAccount: tag,
kSecValueData: data,
]
SecItemAdd(query as CFDictionary, nil)
}
static func loadPassword(tag: String) -> String? {
let query: [CFString: Any] = [
kSecClass: kSecClassGenericPassword,
kSecAttrService: "cat.voice.VoiceCatMac",
kSecAttrAccount: tag,
kSecReturnData: true,
kSecMatchLimit: kSecMatchLimitOne,
]
var result: AnyObject?
guard SecItemCopyMatching(query as CFDictionary, &result) == errSecSuccess,
let data = result as? Data,
let password = String(data: data, encoding: .utf8) else { return nil }
return password
}
static func deletePassword(tag: String) {
let query: [CFString: Any] = [
kSecClass: kSecClassGenericPassword,
kSecAttrService: "cat.voice.VoiceCatMac",
kSecAttrAccount: tag,
]
SecItemDelete(query as CFDictionary)
}
}