diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index 1556ebb..9e1aece 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -235,7 +235,7 @@ pub fn menu_handler(event: WindowMenuEvent) { utils::run_check_update(app, false, None); } // Preferences - "control_center" => window::control_window(&app), + "control_center" => window::control_window(app.clone()), "restart" => tauri::api::process::restart(&app.env()), "inject_script" => open(&app, script_path), "go_conf" => utils::open_file(utils::chat_root()), @@ -431,7 +431,7 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) { } } SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { - "control_center" => window::control_window(&app), + "control_center" => window::control_window(app), "restart" => tauri::api::process::restart(&handle.env()), "show_dock_icon" => { ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": false }), Some(app)).unwrap(); diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs index 54064b6..3aedf0f 100644 --- a/src-tauri/src/app/setup.rs +++ b/src-tauri/src/app/setup.rs @@ -6,7 +6,7 @@ use wry::application::accelerator::Accelerator; pub fn init(app: &mut App) -> std::result::Result<(), Box> { info!("stepup"); let chat_conf = ChatConfJson::get_chat_conf(); - let url = chat_conf.origin.to_string(); + let url = chat_conf.main_origin.to_string(); let theme = ChatConfJson::theme(); let handle = app.app_handle(); @@ -50,7 +50,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box } else { let app = app.handle(); tauri::async_runtime::spawn(async move { - let link = if chat_conf.dashboard { + let link = if chat_conf.main_dashboard { "index.html" } else { &url @@ -65,7 +65,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box main_win = main_win.hidden_title(true); } - if url == "https://chat.openai.com" && !chat_conf.dashboard { + if url == "https://chat.openai.com" && !chat_conf.main_dashboard { main_win = main_win .initialization_script(include_str!("../vendors/floating-ui-core.js")) .initialization_script(include_str!("../vendors/floating-ui-dom.js")) diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index f3f5e2e..8a912e3 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -93,12 +93,12 @@ pub fn dalle2_window( } } -pub fn control_window(handle: &tauri::AppHandle) { - let app = handle.clone(); +#[tauri::command] +pub fn control_window(handle: tauri::AppHandle) { tauri::async_runtime::spawn(async move { - if app.app_handle().get_window("main").is_none() { + if handle.get_window("main").is_none() { WindowBuilder::new( - &app, + &handle, "main", WindowUrl::App("index.html?type=control".into()), ) @@ -110,7 +110,7 @@ pub fn control_window(handle: &tauri::AppHandle) { .build() .unwrap(); } else { - let main_win = app.app_handle().get_window("main").unwrap(); + let main_win = handle.get_window("main").unwrap(); main_win.show().unwrap(); main_win.set_focus().unwrap(); } diff --git a/src-tauri/src/conf.rs b/src-tauri/src/conf.rs index c8455ce..e6832be 100644 --- a/src-tauri/src/conf.rs +++ b/src-tauri/src/conf.rs @@ -18,7 +18,6 @@ pub const BUY_COFFEE: &str = "https://www.buymeacoffee.com/lencx"; pub const GITHUB_PROMPTS_CSV_URL: &str = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"; pub const DEFAULT_CHAT_CONF: &str = r#"{ - "dashboard": false, "stay_on_top": false, "auto_update": "Prompt", "theme": "Light", @@ -27,14 +26,15 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{ "popup_search": false, "global_shortcut": "", "hide_dock_icon": false, - "origin": "https://chat.openai.com", + "main_dashboard": false, + "tray_dashboard": false, + "main_origin": "https://chat.openai.com", "tray_origin": "https://chat.openai.com", "default_origin": "https://chat.openai.com", "ua_window": "", "ua_tray": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1" }"#; pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{ - "dashboard": false, "stay_on_top": false, "auto_update": "Prompt", "theme": "Light", @@ -43,7 +43,9 @@ pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{ "popup_search": false, "global_shortcut": "", "hide_dock_icon": false, - "origin": "https://chat.openai.com", + "main_dashboard": false, + "tray_dashboard": false, + "main_origin": "https://chat.openai.com", "tray_origin": "https://chat.openai.com", "default_origin": "https://chat.openai.com", "ua_window": "", @@ -60,11 +62,12 @@ pub struct ChatConfJson { pub theme: String, // auto update policy, Prompt/Silent/Disable pub auto_update: String, - pub dashboard: bool, pub tray: bool, pub popup_search: bool, pub stay_on_top: bool, - pub origin: String, + pub main_dashboard: bool, + pub tray_dashboard: bool, + pub main_origin: String, pub tray_origin: String, pub default_origin: String, pub ua_window: String, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 23ad286..71def99 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -81,6 +81,7 @@ async fn main() { fs_extra::metadata, window::window_reload, window::wa_window, + window::control_window, ]) .setup(setup::init) .menu(menu::init()); diff --git a/src/components/SwitchOrigin/index.tsx b/src/components/SwitchOrigin/index.tsx index 16e6dee..e07b87a 100644 --- a/src/components/SwitchOrigin/index.tsx +++ b/src/components/SwitchOrigin/index.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; import { Link } from 'react-router-dom'; -import { Form, Select, Tag, Tooltip } from 'antd'; +import { Form, Select, Tag, Tooltip, Switch } from 'antd'; import { QuestionCircleOutlined } from '@ant-design/icons'; import useJson from '@/hooks/useJson'; @@ -11,34 +11,82 @@ interface SwitchOriginProps { const SwitchOrigin: FC = ({ name }) => { const { json: list = [] } = useJson(CHAT_AWESOME_JSON); + const form = Form.useFormInstance(); + + const labelName = `(${name === 'main' ? 'Main' : 'SystemTray'})`; + const dashboardName = `${name}_dashboard`; + const originName = `${name}_origin`; + const isEnable = Form.useWatch(dashboardName, form); return ( - - Switch Origin ({name === 'origin' ? 'Main' : 'SystemTray'}){' '} - - If you need to set a new URL as the application loading window, please add the URL - in the Awesome menu and then select it. - - } - > - - - - } - name={name} - > - - + <> + + Dashboard {labelName}{' '} + +

+ Set the URL dashboard as an application window. +

+

+ If this is enabled, the Switch Origin {labelName}{' '} + setting will be invalid. +

+

+ If you want to add a new URL to the dashboard, add it in the{' '} + Awesome menu and make sure it is enabled. +

+ + } + > + +
+ + } + name={dashboardName} + valuePropName="checked" + > + +
+ + Switch Origin {labelName}{' '} + +

+ Set a single URL as an application window. +

+

+ If you need to set a new URL as the application loading window, please add the + URL in the Awesome menu and then select it. +

+ + } + > + +
+ + } + name={originName} + > + +
+ ); }; diff --git a/src/view/awesome/index.tsx b/src/view/awesome/index.tsx index 0b75c82..ba59b85 100644 --- a/src/view/awesome/index.tsx +++ b/src/view/awesome/index.tsx @@ -34,9 +34,7 @@ export default function Awesome() { updateJson(data); opInfo.resetRecord(); } - }, [opInfo.opType, - - formRef]); + }, [opInfo.opType, formRef]); const hide = () => { setVisible(false); @@ -54,18 +52,33 @@ export default function Awesome() { const handleOk = () => { formRef.current?.form?.validateFields().then(async (vals: Record) => { - if (opInfo.opType === 'new') { - const data = opAdd(vals); - await updateJson(data); - opInit(data); - message.success('Data added successfully'); + const idx = opData.findIndex((i) => i.url === vals.url); + if (idx === -1) { + if (opInfo.opType === 'new') { + const data = opAdd(vals); + await updateJson(data); + opInit(data); + message.success('Data added successfully'); + } + if (opInfo.opType === 'edit') { + const data = opReplace(opInfo?.opRecord?.[opSafeKey], vals); + await updateJson(data); + message.success('Data updated successfully'); + } + hide(); + } else { + const data = opData[idx]; + message.error( +
+
+ + {data.title}: {data.url} + +
+
This URL already exists, please edit it and try again.
+
, + ); } - if (opInfo.opType === 'edit') { - const data = opReplace(opInfo?.opRecord?.[opSafeKey], vals); - await updateJson(data); - message.success('Data updated successfully'); - } - hide(); }); }; diff --git a/src/view/dashboard/index.scss b/src/view/dashboard/index.scss index 4387795..7b66b9e 100644 --- a/src/view/dashboard/index.scss +++ b/src/view/dashboard/index.scss @@ -5,6 +5,30 @@ overflow-y: auto; padding: 15px; + &-no-data { + height: 100%; + display: flex; + align-items: center; + justify-content: center; + text-align: center; + flex-direction: column; + font-weight: bold; + + .icon { + color: #989898; + font-size: 24px; + } + + .txt { + font-size: 12px; + + a { + color: #1677ff; + cursor: pointer; + } + } + } + &.dark { background-color: #000; } diff --git a/src/view/dashboard/index.tsx b/src/view/dashboard/index.tsx index f6dc49e..00a68f0 100644 --- a/src/view/dashboard/index.tsx +++ b/src/view/dashboard/index.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react'; import clsx from 'clsx'; import { Row, Col, Card } from 'antd'; +import { InboxOutlined } from '@ant-design/icons'; import { os, invoke } from '@tauri-apps/api'; import useInit from '@/hooks/useInit'; @@ -10,7 +11,7 @@ import './index.scss'; export default function Dashboard() { const { json } = useJson[]>(CHAT_AWESOME_JSON); - const [list, setList] = useState[]]>>([]); + const [list, setList] = useState[]]>>(); const [hasClass, setClass] = useState(false); const [theme, setTheme] = useState(''); @@ -23,6 +24,7 @@ export default function Dashboard() { }); useEffect(() => { + if (!json) return; const categories = new Map(); json?.forEach((i) => { @@ -43,6 +45,23 @@ export default function Dashboard() { }); }; + if (!list) return null; + if (list?.length === 0) { + return ( +
+
+ +
+ No data +
+ +
+ ); + } + return (
diff --git a/src/view/settings/General.tsx b/src/view/settings/General.tsx index 4d47aad..6f03a5f 100644 --- a/src/view/settings/General.tsx +++ b/src/view/settings/General.tsx @@ -6,6 +6,49 @@ import { platform } from '@tauri-apps/api/os'; import useInit from '@/hooks/useInit'; import { DISABLE_AUTO_COMPLETE } from '@/utils'; +export default function General() { + const [platformInfo, setPlatform] = useState(''); + + useInit(async () => { + setPlatform(await platform()); + }); + + return ( + <> + + + + {platformInfo === 'darwin' && ( + + + + )} + {platformInfo === 'darwin' && ( + + + + )} + + + Light + Dark + {['darwin', 'windows'].includes(platformInfo) && System} + + + } name="auto_update"> + + Prompt + Silent + {/*Disable*/} + + + } name="global_shortcut"> + + + + ); +} + const AutoUpdateLabel = () => { return ( @@ -50,49 +93,3 @@ const GlobalShortcutLabel = () => {
); }; - -export default function General() { - const [platformInfo, setPlatform] = useState(''); - - useInit(async () => { - setPlatform(await platform()); - }); - - return ( - <> - - - - - - - {platformInfo === 'darwin' && ( - - - - )} - {platformInfo === 'darwin' && ( - - - - )} - - - Light - Dark - {['darwin', 'windows'].includes(platformInfo) && System} - - - } name="auto_update"> - - Prompt - Silent - {/*Disable*/} - - - } name="global_shortcut"> - - - - ); -} diff --git a/src/view/settings/MainWindow.tsx b/src/view/settings/MainWindow.tsx index 18f7a6d..0235ab7 100644 --- a/src/view/settings/MainWindow.tsx +++ b/src/view/settings/MainWindow.tsx @@ -36,7 +36,7 @@ export default function General() { } name="popup_search" valuePropName="checked"> - + - + } name="ua_tray">