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

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

View File

@@ -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<tauri::Wry>) {
"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(),

View File

@@ -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()

View File

@@ -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);

View File

@@ -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');

View File

@@ -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,