secubox-openwrt/luci-app-secubox/htdocs/luci-static/resources/secubox/theme.js
CyberMind-FR 5902ac500a release: v0.1.1 - Unified Theme System with Dark/Light Mode Support
Major Features:
• Centralized theme system across SecuBox and System Hub
• Three theme modes: dark (default), light, and system (auto-detect)
• Single theme setting in SecuBox controls both plugins
• Real-time theme switching with OS preference detection

SecuBox Changes:
• Added theme.js manager for centralized theme control
• Implemented CSS variables for dark/light mode (secubox.css)
• Fixed hardcoded colors in dashboard.css, alerts.css, monitoring.css
• Integrated theme.js in all 7 views (dashboard, modules, alerts, monitoring, settings, etc.)
• Added get_theme RPC method to luci.secubox backend
• Updated ACL permissions to include get_theme (read access)
• Version updated to 0.1.1

System Hub Changes:
• Added theme.js manager using SecuBox theme API
• Implemented CSS variables for dark/light mode (dashboard.css)
• Integrated theme.js in all 9 views (overview, health, services, logs, backup, components, remote, settings, diagnostics)
• Version updated to 0.1.1
• README updated with maintainer info

Theme System Architecture:
• Configuration: /etc/config/secubox (option theme: dark|light|system)
• RPCD Backend: luci.secubox/get_theme method
• Frontend: theme.js modules (secubox/theme.js, system-hub/theme.js)
• CSS Variables: --sb-bg, --sb-bg-card, --sb-border, --sb-text, --sb-text-muted, --sb-shadow
• Auto-detection: prefers-color-scheme media query for system mode

Documentation:
• Added LUCI_DEVELOPMENT_REFERENCE.md with comprehensive LuCI development patterns
• Documented ubus/RPC types, baseclass.extend() patterns, ACL structure
• Common errors and solutions from implementation experience

Bug Fixes:
• Fixed SecuBox theme not applying visually (CSS variables now used)
• Fixed missing secubox.css in view imports
• Fixed ACL access denied for get_theme method
• Fixed hardcoded colors preventing theme switching

Testing:
• Verified theme switching works in all SecuBox tabs
• Verified theme switching works in all System Hub tabs
• Verified dark/light/system modes function correctly
• Verified single setting controls both plugins

🤖 Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 16:09:15 +01:00

64 lines
1.7 KiB
JavaScript

'use strict';
'require baseclass';
'require secubox/api as API';
/**
* SecuBox Theme Manager
* Manages dark/light/system theme switching across SecuBox and all modules
* Version: 1.0.0
*/
console.log('🎨 SecuBox Theme Manager v1.0.0 loaded');
return baseclass.extend({
/**
* Initialize theme system
* Loads theme preference and applies it to the page
*/
init: function() {
var self = this;
return API.getTheme().then(function(data) {
var themePref = data.theme || 'dark';
self.applyTheme(themePref);
// Listen for system theme changes if preference is 'system'
if (themePref === 'system' && window.matchMedia) {
var darkModeQuery = window.matchMedia('(prefers-color-scheme: dark)');
darkModeQuery.addListener(function() {
self.applyTheme('system');
});
}
}).catch(function(err) {
console.error('Failed to load theme preference, using dark theme:', err);
self.applyTheme('dark');
});
},
/**
* Apply theme to the page
* @param {string} theme - Theme preference: 'dark', 'light', or 'system'
*/
applyTheme: function(theme) {
var effectiveTheme = theme;
// If 'system', detect from OS
if (theme === 'system' && window.matchMedia) {
effectiveTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
// Apply theme to document root
document.documentElement.setAttribute('data-theme', effectiveTheme);
console.log('🎨 Theme applied:', theme, '(effective:', effectiveTheme + ')');
},
/**
* Get current effective theme
* @returns {string} 'dark' or 'light'
*/
getCurrentTheme: function() {
return document.documentElement.getAttribute('data-theme') || 'dark';
}
});