mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
follow system theme
This commit is contained in:
@@ -27,7 +27,7 @@ regex = "1.7.0"
|
|||||||
tokio = { version = "1.23.0", features = ["macros"] }
|
tokio = { version = "1.23.0", features = ["macros"] }
|
||||||
reqwest = "0.11.13"
|
reqwest = "0.11.13"
|
||||||
wry = "0.23.4"
|
wry = "0.23.4"
|
||||||
|
dark-light = "1.0.0"
|
||||||
[dependencies.tauri-plugin-log]
|
[dependencies.tauri-plugin-log]
|
||||||
git = "https://github.com/tauri-apps/tauri-plugin-log"
|
git = "https://github.com/tauri-apps/tauri-plugin-log"
|
||||||
branch = "dev"
|
branch = "dev"
|
||||||
|
|||||||
@@ -41,7 +41,9 @@ pub fn init() -> Menu {
|
|||||||
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 is_dark = chat_conf.theme == "Dark";
|
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 {
|
let stay_on_top_menu = if chat_conf.stay_on_top {
|
||||||
stay_on_top.selected()
|
stay_on_top.selected()
|
||||||
@@ -65,7 +67,7 @@ pub fn init() -> Menu {
|
|||||||
Submenu::new(
|
Submenu::new(
|
||||||
"Theme",
|
"Theme",
|
||||||
Menu::new()
|
Menu::new()
|
||||||
.add_item(if is_dark {
|
.add_item(if is_dark || is_system {
|
||||||
theme_light
|
theme_light
|
||||||
} else {
|
} else {
|
||||||
theme_light.selected()
|
theme_light.selected()
|
||||||
@@ -74,6 +76,11 @@ pub fn init() -> Menu {
|
|||||||
theme_dark.selected()
|
theme_dark.selected()
|
||||||
} else {
|
} else {
|
||||||
theme_dark
|
theme_dark
|
||||||
|
})
|
||||||
|
.add_item(if is_system {
|
||||||
|
theme_system.selected()
|
||||||
|
} else {
|
||||||
|
theme_system
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
@@ -230,9 +237,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_light" | "theme_dark" | "theme_system" => {
|
||||||
let theme = if menu_id == "theme_dark" {
|
let theme = if menu_id == "theme_dark" {
|
||||||
"Dark"
|
"Dark"
|
||||||
|
} else if menu_id == "theme_system" {
|
||||||
|
"System"
|
||||||
} else {
|
} else {
|
||||||
"Light"
|
"Light"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -177,7 +177,17 @@ 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 == "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)
|
Some(Theme::Dark)
|
||||||
} else {
|
} else {
|
||||||
Some(Theme::Light)
|
Some(Theme::Light)
|
||||||
|
|||||||
5
src/view/General.tsx
vendored
5
src/view/General.tsx
vendored
@@ -111,6 +111,11 @@ export default function General() {
|
|||||||
<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>
|
||||||
|
)
|
||||||
|
}
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked">
|
<Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked">
|
||||||
|
|||||||
Reference in New Issue
Block a user