Skip to content

Commit a2ddba0

Browse files
Lee Seongjooclaude
andcommitted
Pre-fill API key fields with the current key + reveal toggle
The ElevenLabs/Gemini key fields started empty even when a key was set ("설정됨"), so the key wasn't visible/editable. On appear, pre-fill from Secrets; a KeyField masks by default with an eye toggle to reveal/verify. "키 저장" no longer clears the field. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent bdbf938 commit a2ddba0

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

‎Sources/UI/SettingsView.swift‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct SettingsView: View {
2727
.onAppear {
2828
if app.ollamaModels.isEmpty { app.refreshOllamaModels() }
2929
if app.voices.isEmpty && app.keyPresent { app.refreshVoices() }
30+
keyInput = Secrets.elevenLabsKey ?? "" // pre-fill so the current key is visible/editable
31+
geminiKeyInput = Secrets.geminiKey ?? ""
3032
}
3133
.onChange(of: app.localBaseURL) { _, _ in app.saveSettings() }
3234
.onChange(of: app.normalizeEnabled) { _, _ in app.saveSettings() }
@@ -94,10 +96,9 @@ struct SettingsView: View {
9496
Section("연결") {
9597
LabeledContent("API 키", value: app.keyPresent ? "설정됨" : "없음")
9698
LabeledContent("연결", value: app.connectionStatus.isEmpty ? "—" : app.connectionStatus)
97-
labeledField("ElevenLabs API 키", placeholder: "sk_…", secure: true, text: $keyInput,
98-
hint: "App Support에 저장됩니다.")
99+
KeyField(label: "ElevenLabs API 키", text: $keyInput, hint: "App Support에 저장됩니다.")
99100
HStack {
100-
Button("키 저장") { app.saveKey(keyInput); keyInput = "" }
101+
Button("키 저장") { app.saveKey(keyInput) }
101102
.disabled(keyInput.trimmingCharacters(in: .whitespaces).isEmpty)
102103
Button { app.refreshVoices() } label: {
103104
Label("연결 테스트 / 보이스 새로고침", systemImage: "arrow.clockwise")
@@ -144,10 +145,10 @@ struct SettingsView: View {
144145
labeledField("엔드포인트", placeholder: GeminiNormalizer.defaultBaseURL,
145146
text: $app.geminiBaseURL,
146147
hint: "API 루트. 끝에 /models/{모델}:generateContent 가 붙습니다. 프록시·게이트웨이 사용 시 변경.")
147-
labeledField("API 키", placeholder: "AIza…", secure: true, text: $geminiKeyInput,
148-
hint: app.geminiKeyPresent ? "현재: 설정됨 (App Support)" : "현재: 없음")
148+
KeyField(label: "API 키", text: $geminiKeyInput,
149+
hint: app.geminiKeyPresent ? "현재: 설정됨 (App Support)" : "현재: 없음")
149150
HStack {
150-
Button("키 저장") { app.saveGeminiKey(geminiKeyInput); geminiKeyInput = "" }
151+
Button("키 저장") { app.saveGeminiKey(geminiKeyInput) }
151152
.disabled(geminiKeyInput.trimmingCharacters(in: .whitespaces).isEmpty)
152153
Button("연결 확인 / 모델 목록") { app.refreshGeminiModels() }
153154
Spacer()
@@ -189,6 +190,33 @@ struct SettingsView: View {
189190
}
190191
}
191192

193+
/// API-key field: pre-filled with the current key, masked by default with an
194+
/// eye toggle to reveal/verify it.
195+
private struct KeyField: View {
196+
let label: String
197+
@Binding var text: String
198+
var hint: String? = nil
199+
@State private var reveal = false
200+
var body: some View {
201+
VStack(alignment: .leading, spacing: 4) {
202+
Text(label).font(.caption).foregroundStyle(.secondary)
203+
HStack(spacing: 6) {
204+
Group {
205+
if reveal { TextField("", text: $text) }
206+
else { SecureField("", text: $text) }
207+
}
208+
.labelsHidden().textFieldStyle(.roundedBorder)
209+
Button { reveal.toggle() } label: {
210+
Image(systemName: reveal ? "eye.slash" : "eye")
211+
}
212+
.buttonStyle(.plain).foregroundStyle(.secondary)
213+
.help(reveal ? "키 숨기기" : "키 보기")
214+
}
215+
if let hint { Text(hint).font(.caption2).foregroundStyle(.tertiary) }
216+
}
217+
}
218+
}
219+
192220
@ViewBuilder
193221
private func labeledField(_ label: String, placeholder: String, secure: Bool = false,
194222
text: Binding<String>, hint: String? = nil) -> some View {

0 commit comments

Comments
 (0)