feat: add AppSettings with API key, shortcut, output mode, delay
This commit is contained in:
parent
186b6a0a7e
commit
9ec7b94345
1 changed files with 45 additions and 0 deletions
45
MyVoxtral/MyVoxtral/Models/AppSettings.swift
Normal file
45
MyVoxtral/MyVoxtral/Models/AppSettings.swift
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue