2023-09-19 20:24:13 +08:00
|
|
|
import { usePrefersDark } from '@solid-primitives/media'
|
2023-08-30 16:05:13 +08:00
|
|
|
import { Navigate, Route, Routes, useNavigate } from '@solidjs/router'
|
2023-09-03 02:18:05 +08:00
|
|
|
import { Show, createEffect, lazy, onMount } from 'solid-js'
|
2023-09-10 00:58:21 +08:00
|
|
|
import { Toaster } from 'solid-toast'
|
2023-09-05 12:18:32 +08:00
|
|
|
import { twMerge } from 'tailwind-merge'
|
2023-09-03 03:26:29 +08:00
|
|
|
import { Header } from '~/components'
|
2023-09-03 03:36:12 +08:00
|
|
|
import { ROUTES } from '~/constants'
|
2023-09-23 01:46:42 +08:00
|
|
|
import { I18nProvider, locale } from '~/i18n'
|
2023-09-03 03:26:29 +08:00
|
|
|
import {
|
2023-09-08 18:42:15 +08:00
|
|
|
WsMsg,
|
2023-09-19 20:24:13 +08:00
|
|
|
autoSwitchTheme,
|
2023-09-03 03:26:29 +08:00
|
|
|
curTheme,
|
|
|
|
endpoint,
|
2023-09-19 20:24:13 +08:00
|
|
|
favDayTheme,
|
|
|
|
favNightTheme,
|
|
|
|
setCurTheme,
|
2023-09-08 18:42:15 +08:00
|
|
|
setLatestConnectionMsg,
|
2023-09-03 03:26:29 +08:00
|
|
|
useProxies,
|
2023-09-05 11:40:00 +08:00
|
|
|
useTwemoji,
|
2023-09-08 18:42:15 +08:00
|
|
|
useWsRequest,
|
2023-09-03 03:26:29 +08:00
|
|
|
} from '~/signals'
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-29 14:44:49 +08:00
|
|
|
const Setup = lazy(() => import('~/pages/Setup'))
|
|
|
|
const Overview = lazy(() => import('~/pages/Overview'))
|
|
|
|
const Connections = lazy(() => import('~/pages/Connections'))
|
|
|
|
const Logs = lazy(() => import('~/pages/Logs'))
|
|
|
|
const Proxies = lazy(() => import('~/pages/Proxies'))
|
|
|
|
const Rules = lazy(() => import('~/pages/Rules'))
|
|
|
|
const Config = lazy(() => import('~/pages/Config'))
|
|
|
|
|
2023-09-19 20:24:13 +08:00
|
|
|
const ProtectedResources = () => {
|
|
|
|
const { fetchProxies } = useProxies()
|
|
|
|
|
|
|
|
onMount(fetchProxies)
|
|
|
|
|
|
|
|
const latestConnectionMsg = useWsRequest<WsMsg>('connections')
|
|
|
|
|
|
|
|
createEffect(() => {
|
|
|
|
setLatestConnectionMsg(latestConnectionMsg())
|
|
|
|
})
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-08-24 04:20:53 +08:00
|
|
|
export const App = () => {
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
2023-09-19 20:24:13 +08:00
|
|
|
const prefersDark = usePrefersDark()
|
2023-09-02 19:06:02 +08:00
|
|
|
|
2023-09-03 02:18:05 +08:00
|
|
|
createEffect(() => {
|
2023-09-19 20:24:13 +08:00
|
|
|
if (autoSwitchTheme()) {
|
|
|
|
setCurTheme(prefersDark() ? favNightTheme() : favDayTheme())
|
2023-09-03 02:18:05 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-09-03 05:35:08 +08:00
|
|
|
onMount(() => {
|
2023-09-19 20:24:13 +08:00
|
|
|
if (!endpoint()) {
|
2023-09-04 13:08:05 +08:00
|
|
|
navigate(ROUTES.Setup)
|
2023-08-24 04:20:53 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
2023-09-23 01:46:42 +08:00
|
|
|
<I18nProvider locale={locale()}>
|
|
|
|
<div
|
|
|
|
class={twMerge(
|
|
|
|
'relative flex h-screen flex-col subpixel-antialiased p-safe',
|
|
|
|
useTwemoji() ? 'font-twemoji' : 'font-no-twemoji',
|
|
|
|
)}
|
|
|
|
data-theme={curTheme()}
|
|
|
|
>
|
|
|
|
<Header />
|
|
|
|
|
|
|
|
<div class="flex-1 overflow-y-auto p-2 sm:p-4">
|
|
|
|
<Routes>
|
|
|
|
<Show when={endpoint()}>
|
|
|
|
<Route path={ROUTES.Overview} component={Overview} />
|
|
|
|
<Route path={ROUTES.Proxies} component={Proxies} />
|
|
|
|
<Route path={ROUTES.Rules} component={Rules} />
|
|
|
|
<Route path={ROUTES.Conns} component={Connections} />
|
|
|
|
<Route path={ROUTES.Log} component={Logs} />
|
|
|
|
<Route path={ROUTES.Config} component={Config} />
|
|
|
|
<Route path="*" element={<Navigate href={ROUTES.Overview} />} />
|
|
|
|
</Show>
|
|
|
|
|
|
|
|
<Route path={endpoint() ? ROUTES.Setup : '*'} component={Setup} />
|
|
|
|
</Routes>
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-09-19 20:24:13 +08:00
|
|
|
<Show when={endpoint()}>
|
2023-09-23 01:46:42 +08:00
|
|
|
<ProtectedResources />
|
2023-08-24 04:20:53 +08:00
|
|
|
</Show>
|
2023-09-23 01:46:42 +08:00
|
|
|
</div>
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-09-23 01:46:42 +08:00
|
|
|
<Toaster position="bottom-center" />
|
2023-08-24 04:20:53 +08:00
|
|
|
</div>
|
2023-09-23 01:46:42 +08:00
|
|
|
</I18nProvider>
|
2023-08-24 04:20:53 +08:00
|
|
|
)
|
|
|
|
}
|