1
0
mirror of https://github.com/lencx/ChatGPT.git synced 2024-10-01 01:06:13 -04:00

Merge pull request #145 from tk103331/main

This commit is contained in:
lencx 2023-01-04 17:16:46 +08:00 committed by GitHub
commit 5286de2f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 4 deletions

View File

@ -27,7 +27,7 @@ regex = "1.7.0"
tokio = { version = "1.23.0", features = ["macros"] }
reqwest = "0.11.13"
wry = "0.23.4"
dark-light = "1.0.0"
[dependencies.tauri-plugin-log]
git = "https://github.com/tauri-apps/tauri-plugin-log"
branch = "dev"

View File

@ -41,7 +41,9 @@ pub fn init() -> Menu {
CustomMenuItem::new("titlebar".to_string(), "Titlebar").accelerator("CmdOrCtrl+B");
let theme_light = CustomMenuItem::new("theme_light".to_string(), "Light");
let theme_dark = CustomMenuItem::new("theme_dark".to_string(), "Dark");
let theme_system = CustomMenuItem::new("theme_system".to_string(), "System");
let is_dark = chat_conf.theme == "Dark";
let is_system = chat_conf.theme == "System";
let stay_on_top_menu = if chat_conf.stay_on_top {
stay_on_top.selected()
@ -65,7 +67,7 @@ pub fn init() -> Menu {
Submenu::new(
"Theme",
Menu::new()
.add_item(if is_dark {
.add_item(if is_dark || is_system {
theme_light
} else {
theme_light.selected()
@ -74,6 +76,11 @@ pub fn init() -> Menu {
theme_dark.selected()
} else {
theme_dark
})
.add_item(if is_system {
theme_system.selected()
} else {
theme_system
}),
)
.into(),
@ -230,9 +237,11 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
.unwrap();
tauri::api::process::restart(&app.env());
}
"theme_light" | "theme_dark" => {
"theme_light" | "theme_dark" | "theme_system" => {
let theme = if menu_id == "theme_dark" {
"Dark"
} else if menu_id == "theme_system" {
"System"
} else {
"Light"
};

View File

@ -177,7 +177,17 @@ impl ChatConfJson {
pub fn theme() -> Option<Theme> {
let conf = ChatConfJson::get_chat_conf();
if conf.theme == "Dark" {
if conf.theme == "System" {
let mode = dark_light::detect();
return match mode {
// Dark mode
dark_light::Mode::Dark => Some(Theme::Dark),
// Light mode
dark_light::Mode::Light => Some(Theme::Light),
// Unspecified
dark_light::Mode::Default => Some(Theme::Light),
}
} if conf.theme == "Dark" {
Some(Theme::Dark)
} else {
Some(Theme::Light)

View File

@ -111,6 +111,11 @@ export default function General() {
<Radio.Group>
<Radio value="Light">Light</Radio>
<Radio value="Dark">Dark</Radio>
{
(["darwin", "windows"].includes(platformInfo) ) && (
<Radio value="System">System</Radio>
)
}
</Radio.Group>
</Form.Item>
<Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked">