mirror of
https://github.com/lencx/ChatGPT.git
synced 2024-10-01 01:06:13 -04:00
chore: fmt
This commit is contained in:
parent
321007bb87
commit
5b6a69444e
@ -1,4 +1,14 @@
|
||||
edition = "2021"
|
||||
max_width = 120
|
||||
max_width = 100
|
||||
hard_tabs = false
|
||||
tab_spaces = 2
|
||||
newline_style = "Auto"
|
||||
newline_style = "Auto"
|
||||
use_small_heuristics = "Default"
|
||||
reorder_imports = true
|
||||
reorder_modules = true
|
||||
remove_nested_parens = true
|
||||
edition = "2021"
|
||||
merge_derives = true
|
||||
use_try_shorthand = false
|
||||
use_field_init_shorthand = false
|
||||
force_explicit_abi = true
|
||||
# imports_granularity = "Crate"
|
@ -267,7 +267,9 @@ pub fn download_list(pathname: &str, dir: &str, filename: Option<String>, id: Op
|
||||
|
||||
#[command]
|
||||
pub async fn sync_prompts(app: AppHandle, time: u64) -> Option<Vec<ModelRecord>> {
|
||||
let res = utils::get_data(GITHUB_PROMPTS_CSV_URL, Some(&app)).await.unwrap();
|
||||
let res = utils::get_data(GITHUB_PROMPTS_CSV_URL, Some(&app))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if let Some(v) = res {
|
||||
let data = parse_prompt(v)
|
||||
@ -289,7 +291,9 @@ pub async fn sync_prompts(app: AppHandle, time: u64) -> Option<Vec<ModelRecord>>
|
||||
|
||||
let model = utils::chat_root().join("chat.model.json");
|
||||
let model_cmd = utils::chat_root().join("chat.model.cmd.json");
|
||||
let chatgpt_prompts = utils::chat_root().join("cache_model").join("chatgpt_prompts.json");
|
||||
let chatgpt_prompts = utils::chat_root()
|
||||
.join("cache_model")
|
||||
.join("chatgpt_prompts.json");
|
||||
|
||||
if !utils::exists(&model) {
|
||||
fs::write(
|
||||
@ -304,7 +308,11 @@ pub async fn sync_prompts(app: AppHandle, time: u64) -> Option<Vec<ModelRecord>>
|
||||
}
|
||||
|
||||
// chatgpt_prompts.json
|
||||
fs::write(chatgpt_prompts, serde_json::to_string_pretty(&data).unwrap()).unwrap();
|
||||
fs::write(
|
||||
chatgpt_prompts,
|
||||
serde_json::to_string_pretty(&data).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
let cmd_data = cmd_list();
|
||||
|
||||
// chat.model.cmd.json
|
||||
|
@ -4,8 +4,8 @@ use crate::{
|
||||
utils,
|
||||
};
|
||||
use tauri::{
|
||||
AppHandle, CustomMenuItem, Manager, Menu, MenuItem, Submenu, SystemTray, SystemTrayEvent, SystemTrayMenu,
|
||||
SystemTrayMenuItem, WindowMenuEvent,
|
||||
AppHandle, CustomMenuItem, Manager, Menu, MenuItem, Submenu, SystemTray, SystemTrayEvent,
|
||||
SystemTrayMenu, SystemTrayMenuItem, WindowMenuEvent,
|
||||
};
|
||||
use tauri_plugin_positioner::{on_tray_event, Position, WindowExt};
|
||||
|
||||
@ -33,7 +33,8 @@ pub fn init() -> Menu {
|
||||
]),
|
||||
);
|
||||
|
||||
let stay_on_top = CustomMenuItem::new("stay_on_top".to_string(), "Stay On Top").accelerator("CmdOrCtrl+T");
|
||||
let stay_on_top =
|
||||
CustomMenuItem::new("stay_on_top".to_string(), "Stay On Top").accelerator("CmdOrCtrl+T");
|
||||
let stay_on_top_menu = if chat_conf.stay_on_top {
|
||||
stay_on_top.selected()
|
||||
} else {
|
||||
@ -98,7 +99,11 @@ pub fn init() -> Menu {
|
||||
} else {
|
||||
theme_light.selected()
|
||||
})
|
||||
.add_item(if is_dark { theme_dark.selected() } else { theme_dark })
|
||||
.add_item(if is_dark {
|
||||
theme_dark.selected()
|
||||
} else {
|
||||
theme_dark
|
||||
})
|
||||
.add_item(if is_system {
|
||||
theme_system.selected()
|
||||
} else {
|
||||
@ -162,13 +167,21 @@ pub fn init() -> Menu {
|
||||
"View",
|
||||
Menu::new()
|
||||
.add_item(CustomMenuItem::new("go_back".to_string(), "Go Back").accelerator("CmdOrCtrl+Left"))
|
||||
.add_item(CustomMenuItem::new("go_forward".to_string(), "Go Forward").accelerator("CmdOrCtrl+Right"))
|
||||
.add_item(CustomMenuItem::new("scroll_top".to_string(), "Scroll to Top of Screen").accelerator("CmdOrCtrl+Up"))
|
||||
.add_item(
|
||||
CustomMenuItem::new("scroll_bottom".to_string(), "Scroll to Bottom of Screen").accelerator("CmdOrCtrl+Down"),
|
||||
CustomMenuItem::new("go_forward".to_string(), "Go Forward").accelerator("CmdOrCtrl+Right"),
|
||||
)
|
||||
.add_item(
|
||||
CustomMenuItem::new("scroll_top".to_string(), "Scroll to Top of Screen")
|
||||
.accelerator("CmdOrCtrl+Up"),
|
||||
)
|
||||
.add_item(
|
||||
CustomMenuItem::new("scroll_bottom".to_string(), "Scroll to Bottom of Screen")
|
||||
.accelerator("CmdOrCtrl+Down"),
|
||||
)
|
||||
.add_native_item(MenuItem::Separator)
|
||||
.add_item(CustomMenuItem::new("reload".to_string(), "Refresh the Screen").accelerator("CmdOrCtrl+R")),
|
||||
.add_item(
|
||||
CustomMenuItem::new("reload".to_string(), "Refresh the Screen").accelerator("CmdOrCtrl+R"),
|
||||
),
|
||||
);
|
||||
|
||||
let window_menu = Submenu::new(
|
||||
@ -183,11 +196,15 @@ pub fn init() -> Menu {
|
||||
let help_menu = Submenu::new(
|
||||
"Help",
|
||||
Menu::new()
|
||||
.add_item(CustomMenuItem::new("chatgpt_log".to_string(), "ChatGPT Log"))
|
||||
.add_item(CustomMenuItem::new(
|
||||
"chatgpt_log".to_string(),
|
||||
"ChatGPT Log",
|
||||
))
|
||||
.add_item(CustomMenuItem::new("update_log".to_string(), "Update Log"))
|
||||
.add_item(CustomMenuItem::new("report_bug".to_string(), "Report Bug"))
|
||||
.add_item(
|
||||
CustomMenuItem::new("dev_tools".to_string(), "Toggle Developer Tools").accelerator("CmdOrCtrl+Shift+I"),
|
||||
CustomMenuItem::new("dev_tools".to_string(), "Toggle Developer Tools")
|
||||
.accelerator("CmdOrCtrl+Shift+I"),
|
||||
),
|
||||
);
|
||||
|
||||
@ -232,7 +249,10 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||
"popup_search" => {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
let popup_search = !chat_conf.popup_search;
|
||||
menu_handle.get_item(menu_id).set_selected(popup_search).unwrap();
|
||||
menu_handle
|
||||
.get_item(menu_id)
|
||||
.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");
|
||||
@ -253,10 +273,16 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||
},
|
||||
);
|
||||
}
|
||||
"hide_dock_icon" => ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": true }), Some(app)).unwrap(),
|
||||
"hide_dock_icon" => {
|
||||
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": true }), Some(app)).unwrap()
|
||||
}
|
||||
"titlebar" => {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
ChatConfJson::amend(&serde_json::json!({ "titlebar": !chat_conf.titlebar }), None).unwrap();
|
||||
ChatConfJson::amend(
|
||||
&serde_json::json!({ "titlebar": !chat_conf.titlebar }),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
tauri::api::process::restart(&app.env());
|
||||
}
|
||||
"system_tray" => {
|
||||
@ -279,15 +305,24 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||
}
|
||||
let auto_update = match menu_id {
|
||||
"update_silent" => {
|
||||
menu_handle.get_item("update_silent").set_selected(true).unwrap();
|
||||
menu_handle
|
||||
.get_item("update_silent")
|
||||
.set_selected(true)
|
||||
.unwrap();
|
||||
"Silent"
|
||||
}
|
||||
"update_disable" => {
|
||||
menu_handle.get_item("update_disable").set_selected(true).unwrap();
|
||||
menu_handle
|
||||
.get_item("update_disable")
|
||||
.set_selected(true)
|
||||
.unwrap();
|
||||
"Disable"
|
||||
}
|
||||
_ => {
|
||||
menu_handle.get_item("update_prompt").set_selected(true).unwrap();
|
||||
menu_handle
|
||||
.get_item("update_prompt")
|
||||
.set_selected(true)
|
||||
.unwrap();
|
||||
"Prompt"
|
||||
}
|
||||
};
|
||||
@ -296,7 +331,10 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||
"stay_on_top" => {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
let stay_on_top = !chat_conf.stay_on_top;
|
||||
menu_handle.get_item(menu_id).set_selected(stay_on_top).unwrap();
|
||||
menu_handle
|
||||
.get_item(menu_id)
|
||||
.set_selected(stay_on_top)
|
||||
.unwrap();
|
||||
win.set_always_on_top(stay_on_top).unwrap();
|
||||
ChatConfJson::amend(&serde_json::json!({ "stay_on_top": stay_on_top }), None).unwrap();
|
||||
}
|
||||
@ -341,10 +379,19 @@ pub fn tray_menu() -> SystemTray {
|
||||
if cfg!(target_os = "macos") {
|
||||
SystemTray::new().with_menu(
|
||||
SystemTrayMenu::new()
|
||||
.add_item(CustomMenuItem::new("control_center".to_string(), "Control Center"))
|
||||
.add_item(CustomMenuItem::new(
|
||||
"control_center".to_string(),
|
||||
"Control Center",
|
||||
))
|
||||
.add_native_item(SystemTrayMenuItem::Separator)
|
||||
.add_item(CustomMenuItem::new("show_dock_icon".to_string(), "Show Dock Icon"))
|
||||
.add_item(CustomMenuItem::new("hide_dock_icon".to_string(), "Hide Dock Icon"))
|
||||
.add_item(CustomMenuItem::new(
|
||||
"show_dock_icon".to_string(),
|
||||
"Show Dock Icon",
|
||||
))
|
||||
.add_item(CustomMenuItem::new(
|
||||
"hide_dock_icon".to_string(),
|
||||
"Hide Dock Icon",
|
||||
))
|
||||
.add_item(CustomMenuItem::new("show_core".to_string(), "Show ChatGPT"))
|
||||
.add_native_item(SystemTrayMenuItem::Separator)
|
||||
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")),
|
||||
@ -352,7 +399,10 @@ pub fn tray_menu() -> SystemTray {
|
||||
} else {
|
||||
SystemTray::new().with_menu(
|
||||
SystemTrayMenu::new()
|
||||
.add_item(CustomMenuItem::new("control_center".to_string(), "Control Center"))
|
||||
.add_item(CustomMenuItem::new(
|
||||
"control_center".to_string(),
|
||||
"Control Center",
|
||||
))
|
||||
.add_item(CustomMenuItem::new("show_core".to_string(), "Show ChatGPT"))
|
||||
.add_native_item(SystemTrayMenuItem::Separator)
|
||||
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")),
|
||||
|
@ -31,7 +31,12 @@ pub fn tray_window(handle: &tauri::AppHandle) {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn dalle2_window(handle: &tauri::AppHandle, query: Option<String>, title: Option<String>, is_new: Option<bool>) {
|
||||
pub fn dalle2_window(
|
||||
handle: &tauri::AppHandle,
|
||||
query: Option<String>,
|
||||
title: Option<String>,
|
||||
is_new: Option<bool>,
|
||||
) {
|
||||
info!("dalle2_query: {:?}", query);
|
||||
let theme = conf::ChatConfJson::theme();
|
||||
let app = handle.clone();
|
||||
@ -57,18 +62,22 @@ pub fn dalle2_window(handle: &tauri::AppHandle, query: Option<String>, title: Op
|
||||
|
||||
if app.get_window("dalle2").is_none() {
|
||||
tauri::async_runtime::spawn(async move {
|
||||
WindowBuilder::new(&app, label, 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!("../scripts/core.js"))
|
||||
.initialization_script(&query)
|
||||
.initialization_script(include_str!("../scripts/dalle2.js"))
|
||||
.build()
|
||||
.unwrap();
|
||||
WindowBuilder::new(
|
||||
&app,
|
||||
label,
|
||||
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!("../scripts/core.js"))
|
||||
.initialization_script(&query)
|
||||
.initialization_script(include_str!("../scripts/dalle2.js"))
|
||||
.build()
|
||||
.unwrap();
|
||||
});
|
||||
} else {
|
||||
let dalle2_win = app.get_window("dalle2").unwrap();
|
||||
|
@ -15,7 +15,8 @@ pub const ISSUES_URL: &str = "https://github.com/lencx/ChatGPT/issues";
|
||||
pub const UPDATE_LOG_URL: &str = "https://github.com/lencx/ChatGPT/blob/main/UPDATE_LOG.md";
|
||||
pub const AWESOME_URL: &str = "https://github.com/lencx/ChatGPT/blob/main/AWESOME.md";
|
||||
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 GITHUB_PROMPTS_CSV_URL: &str =
|
||||
"https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv";
|
||||
pub const DEFAULT_CHAT_CONF: &str = r#"{
|
||||
"stay_on_top": false,
|
||||
"auto_update": "Prompt",
|
||||
@ -148,7 +149,10 @@ impl ChatConfJson {
|
||||
config.insert(k, v);
|
||||
}
|
||||
|
||||
fs::write(ChatConfJson::conf_path(), serde_json::to_string_pretty(&config)?)?;
|
||||
fs::write(
|
||||
ChatConfJson::conf_path(),
|
||||
serde_json::to_string_pretty(&config)?,
|
||||
)?;
|
||||
|
||||
if let Some(handle) = app {
|
||||
tauri::api::process::restart(&handle.env());
|
||||
|
@ -1,4 +1,7 @@
|
||||
#![cfg_attr(all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows")]
|
||||
#![cfg_attr(
|
||||
all(not(debug_assertions), target_os = "windows"),
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
mod app;
|
||||
mod conf;
|
||||
@ -48,7 +51,10 @@ async fn main() {
|
||||
.build(),
|
||||
)
|
||||
.plugin(tauri_plugin_positioner::init())
|
||||
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, None))
|
||||
.plugin(tauri_plugin_autostart::init(
|
||||
MacosLauncher::LaunchAgent,
|
||||
None,
|
||||
))
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
cmd::drag_window,
|
||||
cmd::fullscreen,
|
||||
|
@ -64,7 +64,11 @@ pub fn open_file(path: PathBuf) {
|
||||
Command::new("open").arg("-R").arg(path).spawn().unwrap();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
Command::new("explorer").arg("/select,").arg(path).spawn().unwrap();
|
||||
Command::new("explorer")
|
||||
.arg("/select,")
|
||||
.arg(path)
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
// https://askubuntu.com/a/31071
|
||||
#[cfg(target_os = "linux")]
|
||||
@ -78,12 +82,17 @@ pub fn clear_conf(app: &tauri::AppHandle) {
|
||||
"Path: {}\nAre you sure to clear all ChatGPT configurations? Please backup in advance if necessary!",
|
||||
root.to_string_lossy()
|
||||
);
|
||||
tauri::api::dialog::ask(app.get_window("core").as_ref(), "Clear Config", msg, move |is_ok| {
|
||||
if is_ok {
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
tauri::api::process::restart(&app2.env());
|
||||
}
|
||||
});
|
||||
tauri::api::dialog::ask(
|
||||
app.get_window("core").as_ref(),
|
||||
"Clear Config",
|
||||
msg,
|
||||
move |is_ok| {
|
||||
if is_ok {
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
tauri::api::process::restart(&app2.env());
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn merge(v: &Value, fields: &HashMap<String, Value>) -> Value {
|
||||
@ -104,7 +113,10 @@ pub fn gen_cmd(name: String) -> String {
|
||||
re.replace_all(&name, "_").to_lowercase()
|
||||
}
|
||||
|
||||
pub async fn get_data(url: &str, app: Option<&tauri::AppHandle>) -> Result<Option<String>, reqwest::Error> {
|
||||
pub async fn get_data(
|
||||
url: &str,
|
||||
app: Option<&tauri::AppHandle>,
|
||||
) -> Result<Option<String>, reqwest::Error> {
|
||||
let res = reqwest::get(url).await?;
|
||||
let is_ok = res.status() == 200;
|
||||
let body = res.text().await?;
|
||||
@ -222,7 +234,11 @@ pub async fn silent_install(app: AppHandle<Wry>, update: UpdateResponse<Wry>) ->
|
||||
}
|
||||
|
||||
pub fn is_hidden(entry: &walkdir::DirEntry) -> bool {
|
||||
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
|
||||
entry
|
||||
.file_name()
|
||||
.to_str()
|
||||
.map(|s| s.starts_with('.'))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn vec_to_hashmap(
|
||||
|
Loading…
Reference in New Issue
Block a user