ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
Add runtime theme switching and ThemeContext
Juan Denis78c8300770a7
diff --git a/.env.example b/.env.exampleindex c1344d0b..70b8bbdd 100644--- a/.env.example+++ b/.env.example@@ -40,6 +40,12 @@ SSL_PORT=443# Options: development, productionFLASK_ENV=production+# ----------------------------------------+# GitHub Repository (for agent downloads)+# ----------------------------------------+# This is used to fetch agent releases for the downloads page+SERVERKIT_GITHUB_REPO=jhd3197/ServerKit+# ----------------------------------------# Optional: Notification Webhooks# ----------------------------------------diff --git a/backend/.env.example b/backend/.env.exampleindex c2d1f423..cfde4dab 100644--- a/backend/.env.example+++ b/backend/.env.example@@ -24,3 +24,7 @@ PORT=5000# Run: python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"# Or: python -c "import base64; import os; print(base64.urlsafe_b64encode(os.urandom(32)).decode())"SERVERKIT_ENCRYPTION_KEY=dSenbMzCii4PMYP3Bb_N9jdqm6pa_TOD4l9yAwhhSBA=++# GitHub Repository for agent releases (owner/repo format)+# This is used to fetch the latest agent version for the downloads page+SERVERKIT_GITHUB_REPO=jhd3197/ServerKitdiff --git a/docs/MCP_SERVER_ACCESS.md b/docs/MCP_SERVER_ACCESS.mdindex 9103762e..dbec99ea 100644--- a/docs/MCP_SERVER_ACCESS.md+++ b/docs/MCP_SERVER_ACCESS.md@@ -80,6 +80,7 @@ ssh user@your-server-ip "echo 'SSH works!'"---+## Option 2: Run MCP Server Directly on Your ServerThis runs an MCP server **on your Linux server** that Claude connects to.diff --git a/frontend/index.html b/frontend/index.htmlindex 8339525d..d1199ba5 100644--- a/frontend/index.html+++ b/frontend/index.html@@ -7,6 +7,13 @@<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="description" content="ServerKit - Server Management Dashboard" /><title>ServerKit</title>+ <script>+ // Prevent flash of unstyled content (FOUC) by setting theme before React loads+ (function() {+ const theme = localStorage.getItem('theme') || 'dark';+ document.documentElement.setAttribute('data-theme', theme);+ })();+ </script></head><body>diff --git a/frontend/src/App.jsx b/frontend/src/App.jsxindex 88a9888c..b62f2c23 100644--- a/frontend/src/App.jsx+++ b/frontend/src/App.jsx@@ -2,6 +2,7 @@ import React, { useEffect } from 'react';import { BrowserRouter as Router, Routes, Route, Navigate, useLocation } from 'react-router-dom';import { AuthProvider, useAuth } from './contexts/AuthContext';import { ToastProvider } from './contexts/ToastContext';+import { ThemeProvider } from './contexts/ThemeContext';import { ToastContainer } from './components/Toast';import DashboardLayout from './layouts/DashboardLayout';import Dashboard from './pages/Dashboard';@@ -179,12 +180,14 @@ function App() {return (<Router><PageTitleUpdater />- <AuthProvider>- <ToastProvider>- <AppRoutes />- <ToastContainer />- </ToastProvider>- </AuthProvider>+ <ThemeProvider>+ <AuthProvider>+ <ToastProvider>+ <AppRoutes />+ <ToastContainer />+ </ToastProvider>+ </AuthProvider>+ </ThemeProvider></Router>);}diff --git a/frontend/src/contexts/ThemeContext.jsx b/frontend/src/contexts/ThemeContext.jsxnew file mode 100644index 00000000..6b9daead--- /dev/null+++ b/frontend/src/contexts/ThemeContext.jsx@@ -0,0 +1,76 @@+import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';++const ThemeContext = createContext(null);++// Get the resolved theme based on current setting and OS preference+function getResolvedTheme(theme) {+ if (theme === 'system') {+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';+ }+ return theme;+}++export function ThemeProvider({ children }) {+ const [theme, setThemeState] = useState(() => {+ return localStorage.getItem('theme') || 'dark';+ });++ const [resolvedTheme, setResolvedTheme] = useState(() => {+ const stored = localStorage.getItem('theme') || 'dark';+ return getResolvedTheme(stored);+ });++ // Update the DOM attribute and resolved theme+ const applyTheme = useCallback((newTheme) => {+ document.documentElement.setAttribute('data-theme', newTheme);+ setResolvedTheme(getResolvedTheme(newTheme));+ }, []);++ // Public setter that updates state, localStorage, and DOM+ const setTheme = useCallback((newTheme) => {+ setThemeState(newTheme);+ localStorage.setItem('theme', newTheme);+ applyTheme(newTheme);+ }, [applyTheme]);++ // Listen for OS theme changes when using 'system' theme+ useEffect(() => {+ if (theme !== 'system') return;++ const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');++ const handleChange = (e) => {+ setResolvedTheme(e.matches ? 'dark' : 'light');+ };++ mediaQuery.addEventListener('change', handleChange);+ return () => mediaQuery.removeEventListener('change', handleChange);+ }, [theme]);++ // Apply theme on mount (handles cases where FOUC script didn't run)+ useEffect(() => {+ applyTheme(theme);+ }, [theme, applyTheme]);++ const value = {+ theme, // Current setting: 'dark' | 'light' | 'system'+ resolvedTheme, // Actual appearance: 'dark' | 'light'+ setTheme, // Function to change theme+ };++ return (+ <ThemeContext.Provider value={value}>+ {children}+ </ThemeContext.Provider>+ );+}++export function useTheme() {+ const context = useContext(ThemeContext);+ if (!context) {+ throw new Error('useTheme must be used within a ThemeProvider');+ }+ return context;+}++export default ThemeContext;diff --git a/frontend/src/pages/Settings.jsx b/frontend/src/pages/Settings.jsxindex 3a99659c..7cc682f2 100644--- a/frontend/src/pages/Settings.jsx+++ b/frontend/src/pages/Settings.jsx@@ -1,5 +1,6 @@import React, { useState, useEffect } from 'react';import { useAuth } from '../contexts/AuthContext';+import { useTheme } from '../contexts/ThemeContext';import api from '../services/api';import UsersTab from '../components/settings/UsersTab';import AuditLogTab from '../components/settings/AuditLogTab';@@ -747,15 +748,7 @@ Keep these codes in a safe place.`;};const AppearanceSettings = () => {- const [theme, setTheme] = useState(() => {- return localStorage.getItem('theme') || 'dark';- });-- function handleThemeChange(newTheme) {- setTheme(newTheme);- localStorage.setItem('theme', newTheme);- document.documentElement.setAttribute('data-theme', newTheme);- }+ const { theme, setTheme } = useTheme();return (<div className="settings-section">@@ -770,7 +763,7 @@ const AppearanceSettings = () => {<div className="theme-options"><buttonclassName={`theme-option ${theme === 'dark' ? 'active' : ''}`}- onClick={() => handleThemeChange('dark')}+ onClick={() => setTheme('dark')}><div className="theme-preview dark"><div className="preview-sidebar"></div>@@ -783,7 +776,7 @@ const AppearanceSettings = () => {</button><buttonclassName={`theme-option ${theme === 'light' ? 'active' : ''}`}- onClick={() => handleThemeChange('light')}+ onClick={() => setTheme('light')}><div className="theme-preview light"><div className="preview-sidebar"></div>@@ -796,7 +789,7 @@ const AppearanceSettings = () => {</button><buttonclassName={`theme-option ${theme === 'system' ? 'active' : ''}`}- onClick={() => handleThemeChange('system')}+ onClick={() => setTheme('system')}><div className="theme-preview system"><div className="preview-sidebar"></div>diff --git a/frontend/src/styles/_theme-variables.less b/frontend/src/styles/_theme-variables.lessnew file mode 100644index 00000000..8574870a--- /dev/null+++ b/frontend/src/styles/_theme-variables.less@@ -0,0 +1,110 @@+// ============================================+// SERVERKIT DESIGN SYSTEM - THEME VARIABLES+// ============================================+// CSS Custom Properties that enable runtime theme switching.+// Must be imported FIRST before _variables.less+// ============================================++// --------------------------------------------+// DARK THEME (Default)+// --------------------------------------------+:root {+ // Background colors+ --bg-body: #09090b;+ --bg-sidebar: #0f0f11;+ --bg-card: #18181b;+ --bg-hover: #27272a;+ --bg-elevated: #1f1f23;+ --bg-secondary: #27272a;+ --bg-tertiary: #3f3f46;++ // Border colors+ --border-default: #27272a;+ --border-subtle: #27272a;+ --border-active: #3f3f46;++ // Text colors+ --text-primary: #f4f4f5;+ --text-secondary: #a1a1aa;+ --text-tertiary: #71717a;++ // Shadows+ --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);+ --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);+ --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);++ // Scrollbar+ --scrollbar-track: #18181b;+ --scrollbar-thumb: #3f3f46;+ --scrollbar-thumb-hover: #52525b;+}++// --------------------------------------------+// LIGHT THEME+// --------------------------------------------+[data-theme="light"] {+ // Background colors+ --bg-body: #f8fafc;+ --bg-sidebar: #f1f5f9;+ --bg-card: #ffffff;+ --bg-hover: #f1f5f9;+ --bg-elevated: #ffffff;+ --bg-secondary: #e2e8f0;+ --bg-tertiary: #cbd5e1;++ // Border colors+ --border-default: #e2e8f0;+ --border-subtle: #e2e8f0;+ --border-active: #cbd5e1;++ // Text colors+ --text-primary: #0f172a;+ --text-secondary: #475569;+ --text-tertiary: #64748b;++ // Shadows (lighter for light theme)+ --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);+ --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);+ --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);++ // Scrollbar+ --scrollbar-track: #f1f5f9;+ --scrollbar-thumb: #cbd5e1;+ --scrollbar-thumb-hover: #94a3b8;+}++// --------------------------------------------+// SYSTEM THEME (follows OS preference)+// --------------------------------------------+@media (prefers-color-scheme: light) {+ [data-theme="system"] {+ // Background colors+ --bg-body: #f8fafc;+ --bg-sidebar: #f1f5f9;+ --bg-card: #ffffff;+ --bg-hover: #f1f5f9;+ --bg-elevated: #ffffff;+ --bg-secondary: #e2e8f0;+ --bg-tertiary: #cbd5e1;++ // Border colors+ --border-default: #e2e8f0;+ --border-subtle: #e2e8f0;+ --border-active: #cbd5e1;++ // Text colors+ --text-primary: #0f172a;+ --text-secondary: #475569;+ --text-tertiary: #64748b;++ // Shadows+ --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);+ --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);+ --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);++ // Scrollbar+ --scrollbar-track: #f1f5f9;+ --scrollbar-thumb: #cbd5e1;+ --scrollbar-thumb-hover: #94a3b8;+ }+}diff --git a/frontend/src/styles/_variables.less b/frontend/src/styles/_variables.lessindex 00296ea5..678f536b 100644--- a/frontend/src/styles/_variables.less+++ b/frontend/src/styles/_variables.less@@ -1,34 +1,59 @@// ============================================// SERVERKIT DESIGN SYSTEM - VARIABLES// ============================================+// Theme-sensitive colors use CSS custom properties for runtime theming.+// Raw values (*-raw) are kept for LESS compile-time functions like fade().+// ============================================@white: #f4f4f5;@black: #09090b;// ---------------------------------------------// COLORS - Background+// COLORS - Background (theme-sensitive)// ---------------------------------------------@bg-body: #09090b;-@bg-sidebar: #0f0f11;-@bg-card: #18181b;-@bg-hover: #27272a;-@bg-elevated: #1f1f23;-@bg-secondary: #27272a;-@bg-tertiary: #3f3f46;+// Raw values for LESS functions (dark theme defaults)+@bg-body-raw: #09090b;+@bg-sidebar-raw: #0f0f11;+@bg-card-raw: #18181b;+@bg-hover-raw: #27272a;+@bg-elevated-raw: #1f1f23;+@bg-secondary-raw: #27272a;+@bg-tertiary-raw: #3f3f46;++// Themed values using CSS custom properties+@bg-body: var(--bg-body);+@bg-sidebar: var(--bg-sidebar);+@bg-card: var(--bg-card);+@bg-hover: var(--bg-hover);+@bg-elevated: var(--bg-elevated);+@bg-secondary: var(--bg-secondary);+@bg-tertiary: var(--bg-tertiary);// ---------------------------------------------// COLORS - Borders+// COLORS - Borders (theme-sensitive)// ---------------------------------------------@border-default: #27272a;-@border-subtle: #27272a;-@border-active: #3f3f46;+// Raw values for LESS functions+@border-default-raw: #27272a;+@border-subtle-raw: #27272a;+@border-active-raw: #3f3f46;++// Themed values using CSS custom properties+@border-default: var(--border-default);+@border-subtle: var(--border-subtle);+@border-active: var(--border-active);// ---------------------------------------------// COLORS - Text+// COLORS - Text (theme-sensitive)// ---------------------------------------------@text-primary: #f4f4f5;-@text-secondary: #a1a1aa;-@text-tertiary: #71717a;+// Raw values for LESS functions+@text-primary-raw: #f4f4f5;+@text-secondary-raw: #a1a1aa;+@text-tertiary-raw: #71717a;++// Themed values using CSS custom properties+@text-primary: var(--text-primary);+@text-secondary: var(--text-secondary);+@text-tertiary: var(--text-tertiary);// --------------------------------------------// COLORS - Accent@@ -121,11 +146,11 @@@radius-full: 9999px;// ---------------------------------------------// SHADOWS+// SHADOWS (theme-sensitive)// ---------------------------------------------@shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);-@shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);-@shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);+@shadow-sm: var(--shadow-sm);+@shadow-md: var(--shadow-md);+@shadow-lg: var(--shadow-lg);@shadow-accent: 0 4px 12px @accent-shadow;// --------------------------------------------diff --git a/frontend/src/styles/components/_badges.less b/frontend/src/styles/components/_badges.lessindex ebde820c..eb3a0d84 100644--- a/frontend/src/styles/components/_badges.less+++ b/frontend/src/styles/components/_badges.less@@ -32,9 +32,9 @@}.status-stopped {- background: fade(@text-tertiary, 10%);+ background: fade(@text-tertiary-raw, 10%);color: @text-tertiary;- border-color: fade(@text-tertiary, 20%);+ border-color: fade(@text-tertiary-raw, 20%);}.status-error {diff --git a/frontend/src/styles/components/_linked-apps.less b/frontend/src/styles/components/_linked-apps.lessindex 9694d390..f1ce02aa 100644--- a/frontend/src/styles/components/_linked-apps.less+++ b/frontend/src/styles/components/_linked-apps.less@@ -353,7 +353,7 @@}&.status-stopped {- background: fade(@text-tertiary, 10%);+ background: fade(@text-tertiary-raw, 10%);color: @text-tertiary;}diff --git a/frontend/src/styles/components/_query-runner.less b/frontend/src/styles/components/_query-runner.lessindex 85619f19..863e76c3 100644--- a/frontend/src/styles/components/_query-runner.less+++ b/frontend/src/styles/components/_query-runner.less@@ -406,7 +406,7 @@tbody tr {&:hover {- background: fade(@bg-hover, 50%);+ background: fade(@bg-hover-raw, 50%);}}}diff --git a/frontend/src/styles/components/_spinner.less b/frontend/src/styles/components/_spinner.lessindex c1c55100..8bbbdd95 100644--- a/frontend/src/styles/components/_spinner.less+++ b/frontend/src/styles/components/_spinner.less@@ -97,7 +97,7 @@}&.btn-secondary .spinner .spinner-ring {- border-color: fade(@text-primary, 30%);+ border-color: fade(@text-primary-raw, 30%);border-top-color: @text-primary;}diff --git a/frontend/src/styles/main.less b/frontend/src/styles/main.lessindex 1ae759d9..5f2b1a24 100644--- a/frontend/src/styles/main.less+++ b/frontend/src/styles/main.less@@ -8,6 +8,7 @@// --------------------------------------------// 1. DESIGN TOKENS// --------------------------------------------+@import '_theme-variables'; // CSS custom properties for runtime theming (must be first)@import '_variables';@import '_mixins';diff --git a/frontend/src/styles/pages/_workflow.less b/frontend/src/styles/pages/_workflow.lessindex fc3ef533..064d36a5 100644--- a/frontend/src/styles/pages/_workflow.less+++ b/frontend/src/styles/pages/_workflow.less@@ -174,7 +174,7 @@}&.status-stopped {- background: fade(@text-tertiary, 10%);+ background: fade(@text-tertiary-raw, 10%);color: @text-tertiary;}@@ -1022,7 +1022,7 @@left: 0;right: 0;bottom: 0;- background: fade(@bg-body, 80%);+ background: fade(@bg-body-raw, 80%);backdrop-filter: blur(4px);display: flex;align-items: center;@@ -1307,7 +1307,7 @@left: 0;right: 0;bottom: 0;- background: fade(@bg-body, 80%);+ background: fade(@bg-body-raw, 80%);backdrop-filter: blur(4px);display: flex;align-items: center;