From 847ae72e49b231b42146afc065a801977b247fa4 Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Fri, 24 Apr 2026 22:52:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20LLM=20=E8=AE=BE=E7=BD=AE=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E6=B7=BB=E5=8A=A0=E3=80=8C=E4=BB=8E=E5=8F=A6=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E9=85=8D=E7=BD=AE=E5=A4=8D=E5=88=B6=E3=80=8D=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/UI/SettingsWindow.swift | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Sources/UI/SettingsWindow.swift b/Sources/UI/SettingsWindow.swift index 0504cc9..9f75434 100644 --- a/Sources/UI/SettingsWindow.swift +++ b/Sources/UI/SettingsWindow.swift @@ -9,6 +9,7 @@ final class SettingsWindow: NSWindow { private let modelField: NSTextField private let testButton: NSButton private let saveButton: NSButton + private let copyFromOtherButton: NSButton private let statusLabel: NSTextField init(mode: LLMMode) { @@ -19,9 +20,10 @@ final class SettingsWindow: NSWindow { modelField = NSTextField(frame: .zero) testButton = NSButton(title: "Test", target: nil, action: nil) saveButton = NSButton(title: "Save", target: nil, action: nil) + copyFromOtherButton = NSButton(title: "", target: nil, action: nil) statusLabel = NSTextField(labelWithString: "") - let windowRect = NSRect(x: 0, y: 0, width: 420, height: 280) + let windowRect = NSRect(x: 0, y: 0, width: 420, height: 320) super.init( contentRect: windowRect, styleMask: [.titled, .closable, .miniaturizable], @@ -111,6 +113,13 @@ final class SettingsWindow: NSWindow { saveButton.target = self saveButton.action = #selector(saveConfig) + let otherModeName = mode == .input ? "AI 助手" : "语音输入" + copyFromOtherButton.title = "从「\(otherModeName)」复制配置" + copyFromOtherButton.bezelStyle = .rounded + copyFromOtherButton.translatesAutoresizingMaskIntoConstraints = false + copyFromOtherButton.target = self + copyFromOtherButton.action = #selector(copyFromOther) + statusLabel.font = .systemFont(ofSize: 11) statusLabel.textColor = .secondaryLabelColor statusLabel.alignment = .center @@ -136,6 +145,7 @@ final class SettingsWindow: NSWindow { content.addSubview(grid) content.addSubview(buttonStack) + content.addSubview(copyFromOtherButton) content.addSubview(statusLabel) NSLayoutConstraint.activate([ @@ -147,7 +157,10 @@ final class SettingsWindow: NSWindow { buttonStack.centerXAnchor.constraint(equalTo: content.centerXAnchor), buttonStack.widthAnchor.constraint(equalToConstant: 220), - statusLabel.topAnchor.constraint(equalTo: buttonStack.bottomAnchor, constant: 12), + copyFromOtherButton.topAnchor.constraint(equalTo: buttonStack.bottomAnchor, constant: 10), + copyFromOtherButton.centerXAnchor.constraint(equalTo: content.centerXAnchor), + + statusLabel.topAnchor.constraint(equalTo: copyFromOtherButton.bottomAnchor, constant: 10), statusLabel.centerXAnchor.constraint(equalTo: content.centerXAnchor), statusLabel.widthAnchor.constraint(equalToConstant: 380) ]) @@ -194,6 +207,19 @@ final class SettingsWindow: NSWindow { } } + @objc private func copyFromOther() { + let otherMode: LLMMode = mode == .input ? .assist : .input + let config = Config.shared.getLLMConfig(for: otherMode) + baseURLField.stringValue = config.baseURL + apiKeyField.stringValue = config.apiKey + modelField.stringValue = config.model + statusLabel.stringValue = "✅ 已复制「\(otherMode == .input ? "语音输入" : "AI 助手")」的配置" + statusLabel.textColor = .systemGreen + DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { [weak self] in + self?.statusLabel.stringValue = "" + } + } + @objc private func saveConfig() { let url = baseURLField.stringValue.trimmingCharacters(in: CharacterSet(charactersIn: "/")) let key = apiKeyField.stringValue