mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: dalle2
This commit is contained in:
@@ -19,6 +19,7 @@ pub fn dalle2_window(app: AppHandle, query: String) {
|
|||||||
&app.app_handle(),
|
&app.app_handle(),
|
||||||
Some(query),
|
Some(query),
|
||||||
Some("ChatGPT & DALL·E 2".to_string()),
|
Some("ChatGPT & DALL·E 2".to_string()),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
ChatConfJson::amend(&serde_json::json!({ "stay_on_top": stay_on_top }), None).unwrap();
|
||||||
}
|
}
|
||||||
// Window
|
// Window
|
||||||
"dalle2" => window::dalle2_window(&app, None, None),
|
"dalle2" => window::dalle2_window(&app, None, None, Some(false)),
|
||||||
// View
|
// View
|
||||||
"reload" => win.eval("window.location.reload()").unwrap(),
|
"reload" => win.eval("window.location.reload()").unwrap(),
|
||||||
"go_back" => win.eval("window.history.go(-1)").unwrap(),
|
"go_back" => win.eval("window.history.go(-1)").unwrap(),
|
||||||
|
|||||||
@@ -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);
|
info!("dalle2_query: {:?}", query);
|
||||||
let timestamp = SystemTime::now()
|
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
|
||||||
.unwrap()
|
|
||||||
.as_secs();
|
|
||||||
let theme = conf::ChatConfJson::theme();
|
let theme = conf::ChatConfJson::theme();
|
||||||
let app = handle.clone();
|
let app = handle.clone();
|
||||||
|
|
||||||
@@ -49,24 +50,40 @@ pub fn dalle2_window(handle: &tauri::AppHandle, query: Option<String>, title: Op
|
|||||||
"".to_string()
|
"".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
tauri::async_runtime::spawn(async move {
|
let label = if is_new.unwrap_or(true) {
|
||||||
WindowBuilder::new(
|
let timestamp = SystemTime::now()
|
||||||
&app,
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
format!("dalle2_{}", timestamp),
|
.unwrap()
|
||||||
WindowUrl::App("https://labs.openai.com".into()),
|
.as_secs();
|
||||||
)
|
format!("dalle2_{}", timestamp)
|
||||||
.title(title.unwrap_or_else(|| "DALL·E 2".to_string()))
|
} else {
|
||||||
.resizable(true)
|
"dalle2".to_string()
|
||||||
.fullscreen(false)
|
};
|
||||||
.inner_size(800.0, 600.0)
|
|
||||||
.always_on_top(false)
|
if app.get_window("dalle2").is_none() {
|
||||||
.theme(theme)
|
tauri::async_runtime::spawn(async move {
|
||||||
.initialization_script(include_str!("../assets/core.js"))
|
WindowBuilder::new(
|
||||||
.initialization_script(&query)
|
&app,
|
||||||
.initialization_script(include_str!("../assets/dalle2.js"))
|
label,
|
||||||
.build()
|
WindowUrl::App("https://labs.openai.com".into()),
|
||||||
.unwrap();
|
)
|
||||||
});
|
.title(title.unwrap_or_else(|| "DALL·E 2".to_string()))
|
||||||
|
.resizable(true)
|
||||||
|
.fullscreen(false)
|
||||||
|
.inner_size(800.0, 600.0)
|
||||||
|
.always_on_top(false)
|
||||||
|
.theme(theme)
|
||||||
|
.initialization_script(include_str!("../assets/core.js"))
|
||||||
|
.initialization_script(&query)
|
||||||
|
.initialization_script(include_str!("../assets/dalle2.js"))
|
||||||
|
.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) {
|
pub fn control_window(handle: &tauri::AppHandle) {
|
||||||
|
|||||||
1
src-tauri/src/assets/core.js
vendored
1
src-tauri/src/assets/core.js
vendored
@@ -71,6 +71,7 @@ async function init() {
|
|||||||
|
|
||||||
document.addEventListener("click", (e) => {
|
document.addEventListener("click", (e) => {
|
||||||
const origin = e.target.closest("a");
|
const origin = e.target.closest("a");
|
||||||
|
if (!origin.target) return;
|
||||||
if (origin && origin.href && origin.target !== '_self') {
|
if (origin && origin.href && origin.target !== '_self') {
|
||||||
invoke('open_link', { url: origin.href });
|
invoke('open_link', { url: origin.href });
|
||||||
}
|
}
|
||||||
|
|||||||
1
src-tauri/src/assets/dalle2.js
vendored
1
src-tauri/src/assets/dalle2.js
vendored
@@ -3,6 +3,7 @@
|
|||||||
async function init() {
|
async function init() {
|
||||||
document.addEventListener("click", (e) => {
|
document.addEventListener("click", (e) => {
|
||||||
const origin = e.target.closest("a");
|
const origin = e.target.closest("a");
|
||||||
|
if (!origin.target) return;
|
||||||
if (origin && origin.href && origin.target !== '_self') {
|
if (origin && origin.href && origin.target !== '_self') {
|
||||||
if (/\/(login|signup)$/.test(window.location.href)) {
|
if (/\/(login|signup)$/.test(window.location.href)) {
|
||||||
origin.target = '_self';
|
origin.target = '_self';
|
||||||
|
|||||||
Reference in New Issue
Block a user