chore: dashboard

This commit is contained in:
lencx
2023-01-24 13:23:06 +08:00
parent 1f573102d3
commit f1e528d3a7
12 changed files with 269 additions and 95 deletions

View File

@@ -140,16 +140,6 @@ pub fn parse_prompt(data: String) -> Vec<PromptRecord> {
list
}
#[command]
pub fn window_reload(app: AppHandle, label: &str) {
app
.app_handle()
.get_window(label)
.unwrap()
.eval("window.location.reload()")
.unwrap();
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
pub struct ModelRecord {
pub cmd: String,
@@ -345,8 +335,8 @@ pub async fn sync_prompts(app: AppHandle, time: u64) -> Option<Vec<ModelRecord>>
"Sync Prompts",
"ChatGPT Prompts data has been synchronized!",
);
window_reload(app.clone(), "core");
window_reload(app, "tray");
window::window_reload(app.clone(), "core");
window::window_reload(app, "tray");
return Some(data2);
}

View File

@@ -1,5 +1,5 @@
use crate::{
app::{cmd, window},
app::window,
conf::{self, ChatConfJson},
utils,
};
@@ -250,8 +250,8 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
.set_selected(popup_search)
.unwrap();
ChatConfJson::amend(&serde_json::json!({ "popup_search": popup_search }), None).unwrap();
cmd::window_reload(app.clone(), "core");
cmd::window_reload(app, "tray");
window::window_reload(app.clone(), "core");
window::window_reload(app, "tray");
}
"sync_prompts" => {
tauri::api::dialog::ask(

View File

@@ -50,7 +50,12 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
} else {
let app = app.handle();
tauri::async_runtime::spawn(async move {
let mut main_win = WindowBuilder::new(&app, "core", WindowUrl::App(url.clone().into()))
let link = if chat_conf.dashboard {
"index.html"
} else {
&url
};
let mut main_win = WindowBuilder::new(&app, "core", WindowUrl::App(link.into()))
.title("ChatGPT")
.resizable(true)
.fullscreen(false)
@@ -60,7 +65,7 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
main_win = main_win.hidden_title(true);
}
if url == "https://chat.openai.com" {
if url == "https://chat.openai.com" && !chat_conf.dashboard {
main_win = main_win
.initialization_script(include_str!("../vendors/floating-ui-core.js"))
.initialization_script(include_str!("../vendors/floating-ui-dom.js"))

View File

@@ -97,14 +97,18 @@ pub fn control_window(handle: &tauri::AppHandle) {
let app = handle.clone();
tauri::async_runtime::spawn(async move {
if app.app_handle().get_window("main").is_none() {
WindowBuilder::new(&app, "main", WindowUrl::App("index.html".into()))
.title("Control Center")
.resizable(true)
.fullscreen(false)
.inner_size(1000.0, 700.0)
.min_inner_size(800.0, 600.0)
.build()
.unwrap();
WindowBuilder::new(
&app,
"main",
WindowUrl::App("index.html?type=control".into()),
)
.title("Control Center")
.resizable(true)
.fullscreen(false)
.inner_size(1000.0, 700.0)
.min_inner_size(800.0, 600.0)
.build()
.unwrap();
} else {
let main_win = app.app_handle().get_window("main").unwrap();
main_win.show().unwrap();
@@ -112,3 +116,40 @@ pub fn control_window(handle: &tauri::AppHandle) {
}
});
}
#[tauri::command]
pub async fn wa_window(
app: tauri::AppHandle,
label: String,
title: String,
url: String,
script: Option<String>,
) {
info!("wa_window: {} :=> {}", title, url);
let win = app.get_window(&label);
if win.is_none() {
tauri::async_runtime::spawn(async move {
tauri::WindowBuilder::new(&app, label, tauri::WindowUrl::App(url.parse().unwrap()))
.initialization_script(&script.unwrap_or_default())
.initialization_script(include_str!("../scripts/core.js"))
.title(title)
.build()
.unwrap();
});
} else {
if !win.clone().unwrap().is_visible().unwrap() {
win.clone().unwrap().show().unwrap();
}
win.unwrap().set_focus().unwrap();
}
}
#[tauri::command]
pub fn window_reload(app: tauri::AppHandle, label: &str) {
app
.app_handle()
.get_window(label)
.unwrap()
.eval("window.location.reload()")
.unwrap();
}