Skip to content

Commit 2959cee

Browse files
author
pompurin404
committed
add gray theme
1 parent ab30a2e commit 2959cee

File tree

10 files changed

+64
-26
lines changed

10 files changed

+64
-26
lines changed

src/main/utils/template.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const defaultConfig: IAppConfig = {
22
core: 'mihomo',
33
silentStart: false,
4+
appTheme: 'system',
45
proxyDisplayMode: 'simple',
56
proxyDisplayOrder: 'default',
67
autoCheckUpdate: true,

src/renderer/src/App.tsx

+4-16
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,18 @@ import LogCard from '@renderer/components/sider/log-card'
1818
import MihomoCoreCard from '@renderer/components/sider/mihomo-core-card'
1919
import ResourceCard from '@renderer/components/sider/resource-card'
2020
import UpdaterButton from '@renderer/components/updater/updater-button'
21+
import { useAppConfig } from './hooks/use-app-config'
2122

2223
const App: React.FC = () => {
24+
const { appConfig } = useAppConfig()
25+
const { appTheme = 'system' } = appConfig || {}
2326
const { setTheme } = useTheme()
2427
const navigate = useNavigate()
2528
const location = useLocation()
2629
const page = useRoutes(routes)
2730

2831
useEffect(() => {
29-
try {
30-
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
31-
setTheme('dark')
32-
} else {
33-
setTheme('light')
34-
}
35-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
36-
if (e.matches) {
37-
setTheme('dark')
38-
} else {
39-
setTheme('light')
40-
}
41-
})
42-
} catch {
43-
throw new Error('Failed to set theme')
44-
}
32+
setTheme(appTheme)
4533
}, [])
4634

4735
return (

src/renderer/src/components/profiles/edit-file-modal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const EditFileModal: React.FC<Props> = (props) => {
4040
height="100%"
4141
language="yaml"
4242
value={currData}
43-
theme={theme === 'dark' ? 'vs-dark' : 'vs'}
43+
theme={theme === 'light' ? 'vs' : 'vs-dark'}
4444
options={{
4545
minimap: {
4646
enabled: false

src/renderer/src/components/proxies/proxy-item.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const ProxyItem: React.FC<Props> = (props) => {
5858
onPress={() => onSelect(group.name, proxy.name)}
5959
isPressable
6060
fullWidth
61-
className={`${selected ? 'bg-primary/30' : ''}`}
61+
className={`${selected ? 'bg-primary/30' : 'bg-content2'}`}
6262
radius="sm"
6363
>
6464
<CardBody className="p-2">

src/renderer/src/components/sider/config-viewer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const ConfigViewer: React.FC<Props> = (props) => {
3939
height="100%"
4040
language="yaml"
4141
value={currData}
42-
theme={theme === 'dark' ? 'vs-dark' : 'vs'}
42+
theme={theme === 'light' ? 'vs' : 'vs-dark'}
4343
options={{
4444
readOnly: true,
4545
minimap: {

src/renderer/src/components/sysproxy/pac-editor-modal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const PacEditorViewer: React.FC<Props> = (props) => {
3232
height="100%"
3333
language="javascript"
3434
value={currData}
35-
theme={theme === 'dark' ? 'vs-dark' : 'vs'}
35+
theme={theme === 'light' ? 'vs' : 'vs-dark'}
3636
options={{
3737
minimap: {
3838
enabled: false

src/renderer/src/main.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ init().then(() => {
1111
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
1212
<React.StrictMode>
1313
<NextUIProvider>
14-
<NextThemesProvider attribute="class" defaultTheme="dark">
14+
<NextThemesProvider
15+
attribute="class"
16+
themes={['light', 'dark', 'gray']}
17+
enableSystem
18+
defaultTheme="dark"
19+
>
1520
<HashRouter>
1621
<App />
1722
</HashRouter>

src/renderer/src/pages/settings.tsx

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Button, Input, Switch } from '@nextui-org/react'
1+
import { Button, Input, Switch, Tab, Tabs } from '@nextui-org/react'
22
import BasePage from '@renderer/components/base/base-page'
33
import SettingCard from '@renderer/components/base/base-setting-card'
44
import SettingItem from '@renderer/components/base/base-setting-item'
@@ -15,20 +15,22 @@ import { version } from '@renderer/utils/init'
1515
import useSWR from 'swr'
1616
import { useState } from 'react'
1717
import debounce from '@renderer/utils/debounce'
18+
import { useTheme } from 'next-themes'
1819

1920
const Settings: React.FC = () => {
21+
const { setTheme } = useTheme()
2022
const { data: enable, mutate } = useSWR('checkAutoRun', checkAutoRun, {
2123
errorRetryCount: 5,
2224
errorRetryInterval: 200
2325
})
24-
2526
const { appConfig, patchAppConfig } = useAppConfig()
2627
const {
2728
silentStart = false,
2829
delayTestUrl,
2930
delayTestTimeout,
3031
autoCheckUpdate,
31-
userAgent
32+
userAgent,
33+
appTheme = 'system'
3234
} = appConfig || {}
3335
const [url, setUrl] = useState(delayTestUrl)
3436
const [ua, setUa] = useState(userAgent)
@@ -72,7 +74,7 @@ const Settings: React.FC = () => {
7274
}}
7375
/>
7476
</SettingItem>
75-
<SettingItem title="静默启动">
77+
<SettingItem title="静默启动" divider>
7678
<Switch
7779
size="sm"
7880
isSelected={silentStart}
@@ -81,6 +83,24 @@ const Settings: React.FC = () => {
8183
}}
8284
/>
8385
</SettingItem>
86+
<SettingItem title="应用主题">
87+
<Tabs
88+
size="sm"
89+
color="primary"
90+
selectedKey={appTheme}
91+
onSelectionChange={(key) => {
92+
console.log(key)
93+
setTheme(key as AppTheme)
94+
95+
patchAppConfig({ appTheme: key as AppTheme })
96+
}}
97+
>
98+
<Tab key="system" title="自动" />
99+
<Tab key="dark" title="深色" />
100+
<Tab key="gray" title="灰色" />
101+
<Tab key="light" title="浅色" />
102+
</Tabs>
103+
</SettingItem>
84104
</SettingCard>
85105
<SettingCard>
86106
<SettingItem title="订阅拉取 UA" divider>

src/shared/types.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type OutboundMode = 'rule' | 'global' | 'direct'
22
type LogLevel = 'info' | 'debug' | 'warning' | 'error' | 'silent'
33
type SysProxyMode = 'auto' | 'manual'
4+
type AppTheme = 'system' | 'light' | 'dark' | 'gray'
45
type MihomoGroupType = 'Selector' | 'URLTest' | 'LoadBalance' | 'Relay'
56
type MihomoProxyType =
67
| 'Direct'
@@ -191,6 +192,7 @@ interface IAppConfig {
191192
core: 'mihomo' | 'mihomo-alpha'
192193
proxyDisplayMode: 'simple' | 'full'
193194
proxyDisplayOrder: 'default' | 'delay' | 'name'
195+
appTheme: AppTheme
194196
autoCheckUpdate: boolean
195197
silentStart: boolean
196198
sysProxy: ISysProxyConfig

tailwind.config.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,27 @@ module.exports = {
1010
extend: {}
1111
},
1212
darkMode: 'class',
13-
plugins: [nextui()]
13+
plugins: [
14+
nextui({
15+
themes: {
16+
gray: {
17+
extend: 'dark',
18+
colors: {
19+
background: '#18181b',
20+
content1: '#27272a',
21+
content2: '#3f3f46',
22+
content3: '#52525b',
23+
default: {
24+
DEFAULT: '#52525b',
25+
50: '#27272a',
26+
100: '#3f3f46',
27+
200: '#52525b',
28+
300: '#71717a',
29+
400: '#a1a1aa'
30+
}
31+
}
32+
}
33+
}
34+
})
35+
]
1436
}

0 commit comments

Comments
 (0)