mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: add rustfmt.toml
This commit is contained in:
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]
|
#[command]
|
||||||
pub fn window_reload(app: AppHandle, label: &str) {
|
pub fn window_reload(app: AppHandle, label: &str) {
|
||||||
app.app_handle()
|
app
|
||||||
|
.app_handle()
|
||||||
.get_window(label)
|
.get_window(label)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.eval("window.location.reload()")
|
.eval("window.location.reload()")
|
||||||
@@ -266,9 +267,7 @@ pub fn download_list(pathname: &str, dir: &str, filename: Option<String>, id: Op
|
|||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub async fn sync_prompts(app: AppHandle, time: u64) -> Option<Vec<ModelRecord>> {
|
pub async fn sync_prompts(app: AppHandle, time: u64) -> Option<Vec<ModelRecord>> {
|
||||||
let res = utils::get_data(GITHUB_PROMPTS_CSV_URL, Some(&app))
|
let res = utils::get_data(GITHUB_PROMPTS_CSV_URL, Some(&app)).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if let Some(v) = res {
|
if let Some(v) = res {
|
||||||
let data = parse_prompt(v)
|
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 = utils::chat_root().join("chat.model.json");
|
||||||
let model_cmd = utils::chat_root().join("chat.model.cmd.json");
|
let model_cmd = utils::chat_root().join("chat.model.cmd.json");
|
||||||
let chatgpt_prompts = utils::chat_root()
|
let chatgpt_prompts = utils::chat_root().join("cache_model").join("chatgpt_prompts.json");
|
||||||
.join("cache_model")
|
|
||||||
.join("chatgpt_prompts.json");
|
|
||||||
|
|
||||||
if !utils::exists(&model) {
|
if !utils::exists(&model) {
|
||||||
fs::write(
|
fs::write(
|
||||||
@@ -307,11 +304,7 @@ pub async fn sync_prompts(app: AppHandle, time: u64) -> Option<Vec<ModelRecord>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// chatgpt_prompts.json
|
// chatgpt_prompts.json
|
||||||
fs::write(
|
fs::write(chatgpt_prompts, serde_json::to_string_pretty(&data).unwrap()).unwrap();
|
||||||
chatgpt_prompts,
|
|
||||||
serde_json::to_string_pretty(&data).unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let cmd_data = cmd_list();
|
let cmd_data = cmd_list();
|
||||||
|
|
||||||
// chat.model.cmd.json
|
// chat.model.cmd.json
|
||||||
|
|||||||
@@ -75,7 +75,8 @@ pub struct Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn system_time_to_ms(time: std::io::Result<SystemTime>) -> u64 {
|
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();
|
let duration_since_epoch = t.duration_since(UNIX_EPOCH).unwrap();
|
||||||
duration_since_epoch.as_millis() as u64
|
duration_since_epoch.as_millis() as u64
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use crate::{
|
|||||||
utils,
|
utils,
|
||||||
};
|
};
|
||||||
use tauri::{
|
use tauri::{
|
||||||
AppHandle, CustomMenuItem, Manager, Menu, MenuItem, Submenu, SystemTray, SystemTrayEvent,
|
AppHandle, CustomMenuItem, Manager, Menu, MenuItem, Submenu, SystemTray, SystemTrayEvent, SystemTrayMenu,
|
||||||
SystemTrayMenu, SystemTrayMenuItem, WindowMenuEvent,
|
SystemTrayMenuItem, WindowMenuEvent,
|
||||||
};
|
};
|
||||||
use tauri_plugin_positioner::{on_tray_event, Position, WindowExt};
|
use tauri_plugin_positioner::{on_tray_event, Position, WindowExt};
|
||||||
|
|
||||||
@@ -33,8 +33,7 @@ pub fn init() -> Menu {
|
|||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
let stay_on_top =
|
let stay_on_top = CustomMenuItem::new("stay_on_top".to_string(), "Stay On Top").accelerator("CmdOrCtrl+T");
|
||||||
CustomMenuItem::new("stay_on_top".to_string(), "Stay On Top").accelerator("CmdOrCtrl+T");
|
|
||||||
let stay_on_top_menu = if chat_conf.stay_on_top {
|
let stay_on_top_menu = if chat_conf.stay_on_top {
|
||||||
stay_on_top.selected()
|
stay_on_top.selected()
|
||||||
} else {
|
} else {
|
||||||
@@ -59,8 +58,7 @@ pub fn init() -> Menu {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
let titlebar =
|
let titlebar = CustomMenuItem::new("titlebar".to_string(), "Titlebar").accelerator("CmdOrCtrl+B");
|
||||||
CustomMenuItem::new("titlebar".to_string(), "Titlebar").accelerator("CmdOrCtrl+B");
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
let titlebar_menu = if chat_conf.titlebar {
|
let titlebar_menu = if chat_conf.titlebar {
|
||||||
titlebar.selected()
|
titlebar.selected()
|
||||||
@@ -100,11 +98,7 @@ pub fn init() -> Menu {
|
|||||||
} else {
|
} else {
|
||||||
theme_light.selected()
|
theme_light.selected()
|
||||||
})
|
})
|
||||||
.add_item(if is_dark {
|
.add_item(if is_dark { theme_dark.selected() } else { theme_dark })
|
||||||
theme_dark.selected()
|
|
||||||
} else {
|
|
||||||
theme_dark
|
|
||||||
})
|
|
||||||
.add_item(if is_system {
|
.add_item(if is_system {
|
||||||
theme_system.selected()
|
theme_system.selected()
|
||||||
} else {
|
} else {
|
||||||
@@ -167,26 +161,14 @@ pub fn init() -> Menu {
|
|||||||
let view_menu = Submenu::new(
|
let view_menu = Submenu::new(
|
||||||
"View",
|
"View",
|
||||||
Menu::new()
|
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(
|
.add_item(
|
||||||
CustomMenuItem::new("go_back".to_string(), "Go Back").accelerator("CmdOrCtrl+Left"),
|
CustomMenuItem::new("scroll_bottom".to_string(), "Scroll to Bottom of Screen").accelerator("CmdOrCtrl+Down"),
|
||||||
)
|
|
||||||
.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"),
|
|
||||||
)
|
)
|
||||||
.add_native_item(MenuItem::Separator)
|
.add_native_item(MenuItem::Separator)
|
||||||
.add_item(
|
.add_item(CustomMenuItem::new("reload".to_string(), "Refresh the Screen").accelerator("CmdOrCtrl+R")),
|
||||||
CustomMenuItem::new("reload".to_string(), "Refresh the Screen")
|
|
||||||
.accelerator("CmdOrCtrl+R"),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let window_menu = Submenu::new(
|
let window_menu = Submenu::new(
|
||||||
@@ -201,15 +183,11 @@ pub fn init() -> Menu {
|
|||||||
let help_menu = Submenu::new(
|
let help_menu = Submenu::new(
|
||||||
"Help",
|
"Help",
|
||||||
Menu::new()
|
Menu::new()
|
||||||
.add_item(CustomMenuItem::new(
|
.add_item(CustomMenuItem::new("chatgpt_log".to_string(), "ChatGPT Log"))
|
||||||
"chatgpt_log".to_string(),
|
|
||||||
"ChatGPT Log",
|
|
||||||
))
|
|
||||||
.add_item(CustomMenuItem::new("update_log".to_string(), "Update 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("report_bug".to_string(), "Report Bug"))
|
||||||
.add_item(
|
.add_item(
|
||||||
CustomMenuItem::new("dev_tools".to_string(), "Toggle Developer Tools")
|
CustomMenuItem::new("dev_tools".to_string(), "Toggle Developer Tools").accelerator("CmdOrCtrl+Shift+I"),
|
||||||
.accelerator("CmdOrCtrl+Shift+I"),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -254,12 +232,8 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
"popup_search" => {
|
"popup_search" => {
|
||||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||||
let popup_search = !chat_conf.popup_search;
|
let popup_search = !chat_conf.popup_search;
|
||||||
menu_handle
|
menu_handle.get_item(menu_id).set_selected(popup_search).unwrap();
|
||||||
.get_item(menu_id)
|
ChatConfJson::amend(&serde_json::json!({ "popup_search": popup_search }), None).unwrap();
|
||||||
.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.clone(), "core");
|
||||||
cmd::window_reload(app, "tray");
|
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?",
|
"Data sync will enable all prompts, are you sure you want to sync?",
|
||||||
move |is_restart| {
|
move |is_restart| {
|
||||||
if is_restart {
|
if is_restart {
|
||||||
app.get_window("core")
|
app
|
||||||
|
.get_window("core")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.eval("window.__sync_prompts && window.__sync_prompts()")
|
.eval("window.__sync_prompts && window.__sync_prompts()")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -278,16 +253,10 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
"hide_dock_icon" => {
|
"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()
|
|
||||||
}
|
|
||||||
"titlebar" => {
|
"titlebar" => {
|
||||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||||
ChatConfJson::amend(
|
ChatConfJson::amend(&serde_json::json!({ "titlebar": !chat_conf.titlebar }), None).unwrap();
|
||||||
&serde_json::json!({ "titlebar": !chat_conf.titlebar }),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
tauri::api::process::restart(&app.env());
|
tauri::api::process::restart(&app.env());
|
||||||
}
|
}
|
||||||
"system_tray" => {
|
"system_tray" => {
|
||||||
@@ -310,24 +279,15 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
}
|
}
|
||||||
let auto_update = match menu_id {
|
let auto_update = match menu_id {
|
||||||
"update_silent" => {
|
"update_silent" => {
|
||||||
menu_handle
|
menu_handle.get_item("update_silent").set_selected(true).unwrap();
|
||||||
.get_item("update_silent")
|
|
||||||
.set_selected(true)
|
|
||||||
.unwrap();
|
|
||||||
"Silent"
|
"Silent"
|
||||||
}
|
}
|
||||||
"update_disable" => {
|
"update_disable" => {
|
||||||
menu_handle
|
menu_handle.get_item("update_disable").set_selected(true).unwrap();
|
||||||
.get_item("update_disable")
|
|
||||||
.set_selected(true)
|
|
||||||
.unwrap();
|
|
||||||
"Disable"
|
"Disable"
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
menu_handle
|
menu_handle.get_item("update_prompt").set_selected(true).unwrap();
|
||||||
.get_item("update_prompt")
|
|
||||||
.set_selected(true)
|
|
||||||
.unwrap();
|
|
||||||
"Prompt"
|
"Prompt"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -336,10 +296,7 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
"stay_on_top" => {
|
"stay_on_top" => {
|
||||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||||
let stay_on_top = !chat_conf.stay_on_top;
|
let stay_on_top = !chat_conf.stay_on_top;
|
||||||
menu_handle
|
menu_handle.get_item(menu_id).set_selected(stay_on_top).unwrap();
|
||||||
.get_item(menu_id)
|
|
||||||
.set_selected(stay_on_top)
|
|
||||||
.unwrap();
|
|
||||||
win.set_always_on_top(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();
|
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") {
|
if cfg!(target_os = "macos") {
|
||||||
SystemTray::new().with_menu(
|
SystemTray::new().with_menu(
|
||||||
SystemTrayMenu::new()
|
SystemTrayMenu::new()
|
||||||
.add_item(CustomMenuItem::new(
|
.add_item(CustomMenuItem::new("control_center".to_string(), "Control Center"))
|
||||||
"control_center".to_string(),
|
|
||||||
"Control Center",
|
|
||||||
))
|
|
||||||
.add_native_item(SystemTrayMenuItem::Separator)
|
.add_native_item(SystemTrayMenuItem::Separator)
|
||||||
.add_item(CustomMenuItem::new(
|
.add_item(CustomMenuItem::new("show_dock_icon".to_string(), "Show Dock Icon"))
|
||||||
"show_dock_icon".to_string(),
|
.add_item(CustomMenuItem::new("hide_dock_icon".to_string(), "Hide Dock Icon"))
|
||||||
"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_item(CustomMenuItem::new("show_core".to_string(), "Show ChatGPT"))
|
||||||
.add_native_item(SystemTrayMenuItem::Separator)
|
.add_native_item(SystemTrayMenuItem::Separator)
|
||||||
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")),
|
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")),
|
||||||
@@ -404,10 +352,7 @@ pub fn tray_menu() -> SystemTray {
|
|||||||
} else {
|
} else {
|
||||||
SystemTray::new().with_menu(
|
SystemTray::new().with_menu(
|
||||||
SystemTrayMenu::new()
|
SystemTrayMenu::new()
|
||||||
.add_item(CustomMenuItem::new(
|
.add_item(CustomMenuItem::new("control_center".to_string(), "Control Center"))
|
||||||
"control_center".to_string(),
|
|
||||||
"Control Center",
|
|
||||||
))
|
|
||||||
.add_item(CustomMenuItem::new("show_core".to_string(), "Show ChatGPT"))
|
.add_item(CustomMenuItem::new("show_core".to_string(), "Show ChatGPT"))
|
||||||
.add_native_item(SystemTrayMenuItem::Separator)
|
.add_native_item(SystemTrayMenuItem::Separator)
|
||||||
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")),
|
.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),
|
"control_center" => window::control_window(&app),
|
||||||
"restart" => tauri::api::process::restart(&handle.env()),
|
"restart" => tauri::api::process::restart(&handle.env()),
|
||||||
"show_dock_icon" => {
|
"show_dock_icon" => {
|
||||||
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": false }), Some(app))
|
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": false }), Some(app)).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
"hide_dock_icon" => {
|
"hide_dock_icon" => {
|
||||||
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
let chat_conf = conf::ChatConfJson::get_chat_conf();
|
||||||
if !chat_conf.hide_dock_icon {
|
if !chat_conf.hide_dock_icon {
|
||||||
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": true }), Some(app))
|
ChatConfJson::amend(&serde_json::json!({ "hide_dock_icon": true }), Some(app)).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"show_core" => {
|
"show_core" => {
|
||||||
|
|||||||
@@ -31,12 +31,7 @@ pub fn tray_window(handle: &tauri::AppHandle) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dalle2_window(
|
pub fn dalle2_window(handle: &tauri::AppHandle, query: Option<String>, title: Option<String>, is_new: Option<bool>) {
|
||||||
handle: &tauri::AppHandle,
|
|
||||||
query: Option<String>,
|
|
||||||
title: Option<String>,
|
|
||||||
is_new: Option<bool>,
|
|
||||||
) {
|
|
||||||
info!("dalle2_query: {:?}", query);
|
info!("dalle2_query: {:?}", query);
|
||||||
let theme = conf::ChatConfJson::theme();
|
let theme = conf::ChatConfJson::theme();
|
||||||
let app = handle.clone();
|
let app = handle.clone();
|
||||||
@@ -62,11 +57,7 @@ pub fn dalle2_window(
|
|||||||
|
|
||||||
if app.get_window("dalle2").is_none() {
|
if app.get_window("dalle2").is_none() {
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
WindowBuilder::new(
|
WindowBuilder::new(&app, label, WindowUrl::App("https://labs.openai.com".into()))
|
||||||
&app,
|
|
||||||
label,
|
|
||||||
WindowUrl::App("https://labs.openai.com".into()),
|
|
||||||
)
|
|
||||||
.title(title.unwrap_or_else(|| "DALL·E 2".to_string()))
|
.title(title.unwrap_or_else(|| "DALL·E 2".to_string()))
|
||||||
.resizable(true)
|
.resizable(true)
|
||||||
.fullscreen(false)
|
.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 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 AWESOME_URL: &str = "https://github.com/lencx/ChatGPT/blob/main/AWESOME.md";
|
||||||
pub const BUY_COFFEE: &str = "https://www.buymeacoffee.com/lencx";
|
pub const BUY_COFFEE: &str = "https://www.buymeacoffee.com/lencx";
|
||||||
pub const GITHUB_PROMPTS_CSV_URL: &str =
|
pub const GITHUB_PROMPTS_CSV_URL: &str = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv";
|
||||||
"https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv";
|
|
||||||
pub const DEFAULT_CHAT_CONF: &str = r#"{
|
pub const DEFAULT_CHAT_CONF: &str = r#"{
|
||||||
"stay_on_top": false,
|
"stay_on_top": false,
|
||||||
"auto_update": "Prompt",
|
"auto_update": "Prompt",
|
||||||
@@ -149,10 +148,7 @@ impl ChatConfJson {
|
|||||||
config.insert(k, v);
|
config.insert(k, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::write(
|
fs::write(ChatConfJson::conf_path(), serde_json::to_string_pretty(&config)?)?;
|
||||||
ChatConfJson::conf_path(),
|
|
||||||
serde_json::to_string_pretty(&config)?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
if let Some(handle) = app {
|
if let Some(handle) = app {
|
||||||
tauri::api::process::restart(&handle.env());
|
tauri::api::process::restart(&handle.env());
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#![cfg_attr(
|
#![cfg_attr(all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows")]
|
||||||
all(not(debug_assertions), target_os = "windows"),
|
|
||||||
windows_subsystem = "windows"
|
|
||||||
)]
|
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod conf;
|
mod conf;
|
||||||
@@ -51,10 +48,7 @@ async fn main() {
|
|||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.plugin(tauri_plugin_positioner::init())
|
.plugin(tauri_plugin_positioner::init())
|
||||||
.plugin(tauri_plugin_autostart::init(
|
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, None))
|
||||||
MacosLauncher::LaunchAgent,
|
|
||||||
None,
|
|
||||||
))
|
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
cmd::drag_window,
|
cmd::drag_window,
|
||||||
cmd::fullscreen,
|
cmd::fullscreen,
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ pub fn chat_root() -> PathBuf {
|
|||||||
|
|
||||||
pub fn get_tauri_conf() -> Option<Config> {
|
pub fn get_tauri_conf() -> Option<Config> {
|
||||||
let config_file = include_str!("../tauri.conf.json");
|
let config_file = include_str!("../tauri.conf.json");
|
||||||
let config: Config =
|
let config: Config = serde_json::from_str(config_file).expect("failed to parse tauri.conf.json");
|
||||||
serde_json::from_str(config_file).expect("failed to parse tauri.conf.json");
|
|
||||||
Some(config)
|
Some(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,11 +64,7 @@ pub fn open_file(path: PathBuf) {
|
|||||||
Command::new("open").arg("-R").arg(path).spawn().unwrap();
|
Command::new("open").arg("-R").arg(path).spawn().unwrap();
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
Command::new("explorer")
|
Command::new("explorer").arg("/select,").arg(path).spawn().unwrap();
|
||||||
.arg("/select,")
|
|
||||||
.arg(path)
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// https://askubuntu.com/a/31071
|
// https://askubuntu.com/a/31071
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
@@ -79,18 +74,16 @@ pub fn open_file(path: PathBuf) {
|
|||||||
pub fn clear_conf(app: &tauri::AppHandle) {
|
pub fn clear_conf(app: &tauri::AppHandle) {
|
||||||
let root = chat_root();
|
let root = chat_root();
|
||||||
let app2 = app.clone();
|
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());
|
let msg = format!(
|
||||||
tauri::api::dialog::ask(
|
"Path: {}\nAre you sure to clear all ChatGPT configurations? Please backup in advance if necessary!",
|
||||||
app.get_window("core").as_ref(),
|
root.to_string_lossy()
|
||||||
"Clear Config",
|
);
|
||||||
msg,
|
tauri::api::dialog::ask(app.get_window("core").as_ref(), "Clear Config", msg, move |is_ok| {
|
||||||
move |is_ok| {
|
|
||||||
if is_ok {
|
if is_ok {
|
||||||
fs::remove_dir_all(root).unwrap();
|
fs::remove_dir_all(root).unwrap();
|
||||||
tauri::api::process::restart(&app2.env());
|
tauri::api::process::restart(&app2.env());
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn merge(v: &Value, fields: &HashMap<String, Value>) -> Value {
|
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()
|
re.replace_all(&name, "_").to_lowercase()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_data(
|
pub async fn get_data(url: &str, app: Option<&tauri::AppHandle>) -> Result<Option<String>, reqwest::Error> {
|
||||||
url: &str,
|
|
||||||
app: Option<&tauri::AppHandle>,
|
|
||||||
) -> Result<Option<String>, reqwest::Error> {
|
|
||||||
let res = reqwest::get(url).await?;
|
let res = reqwest::get(url).await?;
|
||||||
let is_ok = res.status() == 200;
|
let is_ok = res.status() == 200;
|
||||||
let body = res.text().await?;
|
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 {
|
pub fn is_hidden(entry: &walkdir::DirEntry) -> bool {
|
||||||
entry
|
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
|
||||||
.file_name()
|
|
||||||
.to_str()
|
|
||||||
.map(|s| s.starts_with('.'))
|
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vec_to_hashmap(
|
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',
|
title: 'URL',
|
||||||
dataIndex: 'url',
|
dataIndex: 'url',
|
||||||
key: 'url',
|
key: 'url',
|
||||||
width: 120,
|
width: 200,
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// title: 'Icon',
|
// title: 'Icon',
|
||||||
@@ -33,7 +33,7 @@ export const awesomeColumns = () => [
|
|||||||
title: 'Category',
|
title: 'Category',
|
||||||
dataIndex: 'category',
|
dataIndex: 'category',
|
||||||
key: 'category',
|
key: 'category',
|
||||||
width: 200,
|
width: 120,
|
||||||
render: (v: string) => <Tag color="geekblue">{v}</Tag>
|
render: (v: string) => <Tag color="geekblue">{v}</Tag>
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user