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

chore: dalle2

This commit is contained in:
lencx 2023-01-06 23:48:53 +08:00
parent de5533d942
commit a3b40f7f40
10 changed files with 50 additions and 13 deletions

View File

@ -90,7 +90,7 @@
- 应用菜单功能强大 - 应用菜单功能强大
- 支持斜杠命令及其配置(可手动配置或从文件同步 [#55](https://github.com/lencx/ChatGPT/issues/55) - 支持斜杠命令及其配置(可手动配置或从文件同步 [#55](https://github.com/lencx/ChatGPT/issues/55)
- 自定义全局快捷键 ([#108](https://github.com/lencx/ChatGPT/issues/108)) - 自定义全局快捷键 ([#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 构建,因其安全限制,会导致部分操作按钮无效,建议前往浏览器操作。
### #⃣ 菜单项 ### #⃣ 菜单项

View File

@ -93,7 +93,7 @@ You can look at **[awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt
- Powerful menu items - 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)) - 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)) - 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 ## #⃣ MenuItem

View File

@ -246,7 +246,8 @@ pub async fn sync_prompts(app: AppHandle, time: u64) -> Option<Vec<ModelRecord>>
"Sync Prompts", "Sync Prompts",
"ChatGPT Prompts data has been synchronized!", "ChatGPT Prompts data has been synchronized!",
); );
window_reload(app, "core"); window_reload(app.clone(), "core");
window_reload(app, "tray");
return Some(data2); return Some(data2);
} }

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
app::window, app::{cmd, window},
conf::{self, ChatConfJson}, conf::{self, ChatConfJson},
utils, utils,
}; };
@ -35,6 +35,12 @@ pub fn init() -> Menu {
let stay_on_top = let stay_on_top =
CustomMenuItem::new("stay_on_top".to_string(), "Stay On Top").accelerator("CmdOrCtrl+T"); 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")] #[cfg(target_os = "macos")]
let titlebar = let titlebar =
@ -50,10 +56,11 @@ pub fn init() -> Menu {
let update_silent = CustomMenuItem::new("update_silent".to_string(), "Silent"); let update_silent = CustomMenuItem::new("update_silent".to_string(), "Silent");
let _update_disable = CustomMenuItem::new("update_disable".to_string(), "Disable"); let _update_disable = CustomMenuItem::new("update_disable".to_string(), "Disable");
let stay_on_top_menu = if chat_conf.stay_on_top { let dalle2_search = CustomMenuItem::new("dalle2_search".to_string(), "DALL·E 2 Search");
stay_on_top.selected() let dalle2_search_menu = if chat_conf.dalle2_search {
dalle2_search.selected()
} else { } else {
stay_on_top dalle2_search
}; };
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
@ -119,6 +126,7 @@ pub fn init() -> Menu {
) )
.into(), .into(),
MenuItem::Separator.into(), MenuItem::Separator.into(),
dalle2_search_menu.into(),
CustomMenuItem::new("sync_prompts".to_string(), "Sync Prompts").into(), CustomMenuItem::new("sync_prompts".to_string(), "Sync Prompts").into(),
MenuItem::Separator.into(), MenuItem::Separator.into(),
CustomMenuItem::new("go_conf".to_string(), "Go to Config") CustomMenuItem::new("go_conf".to_string(), "Go to Config")
@ -238,6 +246,17 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
"go_conf" => utils::open_file(utils::chat_root()), "go_conf" => utils::open_file(utils::chat_root()),
"clear_conf" => utils::clear_conf(&app), "clear_conf" => utils::clear_conf(&app),
"awesome" => open(&app, conf::AWESOME_URL.to_string()), "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" => { "sync_prompts" => {
tauri::api::dialog::ask( tauri::api::dialog::ask(
app.get_window("core").as_ref(), app.get_window("core").as_ref(),

View File

@ -18,8 +18,11 @@ pub fn tray_window(handle: &tauri::AppHandle) {
.always_on_top(true) .always_on_top(true)
.theme(theme) .theme(theme)
.initialization_script(&utils::user_script()) .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/core.js"))
.initialization_script(include_str!("../assets/cmd.js")) .initialization_script(include_str!("../assets/cmd.js"))
.initialization_script(include_str!("../assets/dalle2.core.js"))
.user_agent(&chat_conf.ua_tray) .user_agent(&chat_conf.ua_tray)
.build() .build()
.unwrap() .unwrap()

View File

@ -75,6 +75,11 @@ function init() {
width: 24px; width: 24px;
height: 24px; height: 24px;
} }
@media screen and (max-width: 767px) {
#download-png-button, #download-pdf-button, #download-html-button {
display: none;
}
}
`; `;
document.head.append(styleDom); document.head.append(styleDom);

View File

@ -1,6 +1,8 @@
// *** Core Script - DALL·E 2 Core *** // *** Core Script - DALL·E 2 Core ***
async function init() { async function init() {
const chatConf = await invoke('get_chat_conf') || {};
if (!chatConf.dalle2_search) return;
if (!window.FloatingUIDOM) return; if (!window.FloatingUIDOM) return;
const styleDom = document.createElement('style'); const styleDom = document.createElement('style');

View File

@ -21,6 +21,7 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{
"auto_update": "Prompt", "auto_update": "Prompt",
"theme": "Light", "theme": "Light",
"titlebar": true, "titlebar": true,
"dalle2_search": true,
"global_shortcut": "", "global_shortcut": "",
"hide_dock_icon": false, "hide_dock_icon": false,
"default_origin": "https://chat.openai.com", "default_origin": "https://chat.openai.com",
@ -33,6 +34,7 @@ pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{
"auto_update": "Prompt", "auto_update": "Prompt",
"theme": "Light", "theme": "Light",
"titlebar": false, "titlebar": false,
"dalle2_search": true,
"global_shortcut": "", "global_shortcut": "",
"hide_dock_icon": false, "hide_dock_icon": false,
"default_origin": "https://chat.openai.com", "default_origin": "https://chat.openai.com",
@ -63,6 +65,7 @@ pub struct ChatConfJson {
pub theme: String, pub theme: String,
// auto update policy, Prompt/Silent/Disable // auto update policy, Prompt/Silent/Disable
pub auto_update: String, pub auto_update: String,
pub dalle2_search: bool,
pub stay_on_top: bool, pub stay_on_top: bool,
pub default_origin: String, pub default_origin: String,
pub origin: String, pub origin: String,

View File

@ -47,6 +47,7 @@ export function useCacheModel(file = '') {
const list = await invoke('cmd_list'); const list = await invoke('cmd_list');
await writeJSON(CHAT_MODEL_CMD_JSON, { name: 'ChatGPT CMD', last_updated: Date.now(), data: 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: 'core' });
await invoke('window_reload', { label: 'tray' });
}; };
return { modelCacheJson, modelCacheSet, modelCacheCmd }; return { modelCacheJson, modelCacheSet, modelCacheCmd };

15
src/view/General.tsx vendored
View File

@ -14,12 +14,12 @@ const AutoUpdateLabel = () => {
return ( return (
<span> <span>
Auto Update <Tooltip title={( Auto Update <Tooltip title={(
<div> <div>
<div>Auto Update Policy</div> <div>Auto Update Policy</div>
<span><strong>Prompt</strong>: prompt to install</span><br/> <span><strong>Prompt</strong>: prompt to install</span><br/>
<span><strong>Silent</strong>: install silently</span><br/> <span><strong>Silent</strong>: install silently</span><br/>
{/*<span><strong>Disable</strong>: disable auto update</span><br/>*/} {/*<span><strong>Disable</strong>: disable auto update</span><br/>*/}
</div> </div>
)}><QuestionCircleOutlined style={{ color: '#1677ff' }} /></Tooltip> )}><QuestionCircleOutlined style={{ color: '#1677ff' }} /></Tooltip>
</span> </span>
) )
@ -122,6 +122,9 @@ export default function General() {
<Switch /> <Switch />
</Form.Item> </Form.Item>
)} )}
<Form.Item label="DALL·E 2 Search" name="dalle2_search" valuePropName="checked">
<Switch />
</Form.Item>
<Form.Item label="Theme" name="theme"> <Form.Item label="Theme" name="theme">
<Radio.Group> <Radio.Group>
<Radio value="Light">Light</Radio> <Radio value="Light">Light</Radio>