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-07 13:14:03 +08:00
parent 94a8112d45
commit 8863e4575c
5 changed files with 44 additions and 24 deletions

View File

@ -19,6 +19,7 @@ pub fn dalle2_window(app: AppHandle, query: String) {
&app.app_handle(),
Some(query),
Some("ChatGPT & DALL·E 2".to_string()),
None,
);
}

View File

@ -330,7 +330,7 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
ChatConfJson::amend(&serde_json::json!({ "stay_on_top": stay_on_top }), None).unwrap();
}
// Window
"dalle2" => window::dalle2_window(&app, None, None),
"dalle2" => window::dalle2_window(&app, None, None, Some(false)),
// View
"reload" => win.eval("window.location.reload()").unwrap(),
"go_back" => win.eval("window.history.go(-1)").unwrap(),

View File

@ -31,12 +31,13 @@ pub fn tray_window(handle: &tauri::AppHandle) {
});
}
pub fn dalle2_window(handle: &tauri::AppHandle, query: Option<String>, title: Option<String>) {
pub fn dalle2_window(
handle: &tauri::AppHandle,
query: Option<String>,
title: Option<String>,
is_new: Option<bool>,
) {
info!("dalle2_query: {:?}", query);
let timestamp = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs();
let theme = conf::ChatConfJson::theme();
let app = handle.clone();
@ -49,10 +50,21 @@ pub fn dalle2_window(handle: &tauri::AppHandle, query: Option<String>, title: Op
"".to_string()
};
let label = if is_new.unwrap_or(true) {
let timestamp = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs();
format!("dalle2_{}", timestamp)
} else {
"dalle2".to_string()
};
if app.get_window("dalle2").is_none() {
tauri::async_runtime::spawn(async move {
WindowBuilder::new(
&app,
format!("dalle2_{}", timestamp),
label,
WindowUrl::App("https://labs.openai.com".into()),
)
.title(title.unwrap_or_else(|| "DALL·E 2".to_string()))
@ -67,6 +79,11 @@ pub fn dalle2_window(handle: &tauri::AppHandle, query: Option<String>, title: Op
.build()
.unwrap();
});
} else {
let dalle2_win = app.get_window("dalle2").unwrap();
dalle2_win.show().unwrap();
dalle2_win.set_focus().unwrap();
}
}
pub fn control_window(handle: &tauri::AppHandle) {

View File

@ -71,6 +71,7 @@ async function init() {
document.addEventListener("click", (e) => {
const origin = e.target.closest("a");
if (!origin.target) return;
if (origin && origin.href && origin.target !== '_self') {
invoke('open_link', { url: origin.href });
}

View File

@ -3,6 +3,7 @@
async function init() {
document.addEventListener("click", (e) => {
const origin = e.target.closest("a");
if (!origin.target) return;
if (origin && origin.href && origin.target !== '_self') {
if (/\/(login|signup)$/.test(window.location.href)) {
origin.target = '_self';