mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
Merge pull request #266 from lencx/dev
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use crate::utils;
|
use crate::utils;
|
||||||
use log::info;
|
use log::error;
|
||||||
use std::{fs, path::PathBuf};
|
use std::{fs, path::PathBuf};
|
||||||
use tauri::{api, command, AppHandle, Manager};
|
use tauri::{api, command, AppHandle, Manager};
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ pub async fn get_data(app: AppHandle, url: String, is_msg: Option<bool>) -> Opti
|
|||||||
utils::get_data(&url, None).await
|
utils::get_data(&url, None).await
|
||||||
};
|
};
|
||||||
res.unwrap_or_else(|err| {
|
res.unwrap_or_else(|err| {
|
||||||
info!("chatgpt_client_http_error: {}", err);
|
error!("chatgpt_client_http: {}", err);
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::{
|
|||||||
conf::GITHUB_PROMPTS_CSV_URL,
|
conf::GITHUB_PROMPTS_CSV_URL,
|
||||||
utils,
|
utils,
|
||||||
};
|
};
|
||||||
use log::info;
|
use log::{error, info};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::{collections::HashMap, fs, path::PathBuf, vec};
|
use std::{collections::HashMap, fs, path::PathBuf, vec};
|
||||||
use tauri::{api, command, AppHandle, Manager};
|
use tauri::{api, command, AppHandle, Manager};
|
||||||
@@ -29,7 +29,7 @@ pub fn parse_prompt(data: String) -> Vec<PromptRecord> {
|
|||||||
let mut list = vec![];
|
let mut list = vec![];
|
||||||
for result in rdr.deserialize() {
|
for result in rdr.deserialize() {
|
||||||
let record: PromptRecord = result.unwrap_or_else(|err| {
|
let record: PromptRecord = result.unwrap_or_else(|err| {
|
||||||
info!("parse_prompt_error: {}", err);
|
error!("parse_prompt: {}", err);
|
||||||
PromptRecord {
|
PromptRecord {
|
||||||
cmd: None,
|
cmd: None,
|
||||||
act: "".to_string(),
|
act: "".to_string(),
|
||||||
@@ -84,12 +84,12 @@ pub fn get_download_list(pathname: &str) -> (Vec<serde_json::Value>, PathBuf) {
|
|||||||
info!("get_download_list: {}", pathname);
|
info!("get_download_list: {}", pathname);
|
||||||
let download_path = utils::app_root().join(PathBuf::from(pathname));
|
let download_path = utils::app_root().join(PathBuf::from(pathname));
|
||||||
let content = fs::read_to_string(&download_path).unwrap_or_else(|err| {
|
let content = fs::read_to_string(&download_path).unwrap_or_else(|err| {
|
||||||
info!("download_list_error: {}", err);
|
error!("download_list: {}", err);
|
||||||
fs::write(&download_path, "[]").unwrap();
|
fs::write(&download_path, "[]").unwrap();
|
||||||
"[]".to_string()
|
"[]".to_string()
|
||||||
});
|
});
|
||||||
let list = serde_json::from_str::<Vec<serde_json::Value>>(&content).unwrap_or_else(|err| {
|
let list = serde_json::from_str::<Vec<serde_json::Value>>(&content).unwrap_or_else(|err| {
|
||||||
info!("download_list_parse_error: {}", err);
|
error!("download_list_parse: {}", err);
|
||||||
vec![]
|
vec![]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -249,13 +249,12 @@ pub async fn sync_prompts(app: AppHandle, time: u64) -> Option<Vec<ModelRecord>>
|
|||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub async fn sync_user_prompts(url: String, data_type: String) -> Option<Vec<ModelRecord>> {
|
pub async fn sync_user_prompts(url: String, data_type: String) -> Option<Vec<ModelRecord>> {
|
||||||
|
info!("sync_user_prompts: url => {}", url);
|
||||||
let res = utils::get_data(&url, None).await.unwrap_or_else(|err| {
|
let res = utils::get_data(&url, None).await.unwrap_or_else(|err| {
|
||||||
info!("chatgpt_http_error: {}", err);
|
error!("chatgpt_http: {}", err);
|
||||||
None
|
None
|
||||||
});
|
});
|
||||||
|
|
||||||
info!("chatgpt_http_url: {}", url);
|
|
||||||
|
|
||||||
if let Some(v) = res {
|
if let Some(v) = res {
|
||||||
let data;
|
let data;
|
||||||
if data_type == "csv" {
|
if data_type == "csv" {
|
||||||
@@ -264,11 +263,11 @@ pub async fn sync_user_prompts(url: String, data_type: String) -> Option<Vec<Mod
|
|||||||
} else if data_type == "json" {
|
} else if data_type == "json" {
|
||||||
info!("chatgpt_http_json_parse");
|
info!("chatgpt_http_json_parse");
|
||||||
data = serde_json::from_str(&v).unwrap_or_else(|err| {
|
data = serde_json::from_str(&v).unwrap_or_else(|err| {
|
||||||
info!("chatgpt_http_json_parse_error: {}", err);
|
error!("chatgpt_http_json_parse: {}", err);
|
||||||
vec![]
|
vec![]
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
info!("chatgpt_http_unknown_type");
|
error!("chatgpt_http_unknown_type");
|
||||||
data = vec![];
|
data = vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ pub fn init() -> Menu {
|
|||||||
|
|
||||||
let update_prompt = CustomMenuItem::new("update_prompt".to_string(), "Prompt");
|
let update_prompt = CustomMenuItem::new("update_prompt".to_string(), "Prompt");
|
||||||
let update_silent = CustomMenuItem::new("update_silent".to_string(), "Silent");
|
let update_silent = CustomMenuItem::new("update_silent".to_string(), "Silent");
|
||||||
let _update_disable = CustomMenuItem::new("update_disable".to_string(), "Disable");
|
// let _update_disable = CustomMenuItem::new("update_disable".to_string(), "Disable");
|
||||||
|
|
||||||
let popup_search = CustomMenuItem::new("popup_search".to_string(), "Pop-up Search");
|
let popup_search = CustomMenuItem::new("popup_search".to_string(), "Pop-up Search");
|
||||||
let popup_search_menu = if app_conf.popup_search {
|
let popup_search_menu = if app_conf.popup_search {
|
||||||
@@ -74,6 +74,7 @@ pub fn init() -> Menu {
|
|||||||
system_tray
|
system_tray
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let auto_update = app_conf.get_auto_update();
|
||||||
let preferences_menu = Submenu::new(
|
let preferences_menu = Submenu::new(
|
||||||
"Preferences",
|
"Preferences",
|
||||||
Menu::with_items([
|
Menu::with_items([
|
||||||
@@ -114,16 +115,16 @@ pub fn init() -> Menu {
|
|||||||
Submenu::new(
|
Submenu::new(
|
||||||
"Auto Update",
|
"Auto Update",
|
||||||
Menu::new()
|
Menu::new()
|
||||||
.add_item(if app_conf.auto_update == "Prompt" {
|
.add_item(if auto_update == "prompt" {
|
||||||
update_prompt.selected()
|
update_prompt.selected()
|
||||||
} else {
|
} else {
|
||||||
update_prompt
|
update_prompt
|
||||||
})
|
})
|
||||||
.add_item(if app_conf.auto_update == "Silent" {
|
.add_item(if auto_update == "silent" {
|
||||||
update_silent.selected()
|
update_silent.selected()
|
||||||
} else {
|
} else {
|
||||||
update_silent
|
update_silent
|
||||||
}), // .add_item(if app_conf.auto_update == "Disable" {
|
}), // .add_item(if auto_update == "disable" {
|
||||||
// update_disable.selected()
|
// update_disable.selected()
|
||||||
// } else {
|
// } else {
|
||||||
// update_disable
|
// update_disable
|
||||||
@@ -321,21 +322,21 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
.get_item("update_silent")
|
.get_item("update_silent")
|
||||||
.set_selected(true)
|
.set_selected(true)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
"Silent"
|
"silent"
|
||||||
}
|
}
|
||||||
"update_disable" => {
|
"update_disable" => {
|
||||||
menu_handle
|
menu_handle
|
||||||
.get_item("update_disable")
|
.get_item("update_disable")
|
||||||
.set_selected(true)
|
.set_selected(true)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
"Disable"
|
"disable"
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
menu_handle
|
menu_handle
|
||||||
.get_item("update_prompt")
|
.get_item("update_prompt")
|
||||||
.set_selected(true)
|
.set_selected(true)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
"Prompt"
|
"prompt"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AppConf::read()
|
AppConf::read()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::{app::window, conf::AppConf, utils};
|
use crate::{app::window, conf::AppConf, utils};
|
||||||
use log::info;
|
use log::{error, info};
|
||||||
use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, GlobalShortcutManager, Manager};
|
use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, GlobalShortcutManager, Manager};
|
||||||
use wry::application::accelerator::Accelerator;
|
use wry::application::accelerator::Accelerator;
|
||||||
|
|
||||||
@@ -33,11 +33,11 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|err| {
|
.unwrap_or_else(|err| {
|
||||||
info!("global_shortcut_register_error: {}", err);
|
error!("global_shortcut_register_error: {}", err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
info!("global_shortcut_parse_error: {}", err);
|
error!("global_shortcut_parse_error: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -93,10 +93,11 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// auto_update
|
// auto_update
|
||||||
if app_conf.auto_update != "Disable" {
|
let auto_update = app_conf.get_auto_update();
|
||||||
info!("stepup::run_check_update");
|
if auto_update != "disable" {
|
||||||
|
info!("run_check_update");
|
||||||
let app = app.handle();
|
let app = app.handle();
|
||||||
utils::run_check_update(app, app_conf.auto_update == "Silent", None);
|
utils::run_check_update(app, auto_update == "silent", None);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ macro_rules! pub_struct {
|
|||||||
pub_struct!(AppConf {
|
pub_struct!(AppConf {
|
||||||
titlebar: bool,
|
titlebar: bool,
|
||||||
hide_dock_icon: bool,
|
hide_dock_icon: bool,
|
||||||
// macOS and Windows: Light / Dark / System
|
// macOS and Windows: light / dark / system
|
||||||
theme: String,
|
theme: String,
|
||||||
// auto update policy: Prompt / Silent / Disable
|
// auto update policy: prompt / silent / disable
|
||||||
auto_update: String,
|
auto_update: String,
|
||||||
tray: bool,
|
tray: bool,
|
||||||
popup_search: bool,
|
popup_search: bool,
|
||||||
@@ -54,8 +54,8 @@ impl AppConf {
|
|||||||
Self {
|
Self {
|
||||||
titlebar: !cfg!(target_os = "macos"),
|
titlebar: !cfg!(target_os = "macos"),
|
||||||
hide_dock_icon: false,
|
hide_dock_icon: false,
|
||||||
theme: "Light".into(),
|
theme: "light".into(),
|
||||||
auto_update: "Prompt".into(),
|
auto_update: "prompt".into(),
|
||||||
tray: true,
|
tray: true,
|
||||||
popup_search: false,
|
popup_search: false,
|
||||||
stay_on_top: false,
|
stay_on_top: false,
|
||||||
@@ -88,15 +88,15 @@ impl AppConf {
|
|||||||
let path = &Self::file_path();
|
let path = &Self::file_path();
|
||||||
if !exists(path) {
|
if !exists(path) {
|
||||||
create_file(path).unwrap();
|
create_file(path).unwrap();
|
||||||
info!("conf_init")
|
info!("conf_create");
|
||||||
}
|
}
|
||||||
if let Ok(v) = serde_json::to_string_pretty(&self) {
|
if let Ok(v) = serde_json::to_string_pretty(&self) {
|
||||||
std::fs::write(path, v).unwrap_or_else(|err| {
|
std::fs::write(path, v).unwrap_or_else(|err| {
|
||||||
error!("conf_write_error: {}", err);
|
error!("conf_write: {}", err);
|
||||||
Self::default().write();
|
Self::default().write();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
error!("conf_ser_error");
|
error!("conf_ser");
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -114,12 +114,12 @@ impl AppConf {
|
|||||||
Ok(v) => match serde_json::from_str::<AppConf>(&v) {
|
Ok(v) => match serde_json::from_str::<AppConf>(&v) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("conf_amend_parse_error: {}", err);
|
error!("conf_amend_parse: {}", err);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("conf_amend_str_error: {}", err);
|
error!("conf_amend_str: {}", err);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ impl AppConf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn theme_mode() -> Theme {
|
pub fn theme_mode() -> Theme {
|
||||||
match cmd::get_theme().to_lowercase().as_str() {
|
match Self::get_theme().as_str() {
|
||||||
"system" => match dark_light::detect() {
|
"system" => match dark_light::detect() {
|
||||||
// Dark mode
|
// Dark mode
|
||||||
dark_light::Mode::Dark => Theme::Dark,
|
dark_light::Mode::Dark => Theme::Dark,
|
||||||
@@ -149,6 +149,14 @@ impl AppConf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_theme() -> String {
|
||||||
|
Self::read().theme.to_lowercase()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_auto_update(self) -> String {
|
||||||
|
self.auto_update.to_lowercase()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn theme_check(self, mode: &str) -> bool {
|
pub fn theme_check(self, mode: &str) -> bool {
|
||||||
self.theme.to_lowercase() == mode
|
self.theme.to_lowercase() == mode
|
||||||
}
|
}
|
||||||
@@ -180,7 +188,7 @@ pub mod cmd {
|
|||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub fn get_theme() -> String {
|
pub fn get_theme() -> String {
|
||||||
AppConf::read().theme
|
AppConf::get_theme()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
|
|||||||
@@ -54,16 +54,6 @@ async fn main() {
|
|||||||
None,
|
None,
|
||||||
))
|
))
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
conf::cmd::get_app_conf,
|
|
||||||
conf::cmd::reset_app_conf,
|
|
||||||
conf::cmd::get_theme,
|
|
||||||
conf::cmd::form_confirm,
|
|
||||||
conf::cmd::form_cancel,
|
|
||||||
conf::cmd::form_msg,
|
|
||||||
window::cmd::wa_window,
|
|
||||||
window::cmd::control_window,
|
|
||||||
window::cmd::window_reload,
|
|
||||||
window::cmd::dalle2_search_window,
|
|
||||||
cmd::drag_window,
|
cmd::drag_window,
|
||||||
cmd::fullscreen,
|
cmd::fullscreen,
|
||||||
cmd::download,
|
cmd::download,
|
||||||
@@ -80,6 +70,16 @@ async fn main() {
|
|||||||
gpt::download_list,
|
gpt::download_list,
|
||||||
gpt::get_download_list,
|
gpt::get_download_list,
|
||||||
fs_extra::metadata,
|
fs_extra::metadata,
|
||||||
|
conf::cmd::get_app_conf,
|
||||||
|
conf::cmd::reset_app_conf,
|
||||||
|
conf::cmd::get_theme,
|
||||||
|
conf::cmd::form_confirm,
|
||||||
|
conf::cmd::form_cancel,
|
||||||
|
conf::cmd::form_msg,
|
||||||
|
window::cmd::wa_window,
|
||||||
|
window::cmd::control_window,
|
||||||
|
window::cmd::window_reload,
|
||||||
|
window::cmd::dalle2_search_window,
|
||||||
])
|
])
|
||||||
.setup(setup::init)
|
.setup(setup::init)
|
||||||
.menu(menu::init());
|
.menu(menu::init());
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::info;
|
use log::{error, info};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::{
|
use std::{
|
||||||
@@ -145,7 +145,7 @@ pub async fn get_data(
|
|||||||
if is_ok {
|
if is_ok {
|
||||||
Ok(Some(body))
|
Ok(Some(body))
|
||||||
} else {
|
} else {
|
||||||
info!("chatgpt_http_error: {}", body);
|
error!("chatgpt_http: {}", body);
|
||||||
if let Some(v) = app {
|
if let Some(v) = app {
|
||||||
tauri::api::dialog::message(v.get_window("core").as_ref(), "ChatGPT HTTP", body);
|
tauri::api::dialog::message(v.get_window("core").as_ref(), "ChatGPT HTTP", body);
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/view/settings/General.tsx
vendored
10
src/view/settings/General.tsx
vendored
@@ -30,16 +30,16 @@ export default function General() {
|
|||||||
)}
|
)}
|
||||||
<Form.Item label="Theme" name="theme">
|
<Form.Item label="Theme" name="theme">
|
||||||
<Radio.Group>
|
<Radio.Group>
|
||||||
<Radio value="Light">Light</Radio>
|
<Radio value="light">Light</Radio>
|
||||||
<Radio value="Dark">Dark</Radio>
|
<Radio value="dark">Dark</Radio>
|
||||||
{['darwin', 'windows'].includes(platformInfo) && <Radio value="System">System</Radio>}
|
{['darwin', 'windows'].includes(platformInfo) && <Radio value="System">System</Radio>}
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={<AutoUpdateLabel />} name="auto_update">
|
<Form.Item label={<AutoUpdateLabel />} name="auto_update">
|
||||||
<Radio.Group>
|
<Radio.Group>
|
||||||
<Radio value="Prompt">Prompt</Radio>
|
<Radio value="prompt">Prompt</Radio>
|
||||||
<Radio value="Silent">Silent</Radio>
|
<Radio value="silent">Silent</Radio>
|
||||||
{/*<Radio value="Disable">Disable</Radio>*/}
|
{/*<Radio value="disable">Disable</Radio>*/}
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={<GlobalShortcutLabel />} name="global_shortcut">
|
<Form.Item label={<GlobalShortcutLabel />} name="global_shortcut">
|
||||||
|
|||||||
Reference in New Issue
Block a user