fix:修复空路径问题

This commit is contained in:
SengokuCola
2025-05-29 22:02:54 +08:00
parent d0f9cf9c7b
commit a23ca3c43d
2 changed files with 10 additions and 15 deletions

View File

@@ -6,6 +6,7 @@ import os
from typing import Any, Dict, List from typing import Any, Dict, List
import threading import threading
import time import time
import sys
class ConfigEditor: class ConfigEditor:
def __init__(self, root): def __init__(self, root):
@@ -103,6 +104,8 @@ class ConfigEditor:
except Exception as e: except Exception as e:
messagebox.showerror("错误", f"加载配置文件失败: {str(e)}") messagebox.showerror("错误", f"加载配置文件失败: {str(e)}")
self.config = {} self.config = {}
# 自动打开配置路径窗口
self.open_path_config()
def load_env_vars(self): def load_env_vars(self):
"""加载并解析环境变量文件""" """加载并解析环境变量文件"""
@@ -395,7 +398,7 @@ class ConfigEditor:
providers.append(prefix) providers.append(prefix)
# print(f"添加provider: {prefix}") # print(f"添加provider: {prefix}")
print(f"最终providers列表: {providers}") # print(f"最终providers列表: {providers}")
if providers: if providers:
# 创建模型名称标签(大字体) # 创建模型名称标签(大字体)
model_name = var.get() if var.get() else providers[0] model_name = var.get() if var.get() else providers[0]
@@ -688,7 +691,7 @@ class ConfigEditor:
k = path[1] k = path[1]
if k.endswith("_BASE_URL") or k.endswith("_KEY"): if k.endswith("_BASE_URL") or k.endswith("_KEY"):
new_env_dict[k] = self.get_widget_value(widget) new_env_dict[k] = self.get_widget_value(widget)
# 3. 遍历原有行替换目标key并且只保留当前界面有的key # 3. 遍历原有行替换目标key保留所有其他内容
result_lines = [] result_lines = []
found_keys = set() found_keys = set()
for line in old_lines: for line in old_lines:
@@ -697,9 +700,6 @@ class ConfigEditor:
if k in new_env_dict: if k in new_env_dict:
result_lines.append(f"{k}={new_env_dict[k]}\n") result_lines.append(f"{k}={new_env_dict[k]}\n")
found_keys.add(k) found_keys.add(k)
elif k.endswith("_BASE_URL") or k.endswith("_KEY"):
# 跳过界面上已删除的key不保留
continue
else: else:
result_lines.append(line) result_lines.append(line)
else: else:
@@ -999,11 +999,6 @@ class ConfigEditor:
msg_frame = ttk.Frame(notebook) msg_frame = ttk.Frame(notebook)
notebook.add(msg_frame, text="消息服务") notebook.add(msg_frame, text="消息服务")
self.create_section_widgets(msg_frame, "maim_message", self.config["maim_message"], ["maim_message"]) self.create_section_widgets(msg_frame, "maim_message", self.config["maim_message"], ["maim_message"])
# 关键词反应栏
if "keyword_reaction" in self.config:
kw_frame = ttk.Frame(notebook)
notebook.add(kw_frame, text="关键词反应")
self.create_section_widgets(kw_frame, "keyword_reaction", self.config["keyword_reaction"], ["keyword_reaction"])
# 消息接收栏 # 消息接收栏
if "message_receive" in self.config: if "message_receive" in self.config:
recv_frame = ttk.Frame(notebook) recv_frame = ttk.Frame(notebook)
@@ -1065,8 +1060,12 @@ class ConfigEditor:
# 刷新显示 # 刷新显示
self.refresh_config() self.refresh_config()
messagebox.showinfo("成功", "路径配置已更新") messagebox.showinfo("成功", "路径配置已更新,程序将重新启动")
dialog.destroy() dialog.destroy()
# 重启程序
self.root.quit()
os.execv(sys.executable, ['python'] + sys.argv)
def browse_bot_config(): def browse_bot_config():
file_path = filedialog.askopenfilename( file_path = filedialog.askopenfilename(

View File

@@ -56,7 +56,6 @@ description = "自动退出专注聊天的阈值,越低越容易退出专注
path = "chat.exit_focus_threshold" path = "chat.exit_focus_threshold"
type = "number" type = "number"
[[editor.quick_settings.items]] [[editor.quick_settings.items]]
name = "思考间隔focus模式" name = "思考间隔focus模式"
description = "思考的时间间隔(秒),可以有效减少消耗" description = "思考的时间间隔(秒),可以有效减少消耗"
@@ -87,9 +86,6 @@ description = "是否在回复后显示当前聊天模式"
path = "experimental.debug_show_chat_mode" path = "experimental.debug_show_chat_mode"
type = "bool" type = "bool"
[translations.sections.inner] [translations.sections.inner]
name = "版本" name = "版本"
description = "麦麦的内部配置,包含版本号等信息。此部分仅供显示,不可编辑。" description = "麦麦的内部配置,包含版本号等信息。此部分仅供显示,不可编辑。"