chore: dalle2

This commit is contained in:
lencx
2023-01-06 14:39:25 +08:00
parent d0df8df108
commit 8c2303dec9
9 changed files with 86 additions and 41 deletions

View File

@@ -1,4 +1,5 @@
use crate::{conf, utils};
use log::info;
use std::time::SystemTime;
use tauri::{utils::config::WindowUrl, window::WindowBuilder};
@@ -27,7 +28,8 @@ pub fn tray_window(handle: &tauri::AppHandle) {
});
}
pub fn dalle2_window(handle: &tauri::AppHandle, query: String) {
pub fn dalle2_window(handle: &tauri::AppHandle, query: Option<String>, title: Option<String>) {
info!("dalle2_query: {:?}", query);
let timestamp = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
@@ -35,22 +37,32 @@ pub fn dalle2_window(handle: &tauri::AppHandle, query: String) {
let theme = conf::ChatConfJson::theme();
let app = handle.clone();
let query = if query.is_some() {
format!(
"window.addEventListener('DOMContentLoaded', function() {{\nwindow.__CHATGPT_QUERY__='{}';\n}})",
query.unwrap()
)
} else {
"".to_string()
};
tauri::async_runtime::spawn(async move {
WindowBuilder::new(&app, format!("dalle2_{}", timestamp), WindowUrl::App("https://labs.openai.com".into()))
.title("ChatGPT & DALL·E 2")
.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(&format!(
"window.addEventListener('DOMContentLoaded', function() {{\nwindow.__CHATGPT_QUERY__='{}';\n}})",
query
))
.initialization_script(include_str!("../assets/dalle2.js"))
.build()
.unwrap();
WindowBuilder::new(
&app,
format!("dalle2_{}", timestamp),
WindowUrl::App("https://labs.openai.com/".into()),
)
.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();
});
}