mirror of
https://github.com/lencx/ChatGPT.git
synced 2024-10-01 01:06:13 -04:00
chore: control center
This commit is contained in:
parent
cd7d5fab63
commit
396dc0b762
@ -47,10 +47,6 @@ pub fn init(context: &Context<EmbeddedAssets>) -> Menu {
|
||||
let preferences_menu = Submenu::new(
|
||||
"Preferences",
|
||||
Menu::with_items([
|
||||
CustomMenuItem::new("dashboard".to_string(), "Dashboard")
|
||||
.accelerator("CmdOrCtrl+D")
|
||||
.into(),
|
||||
MenuItem::Separator.into(),
|
||||
Submenu::new(
|
||||
"Theme",
|
||||
Menu::new()
|
||||
@ -73,6 +69,9 @@ pub fn init(context: &Context<EmbeddedAssets>) -> Menu {
|
||||
CustomMenuItem::new("inject_script".to_string(), "Inject Script")
|
||||
.accelerator("CmdOrCtrl+J")
|
||||
.into(),
|
||||
CustomMenuItem::new("control_center".to_string(), "Control Center")
|
||||
.accelerator("CmdOrCtrl+Shift+P")
|
||||
.into(),
|
||||
MenuItem::Separator.into(),
|
||||
CustomMenuItem::new("go_conf".to_string(), "Go to Config")
|
||||
.accelerator("CmdOrCtrl+Shift+G")
|
||||
@ -160,7 +159,7 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||
|
||||
match menu_id {
|
||||
// Preferences
|
||||
"dashboard" => app.get_window("main").unwrap().show().unwrap(),
|
||||
"control_center" => app.get_window("main").unwrap().show().unwrap(),
|
||||
"restart" => tauri::api::process::restart(&app.env()),
|
||||
"inject_script" => open(&app, script_path),
|
||||
"go_conf" => utils::open_file(utils::chat_root()),
|
||||
|
@ -21,7 +21,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
|
||||
.initialization_script(include_str!("../assets/jspdf.js"))
|
||||
.initialization_script(include_str!("../assets/core.js"))
|
||||
.initialization_script(include_str!("../assets/export.js"))
|
||||
.user_agent(&chat_conf.ua_pc)
|
||||
.user_agent(&chat_conf.ua_window)
|
||||
.build()?;
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
@ -37,7 +37,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
|
||||
.initialization_script(include_str!("../assets/jspdf.js"))
|
||||
.initialization_script(include_str!("../assets/core.js"))
|
||||
.initialization_script(include_str!("../assets/export.js"))
|
||||
.user_agent(&chat_conf.ua_pc)
|
||||
.user_agent(&chat_conf.ua_window)
|
||||
.build()?;
|
||||
|
||||
Ok(())
|
||||
|
@ -17,7 +17,7 @@ pub fn mini_window(handle: &tauri::AppHandle) {
|
||||
.initialization_script(include_str!("../assets/jspdf.js"))
|
||||
.initialization_script(include_str!("../assets/core.js"))
|
||||
.initialization_script(include_str!("../assets/export.js"))
|
||||
.user_agent(&chat_conf.ua_phone)
|
||||
.user_agent(&chat_conf.ua_tray)
|
||||
.build()
|
||||
.unwrap()
|
||||
.hide()
|
||||
|
@ -19,8 +19,8 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{
|
||||
"titlebar": true,
|
||||
"default_origin": "https://chat.openai.com",
|
||||
"origin": "https://chat.openai.com",
|
||||
"ua_pc": "",
|
||||
"ua_phone": ""
|
||||
"ua_window": "",
|
||||
"ua_tray": ""
|
||||
}"#;
|
||||
pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{
|
||||
"always_on_top": false,
|
||||
@ -28,8 +28,8 @@ pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{
|
||||
"titlebar": false,
|
||||
"default_origin": "https://chat.openai.com",
|
||||
"origin": "https://chat.openai.com",
|
||||
"ua_pc": "",
|
||||
"ua_phone": ""
|
||||
"ua_window": "",
|
||||
"ua_tray": ""
|
||||
}"#;
|
||||
|
||||
pub struct ChatState {
|
||||
@ -51,8 +51,8 @@ pub struct ChatConfJson {
|
||||
pub theme: String,
|
||||
pub default_origin: String,
|
||||
pub origin: String,
|
||||
pub ua_pc: String,
|
||||
pub ua_phone: String,
|
||||
pub ua_window: String,
|
||||
pub ua_tray: String,
|
||||
}
|
||||
|
||||
impl ChatConfJson {
|
||||
|
@ -9,6 +9,7 @@ mod utils;
|
||||
|
||||
use app::{cmd, menu, setup};
|
||||
use conf::{ChatConfJson, ChatState};
|
||||
use tauri::Manager;
|
||||
|
||||
fn main() {
|
||||
ChatConfJson::init();
|
||||
|
22
src/view/General.tsx
vendored
22
src/view/General.tsx
vendored
@ -1,12 +1,21 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Form, Radio, Switch, Input, Button, Space, message } from 'antd';
|
||||
import { Form, Radio, Switch, Input, Button, Space, message, Tooltip } from 'antd';
|
||||
import { QuestionCircleOutlined } from '@ant-design/icons';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { platform } from '@tauri-apps/api/os';
|
||||
import { ask } from '@tauri-apps/api/dialog';
|
||||
import { relaunch } from '@tauri-apps/api/process';
|
||||
import { clone, pick, isEqual } from 'lodash';
|
||||
|
||||
const restartNames = ['origin', 'ua_window', 'ua_tray']
|
||||
const restartNames = ['theme', 'titlebar', 'origin', 'ua_window', 'ua_tray'];
|
||||
|
||||
const OriginLabel = ({ url }: { url: string }) => {
|
||||
return (
|
||||
<span>
|
||||
Switch Origin <Tooltip title={`Default: ${url}`}><QuestionCircleOutlined /></Tooltip>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export default function General() {
|
||||
const [form] = Form.useForm();
|
||||
@ -27,17 +36,12 @@ export default function General() {
|
||||
form.setFieldsValue(clone(chatConf));
|
||||
}, [chatConf])
|
||||
|
||||
console.log('«28» /src/view/General.tsx ~> ', chatConf);
|
||||
|
||||
|
||||
const onCancel = () => {
|
||||
form.setFieldsValue(chatConf);
|
||||
};
|
||||
|
||||
const onFinish = async (values: any) => {
|
||||
await invoke('form_confirm', { data: values, label: 'main' });
|
||||
console.log('«33» /src/view/General.tsx ~> ', pick(chatConf, restartNames), pick(values, restartNames));
|
||||
|
||||
if (!isEqual(pick(chatConf, restartNames), pick(values, restartNames))) {
|
||||
const isOk = await ask(`Configuration saved successfully, whether to restart?`, {
|
||||
title: 'ChatGPT Preferences'
|
||||
@ -71,13 +75,13 @@ export default function General() {
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
)}
|
||||
<Form.Item label="Switch Origin" name="origin">
|
||||
<Form.Item label={<OriginLabel url={chatConf?.default_origin} />} name="origin">
|
||||
<Input placeholder="https://chat.openai.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label="User Agent (Window)" name="ua_window">
|
||||
<Input.TextArea autoSize={{ minRows: 2, maxRows: 4 }} placeholder="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" />
|
||||
</Form.Item>
|
||||
<Form.Item label="User Agent (Tray)" name="ua_tray">
|
||||
<Form.Item label="User Agent (SystemTray)" name="ua_tray">
|
||||
<Input.TextArea autoSize={{ minRows: 2, maxRows: 4 }} placeholder="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" />
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
|
Loading…
Reference in New Issue
Block a user