1
0
mirror of https://github.com/lencx/ChatGPT.git synced 2024-10-01 01:06:13 -04:00

Add "Reset to defaults" in Control Center

This commit is contained in:
tiankai 2023-01-03 17:35:20 +08:00
parent b370fd187c
commit 6bd52fe961
4 changed files with 33 additions and 0 deletions

View File

@ -38,6 +38,11 @@ pub fn get_chat_conf() -> ChatConfJson {
ChatConfJson::get_chat_conf() ChatConfJson::get_chat_conf()
} }
#[command]
pub fn reset_chat_conf() -> ChatConfJson {
ChatConfJson::reset_chat_conf()
}
#[command] #[command]
pub fn form_confirm(_app: AppHandle, data: serde_json::Value) { pub fn form_confirm(_app: AppHandle, data: serde_json::Value) {
ChatConfJson::amend(&serde_json::json!(data), None).unwrap(); ChatConfJson::amend(&serde_json::json!(data), None).unwrap();

View File

@ -129,6 +129,17 @@ impl ChatConfJson {
} }
} }
pub fn reset_chat_conf() -> Self {
let conf_file = ChatConfJson::conf_path();
let content = if cfg!(target_os = "macos") {
DEFAULT_CHAT_CONF_MAC
} else {
DEFAULT_CHAT_CONF
};
fs::write(&conf_file, content).unwrap();
serde_json::from_str(content).unwrap()
}
// https://users.rust-lang.org/t/updating-object-fields-given-dynamic-json/39049/3 // https://users.rust-lang.org/t/updating-object-fields-given-dynamic-json/39049/3
pub fn amend(new_rules: &Value, app: Option<tauri::AppHandle>) -> Result<()> { pub fn amend(new_rules: &Value, app: Option<tauri::AppHandle>) -> Result<()> {
let config = ChatConfJson::get_chat_conf(); let config = ChatConfJson::get_chat_conf();

View File

@ -56,6 +56,7 @@ async fn main() {
cmd::download, cmd::download,
cmd::open_link, cmd::open_link,
cmd::get_chat_conf, cmd::get_chat_conf,
cmd::reset_chat_conf,
cmd::form_cancel, cmd::form_cancel,
cmd::form_confirm, cmd::form_confirm,
cmd::form_msg, cmd::form_msg,

16
src/view/General.tsx vendored
View File

@ -58,6 +58,19 @@ export default function General() {
form.setFieldsValue(chatConf); form.setFieldsValue(chatConf);
}; };
const onReset = async () => {
const chatData = await invoke('reset_chat_conf');
setChatConf(chatData);
const isOk = await ask(`Configuration reset successfully, whether to restart?`, {
title: 'ChatGPT Preferences'
});
if (isOk) {
relaunch();
return;
}
message.success('Configuration reset successfully');
};
const onFinish = async (values: any) => { const onFinish = async (values: any) => {
if (!isEqual(omit(chatConf, ['default_origin']), values)) { if (!isEqual(omit(chatConf, ['default_origin']), values)) {
await invoke('form_confirm', { data: values, label: 'main' }); await invoke('form_confirm', { data: values, label: 'main' });
@ -115,10 +128,13 @@ export default function General() {
<Form.Item> <Form.Item>
<Space size={20}> <Space size={20}>
<Button onClick={onCancel}>Cancel</Button> <Button onClick={onCancel}>Cancel</Button>
<Button type="primary" htmlType="submit"> <Button type="primary" htmlType="submit">
Submit Submit
</Button> </Button>
<a onClick={onReset}>Reset to defaults</a>
</Space> </Space>
</Form.Item> </Form.Item>
</Form> </Form>
</> </>