diff --git a/src/client/api.ts b/src/client/api.ts index 6b7143f..d79851d 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -4,15 +4,8 @@ export const getLogDates = (name: string): Promise => export const getLogsForDate = (name: string, date: string): Promise => fetch(`/api/apps/${name}/logs?date=${date}`).then(r => r.json()) -export const getWifiConfig = (): Promise<{ network: string, password: string }> => - fetch('/api/system/wifi').then(r => r.json()) - -export const saveWifiConfig = (config: { network: string, password: string }) => - fetch('/api/system/wifi', { - method: 'PUT', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(config), - }).then(r => r.json()) +export const getSystemInfo = (): Promise<{ version: string, sha: string }> => + fetch('/api/system/info').then(r => r.json()) export const shareApp = (name: string) => fetch(`/api/apps/${name}/tunnel`, { method: 'POST' }) diff --git a/src/client/components/SettingsPage.tsx b/src/client/components/SettingsPage.tsx index cce6e10..9b844a1 100644 --- a/src/client/components/SettingsPage.tsx +++ b/src/client/components/SettingsPage.tsx @@ -1,13 +1,9 @@ import { useEffect, useState } from 'hono/jsx' -import { getWifiConfig, saveWifiConfig } from '../api' +import { getSystemInfo } from '../api' import { navigate } from '../router' import { Button, DashboardInstallCmd, - FormActions, - FormField, - FormInput, - FormLabel, HeaderActions, Main, MainContent, @@ -18,15 +14,13 @@ import { } from '../styles' export function SettingsPage({ render }: { render: () => void }) { - const [network, setNetwork] = useState('') - const [password, setPassword] = useState('') - const [saving, setSaving] = useState(false) - const [saved, setSaved] = useState(false) + const [version, setVersion] = useState('') + const [sha, setSha] = useState('') useEffect(() => { - getWifiConfig().then(config => { - setNetwork(config.network) - setPassword(config.password) + getSystemInfo().then(info => { + setVersion(info.version) + setSha(info.sha) }) }, []) @@ -34,15 +28,6 @@ export function SettingsPage({ render }: { render: () => void }) { navigate('/') } - const handleSave = async (e: Event) => { - e.preventDefault() - setSaving(true) - setSaved(false) - await saveWifiConfig({ network, password }) - setSaving(false) - setSaved(true) - } - return (
@@ -53,33 +38,11 @@ export function SettingsPage({ render }: { render: () => void }) {
- WiFi -
- - Network - setNetwork((e.target as HTMLInputElement).value)} - placeholder="SSID" - /> - - - Password - setPassword((e.target as HTMLInputElement).value)} - placeholder="Password" - /> - - - {saved && Saved} - - -
+ About +
+ Version: {version} + SHA: {sha} +
Install CLI diff --git a/src/server/api/system.ts b/src/server/api/system.ts index ffbc1e6..d41794b 100644 --- a/src/server/api/system.ts +++ b/src/server/api/system.ts @@ -1,9 +1,9 @@ -import { allApps, APPS_DIR, onChange, TOES_DIR } from '$apps' +import { allApps, APPS_DIR, onChange } from '$apps' import { onHostLog } from '../tui' import { Hype } from '@because/hype' import { cpus, freemem, platform, totalmem } from 'os' import { join } from 'path' -import { existsSync, mkdirSync, readFileSync, statfsSync, writeFileSync } from 'fs' +import { readFileSync, statfsSync } from 'fs' export interface AppMetrics { cpu: number @@ -18,11 +18,6 @@ export interface SystemMetrics { apps: Record } -export interface WifiConfig { - network: string - password: string -} - export interface UnifiedLogLine { time: number app: string @@ -190,36 +185,12 @@ router.sse('/metrics/stream', (send) => { return () => clearInterval(interval) }) -// WiFi config -const CONFIG_DIR = join(TOES_DIR, 'config') -const WIFI_PATH = join(CONFIG_DIR, 'wifi.json') +// System info +const pkg = JSON.parse(readFileSync(join(import.meta.dir, '../../../package.json'), 'utf-8')) +const sha = Bun.spawnSync(['git', 'rev-parse', '--short', 'HEAD'], { cwd: join(import.meta.dir, '../../..') }).stdout.toString().trim() || 'unknown' -function readWifiConfig(): WifiConfig { - try { - if (existsSync(WIFI_PATH)) { - return JSON.parse(readFileSync(WIFI_PATH, 'utf-8')) - } - } catch {} - return { network: '', password: '' } -} - -function writeWifiConfig(config: WifiConfig) { - if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true }) - writeFileSync(WIFI_PATH, JSON.stringify(config, null, 2)) -} - -router.get('/wifi', c => { - return c.json(readWifiConfig()) -}) - -router.put('/wifi', async c => { - const body = await c.req.json() - const config: WifiConfig = { - network: String(body.network ?? ''), - password: String(body.password ?? ''), - } - writeWifiConfig(config) - return c.json(config) +router.get('/info', c => { + return c.json({ version: pkg.version, sha }) }) // Get recent unified logs