mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: use OS default window manager
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
"deep-link:default",
|
"deep-link:default",
|
||||||
"autostart:allow-enable",
|
"autostart:allow-enable",
|
||||||
"autostart:allow-disable",
|
"autostart:allow-disable",
|
||||||
"autostart:allow-is-enabled"
|
"autostart:allow-is-enabled",
|
||||||
|
"core:window:allow-set-theme"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ pub fn create_window(is_show: bool) -> bool {
|
|||||||
)
|
)
|
||||||
.title("Clash Verge")
|
.title("Clash Verge")
|
||||||
.center()
|
.center()
|
||||||
.decorations(false)
|
.decorations(true)
|
||||||
.fullscreen(false)
|
.fullscreen(false)
|
||||||
.inner_size(DEFAULT_WIDTH as f64, DEFAULT_HEIGHT as f64)
|
.inner_size(DEFAULT_WIDTH as f64, DEFAULT_HEIGHT as f64)
|
||||||
.min_inner_size(520.0, 520.0)
|
.min_inner_size(520.0, 520.0)
|
||||||
|
|||||||
@@ -58,12 +58,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"app": {
|
"app": {
|
||||||
"windows": [
|
|
||||||
{
|
|
||||||
"label": "main",
|
|
||||||
"titleBarStyle": "Overlay"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"security": {
|
"security": {
|
||||||
"capabilities": [
|
"capabilities": [
|
||||||
"desktop-capability",
|
"desktop-capability",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import { alpha, createTheme, Shadows, Theme } from "@mui/material";
|
import { alpha, createTheme, Shadows, Theme as MuiTheme } from "@mui/material";
|
||||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
import { getCurrentWebviewWindow, WebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||||
import { useSetThemeMode, useThemeMode } from "@/services/states";
|
import { useSetThemeMode, useThemeMode } from "@/services/states";
|
||||||
import { defaultTheme, defaultDarkTheme } from "@/pages/_theme";
|
import { defaultTheme, defaultDarkTheme } from "@/pages/_theme";
|
||||||
import { useVerge } from "@/hooks/use-verge";
|
import { useVerge } from "@/hooks/use-verge";
|
||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
arSD as arXDataGrid,
|
arSD as arXDataGrid,
|
||||||
} from "@mui/x-data-grid/locales";
|
} from "@mui/x-data-grid/locales";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
const appWindow = getCurrentWebviewWindow();
|
import { Theme as TauriOsTheme } from "@tauri-apps/api/window";
|
||||||
|
|
||||||
const languagePackMap: Record<string, any> = {
|
const languagePackMap: Record<string, any> = {
|
||||||
zh: { ...zhXDataGrid },
|
zh: { ...zhXDataGrid },
|
||||||
@@ -29,6 +29,7 @@ const getLanguagePackMap = (key: string) =>
|
|||||||
* custom theme
|
* custom theme
|
||||||
*/
|
*/
|
||||||
export const useCustomTheme = () => {
|
export const useCustomTheme = () => {
|
||||||
|
const appWindow: WebviewWindow = getCurrentWebviewWindow();
|
||||||
const { verge } = useVerge();
|
const { verge } = useVerge();
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
const { theme_mode, theme_setting } = verge ?? {};
|
const { theme_mode, theme_setting } = verge ?? {};
|
||||||
@@ -36,28 +37,42 @@ export const useCustomTheme = () => {
|
|||||||
const setMode = useSetThemeMode();
|
const setMode = useSetThemeMode();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const themeMode = ["light", "dark", "system"].includes(theme_mode!)
|
const themeModeSetting = ["light", "dark", "system"].includes(theme_mode!)
|
||||||
? theme_mode!
|
? theme_mode!
|
||||||
: "light";
|
: "light";
|
||||||
|
|
||||||
if (themeMode !== "system") {
|
if (themeModeSetting !== "system") {
|
||||||
setMode(themeMode);
|
setMode(themeModeSetting as 'light' | 'dark');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
appWindow.theme().then((m) => m && setMode(m));
|
appWindow.theme().then((systemTheme: 'light' | 'dark' | null) => {
|
||||||
const unlisten = appWindow.onThemeChanged((e) => setMode(e.payload));
|
if (systemTheme) {
|
||||||
|
setMode(systemTheme);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const unlisten = appWindow.onThemeChanged(({ payload }: { payload: 'light' | 'dark' }) => {
|
||||||
|
setMode(payload);
|
||||||
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unlisten.then((fn) => fn());
|
unlisten.then((fn: () => void) => fn());
|
||||||
};
|
};
|
||||||
}, [theme_mode]);
|
}, [theme_mode, setMode, i18n, theme_setting, appWindow]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (mode) {
|
||||||
|
appWindow.setTheme(mode as TauriOsTheme).catch((err: any) => {
|
||||||
|
console.error("Failed to set window theme:", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [mode, appWindow]);
|
||||||
|
|
||||||
const theme = useMemo(() => {
|
const theme = useMemo(() => {
|
||||||
const setting = theme_setting || {};
|
const setting = theme_setting || {};
|
||||||
const dt = mode === "light" ? defaultTheme : defaultDarkTheme;
|
const dt = mode === "light" ? defaultTheme : defaultDarkTheme;
|
||||||
|
|
||||||
let theme: Theme;
|
let theme: MuiTheme;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
theme = createTheme(
|
theme = createTheme(
|
||||||
|
|||||||
Reference in New Issue
Block a user