feat: add AppSettings with API key, shortcut, output mode, delay

This commit is contained in:
Carsten Abele 2026-04-07 19:39:48 +02:00
parent 186b6a0a7e
commit 9ec7b94345

View file

@ -0,0 +1,45 @@
import SwiftUI
import Carbon.HIToolbox
enum OutputMode: String, CaseIterable {
case textBox = "Text Window"
case cursorInjection = "Type at Cursor"
}
final class AppSettings: ObservableObject {
static let shared = AppSettings()
@AppStorage("apiKey") var apiKey: String = ""
@AppStorage("outputMode") var outputMode: OutputMode = .textBox
@AppStorage("streamingDelayMs") var streamingDelayMs: Int = 480
@AppStorage("shortcutKeyCode") private var shortcutKeyCodeStorage: Int = 0
@AppStorage("shortcutModifiers") private var shortcutModifiersStorage: Int = 0
var shortcutKeyCode: UInt16 {
get { UInt16(shortcutKeyCodeStorage) }
set { shortcutKeyCodeStorage = Int(newValue) }
}
var shortcutModifiers: UInt {
get { UInt(bitPattern: shortcutModifiersStorage) }
set { shortcutModifiersStorage = Int(bitPattern: newValue) }
}
var hasAPIKey: Bool { !apiKey.isEmpty }
var hasShortcut: Bool { shortcutKeyCode != 0 || shortcutModifiers != 0 }
var shortcutDisplayString: String {
guard hasShortcut else { return "Not Set" }
var parts: [String] = []
let mods = NSEvent.ModifierFlags(rawValue: shortcutModifiers)
if mods.contains(.control) { parts.append("") }
if mods.contains(.option) { parts.append("") }
if mods.contains(.shift) { parts.append("") }
if mods.contains(.command) { parts.append("") }
if let scalar = Unicode.Scalar(shortcutKeyCode) {
parts.append(String(Character(scalar)).uppercased())
}
return parts.joined()
}
}