chore: dashboard

This commit is contained in:
lencx
2023-01-24 18:34:31 +08:00
parent 4a7ee4dcf5
commit ba438b0640
12 changed files with 211 additions and 106 deletions

View File

@@ -235,7 +235,7 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
utils::run_check_update(app, false, None);
}
// Preferences
"control_center" => window::control_window(&app),
"control_center" => window::control_window(app.clone()),
"restart" => tauri::api::process::restart(&app.env()),
"inject_script" => open(&app, script_path),
"go_conf" => utils::open_file(utils::chat_root()),
@@ -431,7 +431,7 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) {
}
}
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"control_center" => window::control_window(&app),
"control_center" => window::control_window(app),
"restart" => tauri::api::process::restart(&handle.env()),
"show_dock_icon" => {
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": false }), Some(app)).unwrap();

View File

@@ -6,7 +6,7 @@ use wry::application::accelerator::Accelerator;
pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>> {
info!("stepup");
let chat_conf = ChatConfJson::get_chat_conf();
let url = chat_conf.origin.to_string();
let url = chat_conf.main_origin.to_string();
let theme = ChatConfJson::theme();
let handle = app.app_handle();
@@ -50,7 +50,7 @@ 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 link = if chat_conf.dashboard {
let link = if chat_conf.main_dashboard {
"index.html"
} else {
&url
@@ -65,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" && !chat_conf.dashboard {
if url == "https://chat.openai.com" && !chat_conf.main_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

@@ -93,12 +93,12 @@ pub fn dalle2_window(
}
}
pub fn control_window(handle: &tauri::AppHandle) {
let app = handle.clone();
#[tauri::command]
pub fn control_window(handle: tauri::AppHandle) {
tauri::async_runtime::spawn(async move {
if app.app_handle().get_window("main").is_none() {
if handle.get_window("main").is_none() {
WindowBuilder::new(
&app,
&handle,
"main",
WindowUrl::App("index.html?type=control".into()),
)
@@ -110,7 +110,7 @@ pub fn control_window(handle: &tauri::AppHandle) {
.build()
.unwrap();
} else {
let main_win = app.app_handle().get_window("main").unwrap();
let main_win = handle.get_window("main").unwrap();
main_win.show().unwrap();
main_win.set_focus().unwrap();
}

View File

@@ -18,7 +18,6 @@ pub const BUY_COFFEE: &str = "https://www.buymeacoffee.com/lencx";
pub const GITHUB_PROMPTS_CSV_URL: &str =
"https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv";
pub const DEFAULT_CHAT_CONF: &str = r#"{
"dashboard": false,
"stay_on_top": false,
"auto_update": "Prompt",
"theme": "Light",
@@ -27,14 +26,15 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{
"popup_search": false,
"global_shortcut": "",
"hide_dock_icon": false,
"origin": "https://chat.openai.com",
"main_dashboard": false,
"tray_dashboard": false,
"main_origin": "https://chat.openai.com",
"tray_origin": "https://chat.openai.com",
"default_origin": "https://chat.openai.com",
"ua_window": "",
"ua_tray": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1"
}"#;
pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{
"dashboard": false,
"stay_on_top": false,
"auto_update": "Prompt",
"theme": "Light",
@@ -43,7 +43,9 @@ pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{
"popup_search": false,
"global_shortcut": "",
"hide_dock_icon": false,
"origin": "https://chat.openai.com",
"main_dashboard": false,
"tray_dashboard": false,
"main_origin": "https://chat.openai.com",
"tray_origin": "https://chat.openai.com",
"default_origin": "https://chat.openai.com",
"ua_window": "",
@@ -60,11 +62,12 @@ pub struct ChatConfJson {
pub theme: String,
// auto update policy, Prompt/Silent/Disable
pub auto_update: String,
pub dashboard: bool,
pub tray: bool,
pub popup_search: bool,
pub stay_on_top: bool,
pub origin: String,
pub main_dashboard: bool,
pub tray_dashboard: bool,
pub main_origin: String,
pub tray_origin: String,
pub default_origin: String,
pub ua_window: String,

View File

@@ -81,6 +81,7 @@ async fn main() {
fs_extra::metadata,
window::window_reload,
window::wa_window,
window::control_window,
])
.setup(setup::init)
.menu(menu::init());