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-03 03:26:29 +08:00
|
|
|
import { Header } from '~/components'
|
2023-09-03 03:36:12 +08:00
|
|
|
import { ROUTES } from '~/constants'
|
2023-09-03 03:26:29 +08:00
|
|
|
import {
|
|
|
|
curTheme,
|
|
|
|
endpoint,
|
2023-09-04 20:00:43 +08:00
|
|
|
renderProxiesInSamePage,
|
2023-09-03 03:26:29 +08:00
|
|
|
selectedEndpoint,
|
|
|
|
useAutoSwitchTheme,
|
|
|
|
useProxies,
|
2023-09-05 11:40:00 +08:00
|
|
|
useTwemoji,
|
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'))
|
2023-09-02 16:58:22 +08:00
|
|
|
const ProxyProvider = lazy(() => import('~/pages/ProxyProvider'))
|
2023-08-29 14:44:49 +08:00
|
|
|
const Rules = lazy(() => import('~/pages/Rules'))
|
|
|
|
const Config = lazy(() => import('~/pages/Config'))
|
|
|
|
|
2023-08-24 04:20:53 +08:00
|
|
|
export const App = () => {
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
2023-09-02 19:06:02 +08:00
|
|
|
useAutoSwitchTheme()
|
|
|
|
|
2023-09-03 02:18:05 +08:00
|
|
|
createEffect(() => {
|
|
|
|
if (selectedEndpoint() && endpoint()) {
|
2023-09-03 20:23:02 +08:00
|
|
|
void useProxies().updateProxies()
|
2023-09-03 02:18:05 +08:00
|
|
|
}
|
2023-09-05 11:40:00 +08:00
|
|
|
|
|
|
|
const rootElement = document.querySelector(':root') as HTMLElement
|
|
|
|
|
|
|
|
if (useTwemoji()) {
|
|
|
|
rootElement.style.setProperty(
|
|
|
|
'font-family',
|
|
|
|
"'Fira Sans', 'Twemoji Mozilla', system-ui, monospace",
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
rootElement.style.setProperty(
|
|
|
|
'font-family',
|
|
|
|
"'Fira Sans', system-ui, monospace",
|
|
|
|
)
|
|
|
|
}
|
2023-09-03 02:18:05 +08:00
|
|
|
})
|
|
|
|
|
2023-09-03 05:35:08 +08:00
|
|
|
onMount(() => {
|
2023-08-24 04:20:53 +08:00
|
|
|
if (!selectedEndpoint()) {
|
2023-09-04 13:08:05 +08:00
|
|
|
navigate(ROUTES.Setup)
|
2023-08-24 04:20:53 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
2023-08-27 17:00:43 +08:00
|
|
|
<div
|
2023-09-05 03:11:43 +08:00
|
|
|
class="relative flex h-screen flex-col subpixel-antialiased p-safe"
|
2023-08-27 17:00:43 +08:00
|
|
|
data-theme={curTheme()}
|
|
|
|
>
|
2023-08-27 22:25:41 +08:00
|
|
|
<Header />
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-31 02:06:26 +08:00
|
|
|
<div class="flex-1 overflow-y-auto overflow-x-hidden p-2 sm:p-4">
|
2023-08-24 04:20:53 +08:00
|
|
|
<Routes>
|
|
|
|
<Show when={selectedEndpoint()}>
|
2023-09-03 03:36:12 +08:00
|
|
|
<Route path={ROUTES.Overview} component={Overview} />
|
|
|
|
<Route path={ROUTES.Proxies} component={Proxies} />
|
2023-09-04 20:00:43 +08:00
|
|
|
<Show when={!renderProxiesInSamePage()}>
|
|
|
|
<Route path={ROUTES.ProxyProvider} component={ProxyProvider} />
|
|
|
|
</Show>
|
2023-09-03 03:36:12 +08:00
|
|
|
<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} />} />
|
2023-08-24 04:20:53 +08:00
|
|
|
</Show>
|
|
|
|
|
2023-09-04 13:08:05 +08:00
|
|
|
<Route
|
|
|
|
path={selectedEndpoint() ? ROUTES.Setup : '*'}
|
|
|
|
component={Setup}
|
|
|
|
/>
|
2023-08-24 04:20:53 +08:00
|
|
|
</Routes>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|