mirror of
https://github.com/lencx/ChatGPT.git
synced 2024-10-01 01:06:13 -04:00
chore: add rustfmt.toml
This commit is contained in:
parent
5f1c33d750
commit
321007bb87
4
src-tauri/rustfmt.toml
Normal file
4
src-tauri/rustfmt.toml
Normal file
@ -0,0 +1,4 @@
|
||||
edition = "2021"
|
||||
max_width = 120
|
||||
tab_spaces = 2
|
||||
newline_style = "Auto"
|
@ -142,7 +142,8 @@ pub fn parse_prompt(data: String) -> Vec<PromptRecord> {
|
||||
|
||||
#[command]
|
||||
pub fn window_reload(app: AppHandle, label: &str) {
|
||||
app.app_handle()
|
||||
app
|
||||
.app_handle()
|
||||
.get_window(label)
|
||||
.unwrap()
|
||||
.eval("window.location.reload()")
|
||||
@ -266,9 +267,7 @@ 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)
|
||||
@ -290,9 +289,7 @@ 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(
|
||||
@ -307,11 +304,7 @@ 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
|
||||
|
@ -75,7 +75,8 @@ pub struct Metadata {
|
||||
}
|
||||
|
||||
pub fn system_time_to_ms(time: std::io::Result<SystemTime>) -> u64 {
|
||||
time.map(|t| {
|
||||
time
|
||||
.map(|t| {
|
||||
let duration_since_epoch = t.duration_since(UNIX_EPOCH).unwrap();
|
||||
duration_since_epoch.as_millis() as u64
|
||||
})
|
||||
|
@ -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,8 +33,7 @@ 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 {
|
||||
@ -59,8 +58,7 @@ pub fn init() -> Menu {
|
||||
};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let titlebar =
|
||||
CustomMenuItem::new("titlebar".to_string(), "Titlebar").accelerator("CmdOrCtrl+B");
|
||||
let titlebar = CustomMenuItem::new("titlebar".to_string(), "Titlebar").accelerator("CmdOrCtrl+B");
|
||||
#[cfg(target_os = "macos")]
|
||||
let titlebar_menu = if chat_conf.titlebar {
|
||||
titlebar.selected()
|
||||
@ -100,11 +98,7 @@ 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 {
|
||||
@ -167,26 +161,14 @@ pub fn init() -> Menu {
|
||||
let view_menu = Submenu::new(
|
||||
"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("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("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(
|
||||
@ -201,15 +183,11 @@ 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"),
|
||||
),
|
||||
);
|
||||
|
||||
@ -254,12 +232,8 @@ 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();
|
||||
ChatConfJson::amend(&serde_json::json!({ "popup_search": popup_search }), None)
|
||||
.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");
|
||||
}
|
||||
@ -270,7 +244,8 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
||||
"Data sync will enable all prompts, are you sure you want to sync?",
|
||||
move |is_restart| {
|
||||
if is_restart {
|
||||
app.get_window("core")
|
||||
app
|
||||
.get_window("core")
|
||||
.unwrap()
|
||||
.eval("window.__sync_prompts && window.__sync_prompts()")
|
||||
.unwrap()
|
||||
@ -278,16 +253,10 @@ 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" => {
|
||||
@ -310,24 +279,15 @@ 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"
|
||||
}
|
||||
};
|
||||
@ -336,10 +296,7 @@ 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();
|
||||
}
|
||||
@ -384,19 +341,10 @@ 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")),
|
||||
@ -404,10 +352,7 @@ 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")),
|
||||
@ -443,14 +388,12 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) {
|
||||
"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();
|
||||
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": false }), Some(app)).unwrap();
|
||||
}
|
||||
"hide_dock_icon" => {
|
||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||
if !chat_conf.hide_dock_icon {
|
||||
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": true }), Some(app))
|
||||
.unwrap();
|
||||
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": true }), Some(app)).unwrap();
|
||||
}
|
||||
}
|
||||
"show_core" => {
|
||||
|
@ -31,12 +31,7 @@ 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();
|
||||
@ -62,11 +57,7 @@ pub fn dalle2_window(
|
||||
|
||||
if app.get_window("dalle2").is_none() {
|
||||
tauri::async_runtime::spawn(async move {
|
||||
WindowBuilder::new(
|
||||
&app,
|
||||
label,
|
||||
WindowUrl::App("https://labs.openai.com".into()),
|
||||
)
|
||||
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)
|
||||
|
@ -15,8 +15,7 @@ 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",
|
||||
@ -149,10 +148,7 @@ 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,7 +1,4 @@
|
||||
#![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;
|
||||
@ -51,10 +48,7 @@ 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,
|
||||
|
@ -17,8 +17,7 @@ pub fn chat_root() -> PathBuf {
|
||||
|
||||
pub fn get_tauri_conf() -> Option<Config> {
|
||||
let config_file = include_str!("../tauri.conf.json");
|
||||
let config: Config =
|
||||
serde_json::from_str(config_file).expect("failed to parse tauri.conf.json");
|
||||
let config: Config = serde_json::from_str(config_file).expect("failed to parse tauri.conf.json");
|
||||
Some(config)
|
||||
}
|
||||
|
||||
@ -65,11 +64,7 @@ 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")]
|
||||
@ -79,18 +74,16 @@ pub fn open_file(path: PathBuf) {
|
||||
pub fn clear_conf(app: &tauri::AppHandle) {
|
||||
let root = chat_root();
|
||||
let app2 = app.clone();
|
||||
let msg = format!("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| {
|
||||
let msg = format!(
|
||||
"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());
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn merge(v: &Value, fields: &HashMap<String, Value>) -> Value {
|
||||
@ -111,10 +104,7 @@ 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?;
|
||||
@ -232,11 +222,7 @@ 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(
|
||||
|
4
src/view/awesome/config.tsx
vendored
4
src/view/awesome/config.tsx
vendored
@ -12,7 +12,7 @@ export const awesomeColumns = () => [
|
||||
title: 'URL',
|
||||
dataIndex: 'url',
|
||||
key: 'url',
|
||||
width: 120,
|
||||
width: 200,
|
||||
},
|
||||
// {
|
||||
// title: 'Icon',
|
||||
@ -33,7 +33,7 @@ export const awesomeColumns = () => [
|
||||
title: 'Category',
|
||||
dataIndex: 'category',
|
||||
key: 'category',
|
||||
width: 200,
|
||||
width: 120,
|
||||
render: (v: string) => <Tag color="geekblue">{v}</Tag>
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user