From a3b40f7f40c0a2df8c233f6b9413fc6fdca13e44 Mon Sep 17 00:00:00 2001 From: lencx Date: Fri, 6 Jan 2023 23:48:53 +0800 Subject: [PATCH] chore: dalle2 --- README-ZH_CN.md | 2 +- README.md | 2 +- src-tauri/src/app/cmd.rs | 3 ++- src-tauri/src/app/menu.rs | 27 +++++++++++++++++++++++---- src-tauri/src/app/window.rs | 3 +++ src-tauri/src/assets/cmd.js | 5 +++++ src-tauri/src/assets/dalle2.core.js | 2 ++ src-tauri/src/conf.rs | 3 +++ src/hooks/useChatModel.ts | 1 + src/view/General.tsx | 15 +++++++++------ 10 files changed, 50 insertions(+), 13 deletions(-) diff --git a/README-ZH_CN.md b/README-ZH_CN.md index ecf06ab..fe4141f 100644 --- a/README-ZH_CN.md +++ b/README-ZH_CN.md @@ -90,7 +90,7 @@ - 应用菜单功能强大 - 支持斜杠命令及其配置(可手动配置或从文件同步 [#55](https://github.com/lencx/ChatGPT/issues/55)) - 自定义全局快捷键 ([#108](https://github.com/lencx/ChatGPT/issues/108)) -- DALL·E 2 搜索 (触发方式:鼠标选中文本 [#122](https://github.com/lencx/ChatGPT/issues/122)) +- DALL·E 2 搜索 ([#122](https://github.com/lencx/ChatGPT/issues/122) 鼠标选中文本,不超过 400 个字符):应用使用 Tauri 构建,因其安全限制,会导致部分操作按钮无效,建议前往浏览器操作。 ### #️⃣ 菜单项 diff --git a/README.md b/README.md index 08f3a08..338bd48 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ You can look at **[awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt - Powerful menu items - Support for slash commands and their configuration (can be configured manually or synchronized from a file [#55](https://github.com/lencx/ChatGPT/issues/55)) - Customize global shortcuts ([#108](https://github.com/lencx/ChatGPT/issues/108)) -- DALL·E 2 Search (mouse selected content [#122](https://github.com/lencx/ChatGPT/issues/122), use no more than 400 characters): The application is built using Tauri, and due to its security restrictions, some of the action buttons will not work, so we recommend going to your browser. +- DALL·E 2 Search ([#122](https://github.com/lencx/ChatGPT/issues/122) mouse selected content, use no more than 400 characters): The application is built using Tauri, and due to its security restrictions, some of the action buttons will not work, so we recommend going to your browser. ## #️⃣ MenuItem diff --git a/src-tauri/src/app/cmd.rs b/src-tauri/src/app/cmd.rs index adff518..0d942ea 100644 --- a/src-tauri/src/app/cmd.rs +++ b/src-tauri/src/app/cmd.rs @@ -246,7 +246,8 @@ pub async fn sync_prompts(app: AppHandle, time: u64) -> Option> "Sync Prompts", "ChatGPT Prompts data has been synchronized!", ); - window_reload(app, "core"); + window_reload(app.clone(), "core"); + window_reload(app, "tray"); return Some(data2); } diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index 0af7115..5a9495b 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -1,5 +1,5 @@ use crate::{ - app::window, + app::{cmd, window}, conf::{self, ChatConfJson}, utils, }; @@ -35,6 +35,12 @@ pub fn init() -> Menu { let stay_on_top = CustomMenuItem::new("stay_on_top".to_string(), "Stay On Top").accelerator("CmdOrCtrl+T"); + let stay_on_top_menu = if chat_conf.stay_on_top { + stay_on_top.selected() + } else { + stay_on_top + }; + #[cfg(target_os = "macos")] let titlebar = @@ -50,10 +56,11 @@ pub fn init() -> Menu { let update_silent = CustomMenuItem::new("update_silent".to_string(), "Silent"); let _update_disable = CustomMenuItem::new("update_disable".to_string(), "Disable"); - let stay_on_top_menu = if chat_conf.stay_on_top { - stay_on_top.selected() + let dalle2_search = CustomMenuItem::new("dalle2_search".to_string(), "DALL·E 2 Search"); + let dalle2_search_menu = if chat_conf.dalle2_search { + dalle2_search.selected() } else { - stay_on_top + dalle2_search }; #[cfg(target_os = "macos")] @@ -119,6 +126,7 @@ pub fn init() -> Menu { ) .into(), MenuItem::Separator.into(), + dalle2_search_menu.into(), CustomMenuItem::new("sync_prompts".to_string(), "Sync Prompts").into(), MenuItem::Separator.into(), CustomMenuItem::new("go_conf".to_string(), "Go to Config") @@ -238,6 +246,17 @@ pub fn menu_handler(event: WindowMenuEvent) { "go_conf" => utils::open_file(utils::chat_root()), "clear_conf" => utils::clear_conf(&app), "awesome" => open(&app, conf::AWESOME_URL.to_string()), + "dalle2_search" => { + let chat_conf = conf::ChatConfJson::get_chat_conf(); + let dalle2_search = !chat_conf.dalle2_search; + menu_handle + .get_item(menu_id) + .set_selected(dalle2_search) + .unwrap(); + ChatConfJson::amend(&serde_json::json!({ "dalle2_search": dalle2_search }), None).unwrap(); + cmd::window_reload(app.clone(), "core"); + cmd::window_reload(app, "tray"); + }, "sync_prompts" => { tauri::api::dialog::ask( app.get_window("core").as_ref(), diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index 56022ae..a4edebc 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -18,8 +18,11 @@ pub fn tray_window(handle: &tauri::AppHandle) { .always_on_top(true) .theme(theme) .initialization_script(&utils::user_script()) + .initialization_script(include_str!("../vendors/floating-ui-core.js")) + .initialization_script(include_str!("../vendors/floating-ui-dom.js")) .initialization_script(include_str!("../assets/core.js")) .initialization_script(include_str!("../assets/cmd.js")) + .initialization_script(include_str!("../assets/dalle2.core.js")) .user_agent(&chat_conf.ua_tray) .build() .unwrap() diff --git a/src-tauri/src/assets/cmd.js b/src-tauri/src/assets/cmd.js index 6c712d1..4588e5a 100644 --- a/src-tauri/src/assets/cmd.js +++ b/src-tauri/src/assets/cmd.js @@ -75,6 +75,11 @@ function init() { width: 24px; height: 24px; } + @media screen and (max-width: 767px) { + #download-png-button, #download-pdf-button, #download-html-button { + display: none; + } + } `; document.head.append(styleDom); diff --git a/src-tauri/src/assets/dalle2.core.js b/src-tauri/src/assets/dalle2.core.js index 7478691..ab89b27 100644 --- a/src-tauri/src/assets/dalle2.core.js +++ b/src-tauri/src/assets/dalle2.core.js @@ -1,6 +1,8 @@ // *** Core Script - DALL·E 2 Core *** async function init() { + const chatConf = await invoke('get_chat_conf') || {}; + if (!chatConf.dalle2_search) return; if (!window.FloatingUIDOM) return; const styleDom = document.createElement('style'); diff --git a/src-tauri/src/conf.rs b/src-tauri/src/conf.rs index f71a188..c34b316 100644 --- a/src-tauri/src/conf.rs +++ b/src-tauri/src/conf.rs @@ -21,6 +21,7 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{ "auto_update": "Prompt", "theme": "Light", "titlebar": true, + "dalle2_search": true, "global_shortcut": "", "hide_dock_icon": false, "default_origin": "https://chat.openai.com", @@ -33,6 +34,7 @@ pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{ "auto_update": "Prompt", "theme": "Light", "titlebar": false, + "dalle2_search": true, "global_shortcut": "", "hide_dock_icon": false, "default_origin": "https://chat.openai.com", @@ -63,6 +65,7 @@ pub struct ChatConfJson { pub theme: String, // auto update policy, Prompt/Silent/Disable pub auto_update: String, + pub dalle2_search: bool, pub stay_on_top: bool, pub default_origin: String, pub origin: String, diff --git a/src/hooks/useChatModel.ts b/src/hooks/useChatModel.ts index 45a816a..980fe1c 100644 --- a/src/hooks/useChatModel.ts +++ b/src/hooks/useChatModel.ts @@ -47,6 +47,7 @@ export function useCacheModel(file = '') { const list = await invoke('cmd_list'); await writeJSON(CHAT_MODEL_CMD_JSON, { name: 'ChatGPT CMD', last_updated: Date.now(), data: list }); await invoke('window_reload', { label: 'core' }); + await invoke('window_reload', { label: 'tray' }); }; return { modelCacheJson, modelCacheSet, modelCacheCmd }; diff --git a/src/view/General.tsx b/src/view/General.tsx index 6b5d0aa..979104f 100644 --- a/src/view/General.tsx +++ b/src/view/General.tsx @@ -14,12 +14,12 @@ const AutoUpdateLabel = () => { return ( Auto Update -
Auto Update Policy
- Prompt: prompt to install
- Silent: install silently
- {/*Disable: disable auto update
*/} - +
+
Auto Update Policy
+ Prompt: prompt to install
+ Silent: install silently
+ {/*Disable: disable auto update
*/} +
)}>
) @@ -122,6 +122,9 @@ export default function General() { )} + + + Light