fix: reload tint colors while running
This commit is contained in:
@@ -4,6 +4,8 @@ import AppKit
|
||||
final class TranslationSettingsController: NSViewController {
|
||||
private let keyField = NSSecureTextField()
|
||||
private let status = NSTextField(wrappingLabelWithString: "")
|
||||
private var statusIsError = false
|
||||
private var themeObservation: ThemeObservation?
|
||||
private let credentials: TranslationController.Credentials
|
||||
|
||||
init(credentials: TranslationController.Credentials = .keychain) {
|
||||
@@ -55,6 +57,14 @@ final class TranslationSettingsController: NSViewController {
|
||||
for label in [status, myMemory, openAI] {
|
||||
label.widthAnchor.constraint(equalTo: stack.widthAnchor).isActive = true
|
||||
}
|
||||
themeObservation = ThemeObservation { [weak self] in
|
||||
save.contentTintColor = ThemePalette.accent
|
||||
forget.contentTintColor = ThemePalette.accent
|
||||
myMemory.textColor = ThemePalette.secondaryText
|
||||
openAI.textColor = ThemePalette.secondaryText
|
||||
guard let self else { return }
|
||||
self.status.textColor = self.statusIsError ? ThemePalette.error : ThemePalette.secondaryText
|
||||
}
|
||||
do {
|
||||
setStatus(try credentials.load() == nil ? "No OpenAI API key saved." : "OpenAI API key saved in Keychain.")
|
||||
} catch { setStatus(error.localizedDescription, isError: true) }
|
||||
@@ -84,6 +94,7 @@ final class TranslationSettingsController: NSViewController {
|
||||
}
|
||||
|
||||
private func setStatus(_ message: String, isError: Bool = false) {
|
||||
statusIsError = isError
|
||||
status.stringValue = message
|
||||
status.textColor = isError ? ThemePalette.error : ThemePalette.secondaryText
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user