chore: fmt

This commit is contained in:
lencx
2023-01-04 23:56:57 +08:00
parent 3dd49cd5d3
commit aa98d7dd2a
4 changed files with 27 additions and 26 deletions

View File

@@ -44,7 +44,7 @@ pub fn reset_chat_conf() -> ChatConfJson {
} }
#[command] #[command]
pub fn run_check_update(app: AppHandle) -> () { pub fn run_check_update(app: AppHandle) {
utils::run_check_update(app).unwrap(); utils::run_check_update(app).unwrap();
} }

View File

@@ -36,9 +36,11 @@ 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");
#[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");
let theme_light = CustomMenuItem::new("theme_light".to_string(), "Light"); let theme_light = CustomMenuItem::new("theme_light".to_string(), "Light");
let theme_dark = CustomMenuItem::new("theme_dark".to_string(), "Dark"); let theme_dark = CustomMenuItem::new("theme_dark".to_string(), "Dark");
let theme_system = CustomMenuItem::new("theme_system".to_string(), "System"); let theme_system = CustomMenuItem::new("theme_system".to_string(), "System");
@@ -50,6 +52,7 @@ pub fn init() -> Menu {
} else { } else {
stay_on_top stay_on_top
}; };
#[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()
@@ -237,13 +240,11 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
.unwrap(); .unwrap();
tauri::api::process::restart(&app.env()); tauri::api::process::restart(&app.env());
} }
"theme_light" | "theme_dark" | "theme_system" => { "theme_light" | "theme_dark" | "theme_system" => {
let theme = if menu_id == "theme_dark" { let theme = match menu_id {
"Dark" "theme_dark" => "Dark",
} else if menu_id == "theme_system" { "theme_system" => "System",
"System" _ => "Light",
} else {
"Light"
}; };
ChatConfJson::amend(&serde_json::json!({ "theme": theme }), Some(app)).unwrap(); ChatConfJson::amend(&serde_json::json!({ "theme": theme }), Some(app)).unwrap();
} }

View File

@@ -177,21 +177,20 @@ impl ChatConfJson {
pub fn theme() -> Option<Theme> { pub fn theme() -> Option<Theme> {
let conf = ChatConfJson::get_chat_conf(); let conf = ChatConfJson::get_chat_conf();
if conf.theme == "System" { let theme = match conf.theme.as_str() {
let mode = dark_light::detect(); "System" => match dark_light::detect() {
return match mode {
// Dark mode // Dark mode
dark_light::Mode::Dark => Some(Theme::Dark), dark_light::Mode::Dark => Theme::Dark,
// Light mode // Light mode
dark_light::Mode::Light => Some(Theme::Light), dark_light::Mode::Light => Theme::Light,
// Unspecified // Unspecified
dark_light::Mode::Default => Some(Theme::Light), dark_light::Mode::Default => Theme::Light,
} },
} if conf.theme == "Dark" { "Dark" => Theme::Dark,
Some(Theme::Dark) _ => Theme::Light,
} else { };
Some(Theme::Light)
} Some(theme)
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]

View File

@@ -8,8 +8,8 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
process::Command, process::Command,
}; };
use tauri::{utils::config::Config, Manager, AppHandle, Wry};
use tauri::updater::UpdateResponse; use tauri::updater::UpdateResponse;
use tauri::{utils::config::Config, AppHandle, Manager, Wry};
pub fn chat_root() -> PathBuf { pub fn chat_root() -> PathBuf {
tauri::api::path::home_dir().unwrap().join(".chatgpt") tauri::api::path::home_dir().unwrap().join(".chatgpt")
@@ -146,10 +146,7 @@ pub fn run_check_update(app: AppHandle<Wry>) -> Result<()> {
// Copy private api in tauri/updater/mod.rs. TODO: refactor to public api // Copy private api in tauri/updater/mod.rs. TODO: refactor to public api
// Prompt a dialog asking if the user want to install the new version // Prompt a dialog asking if the user want to install the new version
// Maybe we should add an option to customize it in future versions. // Maybe we should add an option to customize it in future versions.
pub async fn prompt_for_install ( pub async fn prompt_for_install(app: AppHandle<Wry>, update: UpdateResponse<Wry>) -> Result<()> {
app: AppHandle<Wry>,
update: UpdateResponse<Wry>
) -> Result<()> {
let windows = app.windows(); let windows = app.windows();
let parent_window = windows.values().next(); let parent_window = windows.values().next();
let package_info = app.package_info().clone(); let package_info = app.package_info().clone();
@@ -167,7 +164,11 @@ Would you like to install it now?
Release Notes: Release Notes:
{}"#, {}"#,
package_info.name, update.latest_version(), package_info.version, body), package_info.name,
update.latest_version(),
package_info.version,
body
),
); );
if should_install { if should_install {