diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index 5b01d25..c0c6ff8 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -1,6 +1,7 @@ export const defaultConfig: IAppConfig = { core: 'mihomo', silentStart: false, + appTheme: 'system', proxyDisplayMode: 'simple', proxyDisplayOrder: 'default', autoCheckUpdate: true, diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 8c3b50e..9ae49fc 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -18,30 +18,18 @@ import LogCard from '@renderer/components/sider/log-card' import MihomoCoreCard from '@renderer/components/sider/mihomo-core-card' import ResourceCard from '@renderer/components/sider/resource-card' import UpdaterButton from '@renderer/components/updater/updater-button' +import { useAppConfig } from './hooks/use-app-config' const App: React.FC = () => { + const { appConfig } = useAppConfig() + const { appTheme = 'system' } = appConfig || {} const { setTheme } = useTheme() const navigate = useNavigate() const location = useLocation() const page = useRoutes(routes) useEffect(() => { - try { - if (window.matchMedia('(prefers-color-scheme: dark)').matches) { - setTheme('dark') - } else { - setTheme('light') - } - window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => { - if (e.matches) { - setTheme('dark') - } else { - setTheme('light') - } - }) - } catch { - throw new Error('Failed to set theme') - } + setTheme(appTheme) }, []) return ( diff --git a/src/renderer/src/components/profiles/edit-file-modal.tsx b/src/renderer/src/components/profiles/edit-file-modal.tsx index 8f65a7f..a9f2277 100644 --- a/src/renderer/src/components/profiles/edit-file-modal.tsx +++ b/src/renderer/src/components/profiles/edit-file-modal.tsx @@ -40,7 +40,7 @@ const EditFileModal: React.FC = (props) => { height="100%" language="yaml" value={currData} - theme={theme === 'dark' ? 'vs-dark' : 'vs'} + theme={theme === 'light' ? 'vs' : 'vs-dark'} options={{ minimap: { enabled: false diff --git a/src/renderer/src/components/proxies/proxy-item.tsx b/src/renderer/src/components/proxies/proxy-item.tsx index a6138ea..a0dfd2c 100644 --- a/src/renderer/src/components/proxies/proxy-item.tsx +++ b/src/renderer/src/components/proxies/proxy-item.tsx @@ -58,7 +58,7 @@ const ProxyItem: React.FC = (props) => { onPress={() => onSelect(group.name, proxy.name)} isPressable fullWidth - className={`${selected ? 'bg-primary/30' : ''}`} + className={`${selected ? 'bg-primary/30' : 'bg-content2'}`} radius="sm" > diff --git a/src/renderer/src/components/sider/config-viewer.tsx b/src/renderer/src/components/sider/config-viewer.tsx index 26b04dd..2faabfd 100644 --- a/src/renderer/src/components/sider/config-viewer.tsx +++ b/src/renderer/src/components/sider/config-viewer.tsx @@ -39,7 +39,7 @@ const ConfigViewer: React.FC = (props) => { height="100%" language="yaml" value={currData} - theme={theme === 'dark' ? 'vs-dark' : 'vs'} + theme={theme === 'light' ? 'vs' : 'vs-dark'} options={{ readOnly: true, minimap: { diff --git a/src/renderer/src/components/sysproxy/pac-editor-modal.tsx b/src/renderer/src/components/sysproxy/pac-editor-modal.tsx index 934f775..2d0821c 100644 --- a/src/renderer/src/components/sysproxy/pac-editor-modal.tsx +++ b/src/renderer/src/components/sysproxy/pac-editor-modal.tsx @@ -32,7 +32,7 @@ const PacEditorViewer: React.FC = (props) => { height="100%" language="javascript" value={currData} - theme={theme === 'dark' ? 'vs-dark' : 'vs'} + theme={theme === 'light' ? 'vs' : 'vs-dark'} options={{ minimap: { enabled: false diff --git a/src/renderer/src/main.tsx b/src/renderer/src/main.tsx index 5f67e3f..fe9000a 100644 --- a/src/renderer/src/main.tsx +++ b/src/renderer/src/main.tsx @@ -11,7 +11,12 @@ init().then(() => { ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( - + diff --git a/src/renderer/src/pages/settings.tsx b/src/renderer/src/pages/settings.tsx index 6d707d9..930e217 100644 --- a/src/renderer/src/pages/settings.tsx +++ b/src/renderer/src/pages/settings.tsx @@ -1,4 +1,4 @@ -import { Button, Input, Switch } from '@nextui-org/react' +import { Button, Input, Switch, Tab, Tabs } from '@nextui-org/react' import BasePage from '@renderer/components/base/base-page' import SettingCard from '@renderer/components/base/base-setting-card' import SettingItem from '@renderer/components/base/base-setting-item' @@ -15,20 +15,22 @@ import { version } from '@renderer/utils/init' import useSWR from 'swr' import { useState } from 'react' import debounce from '@renderer/utils/debounce' +import { useTheme } from 'next-themes' const Settings: React.FC = () => { + const { setTheme } = useTheme() const { data: enable, mutate } = useSWR('checkAutoRun', checkAutoRun, { errorRetryCount: 5, errorRetryInterval: 200 }) - const { appConfig, patchAppConfig } = useAppConfig() const { silentStart = false, delayTestUrl, delayTestTimeout, autoCheckUpdate, - userAgent + userAgent, + appTheme = 'system' } = appConfig || {} const [url, setUrl] = useState(delayTestUrl) const [ua, setUa] = useState(userAgent) @@ -72,7 +74,7 @@ const Settings: React.FC = () => { }} /> - + { }} /> + + { + console.log(key) + setTheme(key as AppTheme) + + patchAppConfig({ appTheme: key as AppTheme }) + }} + > + + + + + + diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index c58d1a9..d56fecd 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -1,6 +1,7 @@ type OutboundMode = 'rule' | 'global' | 'direct' type LogLevel = 'info' | 'debug' | 'warning' | 'error' | 'silent' type SysProxyMode = 'auto' | 'manual' +type AppTheme = 'system' | 'light' | 'dark' | 'gray' type MihomoGroupType = 'Selector' | 'URLTest' | 'LoadBalance' | 'Relay' type MihomoProxyType = | 'Direct' @@ -191,6 +192,7 @@ interface IAppConfig { core: 'mihomo' | 'mihomo-alpha' proxyDisplayMode: 'simple' | 'full' proxyDisplayOrder: 'default' | 'delay' | 'name' + appTheme: AppTheme autoCheckUpdate: boolean silentStart: boolean sysProxy: ISysProxyConfig diff --git a/tailwind.config.js b/tailwind.config.js index ac1ec3b..033322a 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -10,5 +10,27 @@ module.exports = { extend: {} }, darkMode: 'class', - plugins: [nextui()] + plugins: [ + nextui({ + themes: { + gray: { + extend: 'dark', + colors: { + background: '#18181b', + content1: '#27272a', + content2: '#3f3f46', + content3: '#52525b', + default: { + DEFAULT: '#52525b', + 50: '#27272a', + 100: '#3f3f46', + 200: '#52525b', + 300: '#71717a', + 400: '#a1a1aa' + } + } + } + } + }) + ] }