chahuadev
Update README
857cdcf
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chahua Plugin Management System</title>
<style>
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 1: GLOBAL STYLES ║ */
/* ║ Primary CSS Variables and Base Styles ║ */
/* ║ [USAGE] Used together: Terminal, Plugin Manager ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Global CSS Variables and Base Styles */
:root {
/* Chahua Web Store Color Scheme - Same colors as web store */
--bg-primary: #0a0e16;
--bg-secondary: #111827;
--bg-tertiary: #0d1117;
--bg-card: #111827;
--text-primary: #f9fafb;
--text-secondary: #9ca3af;
--text-muted: #6b7280;
--accent-blue: #0ea5e9;
--accent-blue-hover: #0284c7;
--accent-light: #38bdf8;
--accent-dark: #0369a1;
--border-color: rgba(255, 255, 255, 0.1);
--border-hover: rgba(255, 255, 255, 0.2);
--shadow-color: rgba(14, 165, 233, 0.25);
--success-color: #10b981;
--success-green: #10b981;
--warning-color: #f59e0b;
--warning-orange: #f59e0b;
--error-color: #ef4444;
--gradient-primary: linear-gradient(
135deg,
var(--bg-primary) 0%,
var(--bg-secondary) 100%
);
--gradient-blue: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
--gradient-card: linear-gradient(
145deg,
rgba(17, 24, 39, 0.8) 0%,
rgba(10, 14, 22, 0.9) 100%
);
/* Enhanced shadow system - Matches web store */
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
0 2px 4px -1px rgba(0, 0, 0, 0.06);
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3),
0 4px 6px -2px rgba(0, 0, 0, 0.2);
--shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4),
0 10px 10px -5px rgba(0, 0, 0, 0.25);
/* Enhanced Glow Effects */
--shadow-glow:
0 0 0 1px rgba(14, 165, 233, 0.3),
0 0 10px rgba(14, 165, 233, 0.2),
0 0 20px rgba(14, 165, 233, 0.1),
0 4px 20px rgba(14, 165, 233, 0.25);
--shadow-glow-strong:
0 0 0 1px rgba(14, 165, 233, 0.5),
0 0 15px rgba(14, 165, 233, 0.4),
0 0 30px rgba(14, 165, 233, 0.3),
0 6px 30px rgba(14, 165, 233, 0.4);
--shadow-glow-subtle:
0 0 5px rgba(14, 165, 233, 0.1),
0 0 10px rgba(14, 165, 233, 0.05),
0 2px 8px rgba(14, 165, 233, 0.1);
--shadow-glow-card:
0 0 0 1px rgba(14, 165, 233, 0.2),
0 0 8px rgba(14, 165, 233, 0.15),
0 0 16px rgba(14, 165, 233, 0.1),
0 2px 12px rgba(0, 0, 0, 0.2);
/* Glass effect - Matches web store */
--glass-bg: linear-gradient(
135deg,
rgba(255, 255, 255, 0.08) 0%,
rgba(255, 255, 255, 0.03) 100%
);
--glass-border: rgba(255, 255, 255, 0.15);
--glass-border-hover: rgba(255, 255, 255, 0.25);
/* Enhanced Grid background - Matches web store */
--grid-color: rgba(255, 255, 255, 0.03);
--grid-size: 40px;
--grid-thick-color: rgba(14, 165, 233, 0.1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 100vh;
overflow: hidden;
margin: 0;
padding: 0 0 8px 0;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 2: BODY & LAYOUT ║ */
/* ║ Main Layout, Background and Container ║ */
/* ║ [USAGE] Used together: Entire app - Background Grid Effect ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
background-color: var(--bg-primary);
color: var(--text-primary);
line-height: 1.6;
/* Enhanced background with grid effect - Matches web store */
background-image:
radial-gradient(1200px 600px at 70% 10%, rgba(14, 165, 233, 0.1), rgba(0, 0, 0, 0) 60%),
linear-gradient(var(--grid-color) 1px, transparent 1px),
linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
background-size: 100% 100%, 40px 40px, 40px 40px;
background-position: 0 0, 0 0, 0 0;
background-attachment: fixed;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 4: ANIMATIONS ║ */
/* ║ [SVG\] Animations & Keyframes ║ */
/* ║ Animations and Keyframes ║ */
/* ║ [USAGE] Used together: Background Grid Animation entire app ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
@keyframes subtle-grid-move {
0%,
100% {
background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0;
}
50% {
background-position: 0 0, 0 0, 2px 2px, 2px 2px, 4px 4px, 4px 4px;
}
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 5: LAYOUT ║ */
/* ║ Layout & Container Styles ║ */
/* ║ Layout and Container ║ */
/* ║ [USAGE] Used together: Container Layout entire app ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 3: PLUGIN SYSTEM VARIABLES ║ */
/* ║ Variables for Plugin Management System ║ */
/* ║ [USAGE] Used separately: Plugin Manager only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
:root {
/* Use the new Community Forum color scheme */
--terminal-bg: var(--bg-secondary);
--terminal-border: var(--border-color);
--plugin-card-bg: var(--glass-bg);
--plugin-card-border: var(--glass-border);
--surface-color: var(--bg-card);
--primary-text-color: var(--text-primary);
--secondary-text-color: var(--text-secondary);
--accent-color: var(--accent-blue);
--accent-hover-color: var(--accent-blue-hover);
--danger-color: var(--error-color);
--info-color: var(--accent-light);
--font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
--border-radius: 12px;
--shadow: var(--shadow-md);
--transition: all 0.3s ease;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 6: PLUGIN COMPONENTS ║ */
/* ║ Plugin Cards & Interface ║ */
/* ║ Plugin Display and Management Components ║ */
/* ║ [USAGE] Used separately: Plugin Manager only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Plugin preview image styling */
.plugin-image-container {
width: 100%;
height: 150px;
overflow: hidden;
border-radius: 12px;
margin-bottom: 15px;
border: 1px solid var(--border-color);
transition: all 0.3s ease;
position: relative;
background: var(--bg-secondary);
}
.plugin-image-container:hover {
border-color: var(--accent-blue);
box-shadow: var(--shadow-glow-subtle);
}
.plugin-preview-image {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
transition: all 0.3s ease;
display: block;
}
.plugin-preview-image:hover {
transform: scale(1.05);
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 7: RESET STYLES ║ */
/* ║ Global Reset and Override ║ */
/* ║ [USAGE] Used together: Reset Styles for entire app ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Override body styles for plugin management */
body {
overflow: hidden;
height: 100vh;
width: 100vw;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 8: MAIN CONTAINER LAYOUT ║ */
/* ║ Main Flexbox Container Layout ║ */
/* ║ [USAGE] Used together: Main Container for Terminal + Plugin ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Main Container Layout with Community Forum Style */
.container {
display: flex;
height: calc(100vh - 132px); /* 88px nav + 44px outer topnav */
gap: 5px;
padding: 5px;
position: relative;
max-width: none; /* Override global container max-width */
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 9: TERMINAL SECTION ║ */
/* ║ Terminal Panel Styles ║ */
/* ║ [USAGE] Used separately: Terminal Section only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Left Panel - Terminal Section with Glass Effect */
.terminal-section {
background: var(--glass-bg);
border-radius: 16px;
color: var(--text-primary);
font-family: "Courier New", monospace;
box-shadow: var(--shadow-glow-card);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid var(--glass-border);
display: flex;
flex-direction: column;
overflow: hidden;
flex: 0 0 auto;
position: relative;
min-width: 400px;
max-width: 75%;
width: calc(60% - 10px);
}
.terminal-header {
background: linear-gradient(
135deg,
var(--accent-blue),
var(--accent-dark)
);
padding: 15px 20px;
border-bottom: 1px solid var(--glass-border);
display: flex;
align-items: center;
gap: 10px;
border-radius: 16px 16px 0 0;
}
.terminal-header h2 {
color: white;
font-size: 1.1rem;
margin: 0;
font-weight: 600;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 10: TERMINAL STATUS ║ */
/* ║ Terminal Status Indicator ║ */
/* ║ [USAGE] Used separately: Terminal Status only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
.terminal-status {
width: 8px;
height: 8px;
border-radius: 50%;
background: #10b981;
animation: pulse 3s infinite;
box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 11: TERMINAL ANIMATIONS ║ */
/* ║ Pulse Animation for Status ║ */
/* ║ [USAGE] Used separately: Terminal Pulse Animation only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
@keyframes pulse {
0%,
100% {
opacity: 1;
transform: scale(1);
}
50% {
opacity: 0.85;
transform: scale(1.05);
}
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 12: LOG VIEWER ║ */
/* ║ Log Display and Terminal Output ║ */
/* ║ [USAGE] Used separately: Terminal Log Display only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* CSS for new Log Viewer - Community Forum Style */
.log-viewer-container {
flex: 1;
background: var(--bg-primary);
color: var(--text-secondary);
font-family: "Consolas", "Courier New", monospace;
font-size: 13px;
padding: 15px;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-all;
margin: 0;
border: none;
outline: none;
border-radius: 0 0 16px 16px;
}
/* Custom scrollbar for log viewer */
.log-viewer-container::-webkit-scrollbar {
width: 8px;
}
.log-viewer-container::-webkit-scrollbar-track {
background: var(--bg-secondary);
border-radius: 4px;
}
.log-viewer-container::-webkit-scrollbar-thumb {
background: var(--accent-blue);
border-radius: 4px;
}
.log-viewer-container::-webkit-scrollbar-thumb:hover {
background: var(--accent-blue-hover);
}
/* Styles for each Log line */
.log-line {
display: block;
margin: 0;
padding: 2px 0;
border-left: 3px solid transparent;
padding-left: 8px;
transition: all 0.2s ease;
}
.log-line:hover {
background: rgba(59, 130, 246, 0.1);
border-left-color: var(--accent-blue);
}
/* Colors for each Log type - Community Forum Colors */
.log-line.log-error {
color: #ef4444;
font-weight: bold;
border-left-color: #ef4444;
background: rgba(239, 68, 68, 0.05);
}
.log-line.log-warning {
color: #f59e0b;
border-left-color: #f59e0b;
background: rgba(245, 158, 11, 0.05);
}
.log-line.log-success {
color: #10b981;
border-left-color: #10b981;
background: rgba(16, 185, 129, 0.05);
}
.log-line.log-info {
color: var(--text-secondary);
}
.log-line.log-debug {
color: var(--accent-light);
}
.log-line.log-command {
color: #a855f7;
font-style: italic;
border-left-color: #a855f7;
background: rgba(168, 85, 247, 0.05);
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 13: TERMINAL LINES ║ */
/* ║ Terminal Text Line Colors ║ */
/* ║ [USAGE] Used separately: Terminal Text Styling only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Legacy support for old CSS classes */
.terminal-line.info {
color: var(--accent-light);
}
.terminal-line.error {
color: #ef4444;
}
.terminal-line.success {
color: #10b981;
}
.terminal-line.warning {
color: #f59e0b;
}
.terminal-line.user {
color: #f59e0b;
font-weight: bold;
}
.terminal-line.command {
color: var(--accent-light);
}
.terminal-line.stdout {
color: var(--text-secondary);
white-space: pre-wrap;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 14: VIEW SWITCHER ║ */
/* ║ Navigation Tab Buttons ║ */
/* ║ [USAGE] Used together: View Tab Navigation entire app ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* --- View Switcher Styles - Community Forum Style --- */
.view-switcher {
margin-left: auto;
margin-top: 8px;
display: flex;
justify-content: space-between; /* Separate each section for spacing */
width: 100%; /* Use full width */
gap: 4px;
padding: 6px;
align-items: center;
/* Removed background, border, backdrop-filter, and box-shadow to hide container */
/* --- Add 2 lines here --- */
position: relative; /* Added to create Stacking Context */
z-index: 100; /* Set "this box" to float above container */
}
.view-btn {
background: transparent !important;
border: none !important;
color: var(--text-secondary) !important;
padding: 8px 16px !important;
cursor: pointer;
border-radius: 8px !important;
font-weight: 500 !important;
transition: all 0.3s ease !important;
box-shadow: none !important;
font-size: 14px !important;
}
.view-btn:hover {
background: rgba(59, 130, 246, 0.1) !important;
color: var(--accent-blue) !important;
transform: translateY(-1px) !important;
box-shadow: var(--shadow-glow-subtle) !important;
}
.view-btn.active {
background: var(--gradient-blue) !important;
color: white !important;
font-weight: 600 !important;
box-shadow: var(--shadow-glow) !important;
}
/* --- Refresh Button Styles - Community Forum Style --- */
.refresh-btn {
background: rgba(16, 185, 129, 0.1) !important;
border: 1px solid rgba(16, 185, 129, 0.3) !important;
color: #10b981 !important;
padding: 6px 12px !important;
margin-left: 8px !important;
cursor: pointer;
border-radius: 8px !important;
font-size: 12px !important;
font-weight: 500 !important;
transition: all 0.3s ease !important;
box-shadow: none !important;
}
.refresh-btn:hover {
background: rgba(16, 185, 129, 0.2) !important;
border-color: rgba(16, 185, 129, 0.5) !important;
color: #ffffff !important;
transform: translateY(-2px) !important;
box-shadow: 0 4px 8px rgba(16, 185, 129, 0.3) !important;
}
.refresh-btn:active {
transform: translateY(0) !important;
box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3) !important;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 15: VIEW CONTAINER ║ */
/* ║ View Panel Container System ║ */
/* ║ [USAGE] Used together: View Panel Switching entire app ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* --- View Container for Panels --- */
.view-container {
flex: 1;
position: relative;
overflow: hidden;
}
.view-panel {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s ease;
visibility: hidden;
}
.view-panel.active {
opacity: 1;
pointer-events: auto;
visibility: visible;
}
/* --- Marketplace WebView Styles --- */
#marketplace-webview {
width: 100%;
height: 100%;
border: none;
background-color: var(--bg-color);
}
/* Resize Handle */
.resize-handle {
position: absolute;
top: 0;
right: -10px;
width: 20px;
height: 100%;
cursor: col-resize;
background: transparent;
z-index: 10;
user-select: none;
display: flex;
align-items: center;
justify-content: center;
}
.resize-handle::before {
content: "";
width: 4px;
height: 40px;
background: var(--border-color);
border-radius: 2px;
transition: var(--transition);
}
.resize-handle:hover::before {
background: var(--accent-color);
opacity: 0.7;
}
.resize-handle.resizing::before {
background: var(--accent-color);
opacity: 1;
box-shadow: 0 0 10px rgba(0, 86, 179, 0.5);
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 16: RESIZE SYSTEM ║ */
/* ║ Panel Resize Handle System ║ */
/* ║ [USAGE] Used together: Resize Handle between Panels ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
.container.resizing {
user-select: none;
}
.container.resizing * {
pointer-events: none;
}
.container.resizing .resize-handle {
pointer-events: auto;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 17: SIDEBAR PANEL ║ */
/* ║ Right Sidebar Plugin Management ║ */
/* ║ [USAGE] Used separately: Plugin Management Sidebar only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Right Panel - Plugin Management with Glass Effect */
.sidebar {
background: var(--glass-bg);
border-radius: 16px;
padding: 10px;
box-shadow: var(--shadow-glow-card);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid var(--glass-border);
overflow-y: auto;
flex: 1;
min-width: 300px;
position: relative;
display: flex;
flex-direction: column;
gap: 12px;
}
/* Custom scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
width: 8px;
}
.sidebar::-webkit-scrollbar-track {
background: rgba(148, 163, 184, 0.1);
border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb {
background: var(--accent-blue);
border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
background: var(--accent-blue-hover);
}
.sidebar h2 {
color: var(--accent-blue);
margin-bottom: 10px;
font-size: 1.4rem;
text-align: center;
font-weight: 700;
text-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}
/* Plugin Grid with Enhanced Styling */
.plugin-grid {
display: flex;
flex-direction: column;
gap: 16px;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 18: UTILITIES ║ */
/* ║ CSS Utilities and More ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* Utility classes */
.fade-in {
animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 19: UTILITY CLASSES ║ */
/* ║ Utility and Helper Classes ║ */
/* ║ [USAGE] Used together: Utility Classes entire app ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Utility classes */
.fade-in {
animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 20: PLUGIN META INFO ║ */
/* ║ Plugin Information Display ║ */
/* ║ [USAGE] Used separately: Plugin Meta Display only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Plugin Meta Information */
.plugin-meta {
background: var(--bg-secondary);
border: 1px solid var(--glass-border);
border-radius: 12px;
padding: 1rem;
margin: 1rem 0;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 0.75rem;
text-align: left;
}
.meta-item {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
.meta-label {
font-size: 0.9rem;
color: var(--text-secondary);
margin-bottom: 0.5rem;
}
.meta-value {
font-size: 1.1rem;
color: var(--text-primary);
font-weight: 600;
}
/* Star Rating */
.stars {
display: flex;
gap: 2px;
justify-content: center;
margin-bottom: 0.25rem;
}
.star {
font-size: 1rem;
}
.star.filled {
color: #ffd700;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 21: ERROR & EMPTY STATES ║ */
/* ║ Error and Empty State Displays ║ */
/* ║ [USAGE] Used together: Error States entire app ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Error and Empty States */
.error-slide h2 {
color: var(--text-primary);
margin-bottom: 1rem;
font-size: 2rem;
}
.error-slide p {
margin-bottom: 1rem;
font-size: 1.1rem;
line-height: 1.6;
color: var(--text-secondary);
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 22: NAVIGATION STYLES ║ */
/* ║ Top Navigation Buttons ║ */
/* ║ [USAGE] Used together: Navigation Bar entire app ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* ===========================
VIEW SWITCHER STYLES
=========================== */
.view-switcher {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.15rem 0.3rem;
margin: 0.1rem;
}
.view-tabs {
display: flex;
gap: 0.15rem;
}
.view-btn {
padding: 0.3rem 0.6rem;
background: transparent;
border: 1px solid var(--glass-border);
color: var(--text);
border-radius: 20px;
cursor: pointer;
font-size: 0.8rem;
font-weight: 500;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 0.4rem;
white-space: nowrap;
}
.view-btn:hover {
background: var(--accent-color);
color: white;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 123, 255, 0.3);
}
.view-btn.active {
background: linear-gradient(
135deg,
var(--accent-color) 0%,
var(--secondary-color) 100%
);
color: white;
border-color: var(--accent-color);
box-shadow: 0 4px 15px rgba(0, 123, 255, 0.4);
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 23: MODAL STYLES ║ */
/* ║ Modal and Forms ║ */
/* ║ [USAGE] Used separately: Modal System only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
.loading-state {
text-align: center;
padding: 2rem 1rem;
color: var(--text);
background: linear-gradient(
135deg,
var(--glass-bg) 0%,
var(--accent-color) 20 20%
);
border-radius: 15px;
margin: 1rem;
border: 1px solid var(--glass-border);
box-shadow: var(--glass-shadow);
}
.loading-spinner {
width: 50px;
height: 50px;
border: 4px solid var(--glass-border);
border-top: 4px solid var(--accent-color);
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 1rem;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.error-state {
text-align: center;
padding: 2rem 1rem;
color: var(--text);
background: linear-gradient(
135deg,
rgba(220, 53, 69, 0.1) 0%,
rgba(220, 53, 69, 0.05) 100%
);
border-radius: 15px;
margin: 1rem;
border: 1px solid rgba(220, 53, 69, 0.3);
box-shadow: var(--glass-shadow);
}
.error-state h3 {
color: #dc3545;
margin-bottom: 1rem;
}
.retry-button {
background: linear-gradient(
135deg,
var(--accent-color) 0%,
var(--secondary-color) 100%
);
color: white;
border: none;
padding: 0.75rem 1.5rem;
border-radius: 25px;
cursor: pointer;
font-size: 0.9rem;
font-weight: 500;
transition: all 0.3s ease;
margin-top: 1rem;
box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
}
.retry-button:hover {
background: linear-gradient(
135deg,
var(--secondary-color) 0%,
var(--accent-color) 100%
);
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0, 123, 255, 0.4);
}
/* ===========================
RESPONSIVE DESIGN
=========================== */
/* ===========================
TABLET AND MOBILE RESPONSIVE
=========================== */
@media (max-width: 1024px) {
/* Removed #store-container CSS */
}
@media (max-width: 768px) {
/* Removed #store-container CSS */
.view-switcher {
flex-direction: column;
gap: 1rem;
padding: 1rem;
}
.view-tabs {
flex-wrap: wrap;
justify-content: center;
}
.view-btn {
padding: 0.6rem 1rem;
font-size: 0.85rem;
white-space: nowrap;
}
.refresh-btn {
min-width: auto;
width: 100%;
justify-content: center;
}
.loading-state,
.error-state {
margin: 1rem;
padding: 2rem 1rem;
}
.modal {
width: 95%;
max-width: none;
margin: 0.5rem;
}
.modal-body {
padding: 1.5rem;
}
}
@media (max-width: 480px) {
.slide-presentation-container {
margin: 0.25rem;
height: calc(100vh - 160px);
}
.view-switcher {
padding: 0.75rem;
margin: 0.5rem;
}
.view-tabs {
flex-direction: column;
width: 100%;
}
.view-btn {
padding: 0.5rem 1rem;
font-size: 0.8rem;
width: 100%;
justify-content: center;
}
.action-buttons {
flex-direction: column;
gap: 0.5rem;
}
.action-btn {
width: 100%;
text-align: center;
}
}
@media (max-width: 480px) {
.sidebar-header {
padding: 1rem;
}
}
/* OLD: Original Plugin Cards (Kept for reference) */
.plugin-card {
background: var(--gradient-card);
border: 1px solid var(--glass-border);
border-radius: 12px;
padding: 12px;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
box-shadow: var(--shadow-glow-subtle);
}
.plugin-card::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(59, 130, 246, 0.1),
transparent
);
transition: left 0.6s ease;
}
.plugin-card:hover::before {
left: 100%;
}
.plugin-card:hover {
transform: translateY(-2px);
border-color: var(--accent-blue);
box-shadow: var(--shadow-glow-subtle);
}
.plugin-card h3 {
font-size: 1.1rem;
color: var(--primary-text-color);
margin-bottom: 10px;
font-weight: 600;
}
.plugin-card p {
font-size: 0.9rem;
color: var(--secondary-text-color);
margin-bottom: 15px;
line-height: 1.5;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 24: PLUGIN BUTTONS ║ */
/* ║ Plugin Action Buttons ║ */
/* ║ [USAGE] Used separately: Plugin Card Buttons only ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
.plugin-buttons {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
gap: 8px;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 25: INTERACTIVE BUTTONS ║ */
/* ║ Buttons, Forms and Interactive Elements ║ */
/* ║ [USAGE] Used together: Button Styles entire app ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Button Styles - Community Forum Style */
.button,
.plugin-buttons button,
button:not(.modal-close-btn):not(.password-toggle) {
background: var(--glass-bg) !important;
color: var(--accent-blue) !important;
border: 1px solid var(--glass-border) !important;
padding: 8px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 0.8rem;
font-weight: 500;
transition: all 0.3s ease;
outline: none;
text-align: center;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
position: relative;
overflow: hidden;
min-height: auto;
}
.button::before,
.plugin-buttons button::before,
button:not(.modal-close-btn):not(.password-toggle)::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(59, 130, 246, 0.2),
transparent
);
transition: left 0.5s ease;
}
.button:hover::before,
.plugin-buttons button:hover::before,
button:not(.modal-close-btn):not(.password-toggle):hover::before {
left: 100%;
}
.button:hover,
.plugin-buttons button:hover,
button:not(.modal-close-btn):not(.password-toggle):hover {
background: var(--gradient-blue) !important;
color: white !important;
border-color: var(--accent-blue) !important;
transform: translateY(-2px);
box-shadow: var(--shadow-glow);
}
/* Special Button Types - Community Forum Colors */
.scan-btn {
color: var(--success-color) !important;
border-color: rgba(16, 185, 129, 0.3) !important;
background: rgba(16, 185, 129, 0.1) !important;
}
.scan-btn:hover {
background: linear-gradient(
135deg,
var(--success-color),
#059669
) !important;
color: white !important;
border-color: var(--success-color) !important;
}
.folder-btn {
color: var(--accent-light) !important;
border-color: rgba(96, 165, 250, 0.3) !important;
background: rgba(96, 165, 250, 0.1) !important;
}
.folder-btn:hover {
background: linear-gradient(
135deg,
var(--accent-light),
var(--accent-blue)
) !important;
color: white !important;
border-color: var(--accent-light) !important;
}
.build-btn {
color: var(--warning-color) !important;
border-color: rgba(245, 158, 11, 0.3) !important;
background: rgba(245, 158, 11, 0.1) !important;
}
.build-btn:hover {
background: linear-gradient(
135deg,
var(--warning-color),
#d97706
) !important;
color: white !important;
border-color: var(--warning-color) !important;
}
.info-btn {
color: var(--accent-light) !important;
border-color: rgba(96, 165, 250, 0.3) !important;
background: rgba(96, 165, 250, 0.1) !important;
}
.info-btn:hover {
background: linear-gradient(
135deg,
var(--accent-light),
var(--accent-blue)
) !important;
color: white !important;
border-color: var(--accent-light) !important;
}
.danger-btn {
color: var(--danger-color) !important;
border-color: var(--danger-color) !important;
}
.danger-btn:hover {
background: var(--danger-color) !important;
color: white !important;
}
/* Plugin Tools Section */
.plugin-tools {
margin-bottom: 10px;
}
/* Loading State */
.loading {
text-align: center;
color: var(--secondary-text-color);
padding: 30px;
font-style: italic;
background: rgba(0, 86, 179, 0.05);
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
}
/* Debug Info */
.debug-info {
margin: 10px 0;
padding: 15px;
background: rgba(0, 86, 179, 0.05);
border-radius: var(--border-radius);
border-left: 4px solid var(--accent-color);
}
.debug-stats {
display: flex;
gap: 15px;
font-size: 0.85rem;
}
.stat-files {
color: var(--secondary-text-color);
}
.stat-issues {
color: var(--success-color);
}
.stat-issues.has-errors {
color: var(--danger-color);
font-weight: bold;
}
/* Modal Styles */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: none;
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-overlay.show {
display: flex;
}
.modal-container {
background: var(--surface-color);
border-radius: var(--border-radius);
box-shadow: var(--shadow);
min-width: 400px;
max-width: 600px;
max-height: 80vh;
overflow-y: auto;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
border-bottom: 1px solid var(--border-color);
}
.modal-header h3 {
color: var(--accent-color);
margin: 0;
font-size: 1.2rem;
}
.modal-close-btn {
background: transparent;
border: none;
font-size: 24px;
color: var(--secondary-text-color);
cursor: pointer;
padding: 5px;
border-radius: 50%;
transition: var(--transition);
}
.modal-close-btn:hover {
background: var(--danger-color);
color: white;
}
.modal-body {
padding: 20px;
}
.status-item {
display: flex;
justify-content: space-between;
padding: 10px 0;
border-bottom: 1px solid var(--border-color);
}
.status-item:last-child {
border-bottom: none;
}
.status-label {
font-weight: 600;
color: var(--primary-text-color);
}
.status-value {
color: var(--secondary-text-color);
}
.status-value.small {
font-size: 0.85rem;
font-family: monospace;
}
/* Progress Bar Styles */
.progress-label {
font-size: 0.85rem;
color: var(--secondary-text-color);
margin-bottom: 5px;
}
.progress-bar {
background: var(--border-color);
height: 10px;
border-radius: 5px;
overflow: hidden;
position: relative;
}
.progress-fill {
height: 100%;
background: linear-gradient(
90deg,
var(--success-color),
var(--accent-color)
);
transition: width 0.8s ease;
position: relative;
overflow: hidden;
}
.progress-fill::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.3),
transparent
);
animation: progressShine 2s infinite;
}
.progress-text {
font-size: 0.8rem;
color: var(--secondary-text-color);
margin-top: 3px;
text-align: center;
}
/* Time Remaining Styles */
.time-remaining {
font-weight: bold;
}
.time-critical {
color: var(--danger-color);
}
.time-warning {
color: var(--warning-color);
}
.time-normal {
color: var(--success-color);
}
/* Activation Status Styles */
.status-icon {
font-size: 1.2rem;
margin-right: 5px;
animation: bounce 2s infinite;
}
.activation-badge {
display: inline-block;
padding: 4px 8px;
border-radius: 12px;
font-size: 0.75rem;
color: white;
font-weight: 500;
animation: fadeIn 1s ease-in-out;
}
.badge-activated {
background: var(--success-color);
}
.badge-pending {
background: var(--warning-color);
color: var(--bg-color);
}
.badge-expired {
background: var(--danger-color);
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 26: ADVANCED ANIMATIONS ║ */
/* ║ Complex Animations และ Effects ║ */
/* ║ [USAGE] ใช้ร่วมกัน: Advanced Effects ทั้งแอป ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes slideIn {
from {
transform: translateX(-10px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes scaleIn {
from {
transform: scale(0.98);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
@keyframes shimmer {
0% {
background-position: -200px 0;
}
100% {
background-position: 200px 0;
}
}
@keyframes bounce {
0%,
20%,
50%,
80%,
100% {
transform: translateY(0);
}
40% {
transform: translateY(-10px);
}
60% {
transform: translateY(-5px);
}
}
@keyframes progressShine {
0% {
left: -100%;
}
100% {
left: 100%;
}
}
@keyframes pulse {
0% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.01);
opacity: 0.9;
} /* ลดการเคลื่อนไหวให้นุ่มนวล */
100% {
transform: scale(1);
opacity: 1;
}
}
@keyframes gentleGlow {
0%,
100% {
box-shadow: 0 0 3px rgba(0, 170, 255, 0.2);
} /* ลดความเข้ม */
50% {
box-shadow: 0 0 6px rgba(0, 170, 255, 0.3);
} /* ลดความเข้ม */
}
@keyframes gentleShake {
0%,
100% {
transform: translateX(0);
}
25% {
transform: translateX(-1px);
} /* ลดจาก -2px เป็น -1px */
75% {
transform: translateX(1px);
} /* ลดจาก 2px เป็น 1px */
}
/* Apply gentle animations - ลบส่วนนี้ออกเพราะซ้ำกับ main plugin-card */
.plugin-card:nth-child(1) {
animation-delay: 0.05s;
}
.plugin-card:nth-child(2) {
animation-delay: 0.1s;
}
.plugin-card:nth-child(3) {
animation-delay: 0.15s;
}
.plugin-card:nth-child(4) {
animation-delay: 0.2s;
}
.plugin-card:nth-child(5) {
animation-delay: 0.25s;
}
.plugin-card:nth-child(6) {
animation-delay: 0.3s;
}
.plugin-buttons button {
position: relative;
overflow: hidden;
transition: all 0.2s ease;
padding: 6px 10px;
font-size: 0.75rem;
}
/* ปรับขนาด icon ในปุ่ม */
.btn-icon {
width: 12px !important;
height: 12px !important;
margin-right: 4px;
}
.plugin-buttons button::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.1),
transparent
); /* ลดความเข้มจาก 0.2 เป็น 0.1 */
transition: all 0.8s ease; /* เพิ่มจาก 0.5s เป็น 0.8s เพื่อให้นุ่มนวลขึ้น */
}
.plugin-buttons button:hover::before {
left: 100%;
}
.plugin-buttons button:active {
transform: translateY(1px); /* ลดการกดจาก translateY(0) */
transition: all 0.1s;
}
/* Enhanced success/error states */
.success-animation {
animation: gentleGlow 0.3s ease-in-out;
}
.error-animation {
animation: gentleShake 0.3s ease-in-out;
}
/* Shimmer effect for loading */
.shimmer {
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.05),
transparent
); /* ลดความเข้มจาก 0.1 เป็น 0.05 */
background-size: 200px 100%;
animation: shimmer 2.5s infinite; /* เพิ่มจาก 1.5s เป็น 2.5s เพื่อให้นุ่มนวล */
}
/* Dropdown Styles */
.header {
display: flex;
justify-content: space-between;
align-items: center;
}
.header-left {
flex: 1;
}
.header-right {
display: flex;
align-items: center;
gap: 15px;
}
.theme-controls {
display: flex;
align-items: center;
gap: 10px;
}
.header-btn {
padding: 8px 16px;
border: 1px solid var(--border-color);
background: var(--surface-color);
color: var(--primary-text-color);
border-radius: var(--border-radius);
cursor: pointer;
font-size: 14px;
transition: var(--transition);
display: flex;
align-items: center;
gap: 6px;
}
.header-btn:hover {
background: var(--accent-color);
color: white;
transform: translateY(-1px);
box-shadow: var(--shadow);
}
.header-btn:active {
transform: translateY(0);
}
#themeToggleBtn {
min-width: 40px;
justify-content: center;
}
#themeIcon {
font-size: 16px;
transition: var(--transition);
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-toggle,
.btn {
background-color: transparent;
color: white;
border: 2px solid rgba(255, 255, 255, 0.5);
padding: 10px 16px;
border-radius: 8px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
font-weight: 600;
transition: all 0.3s ease;
}
.dropdown-toggle:hover,
.btn:hover {
background-color: rgba(255, 255, 255, 0.2);
border-color: white;
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(255, 255, 255, 0.1);
}
.dropdown-menu {
position: absolute;
top: 100%;
right: 0;
background: var(--surface-color);
border: 1px solid var(--border-color);
border-radius: 8px;
box-shadow: 0 8px 25px var(--shadow-color);
min-width: 150px;
z-index: 1000;
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s ease;
}
.dropdown-menu.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
.dropdown-item {
display: block;
padding: 12px 16px;
color: var(--primary-text-color);
text-decoration: none;
font-weight: 500;
transition: all 0.2s ease;
}
.dropdown-item:hover {
background-color: var(--accent-color);
color: white;
}
/* Modal Styles */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
backdrop-filter: blur(5px);
display: flex;
justify-content: center;
align-items: center;
z-index: 2000;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
}
.modal-overlay.show {
opacity: 1;
visibility: visible;
}
.modal-container {
background: var(--surface-color);
border: 1px solid var(--border-color);
border-radius: 12px;
box-shadow: 0 8px 25px var(--shadow-color);
max-width: 500px;
width: 90%;
max-height: 80vh;
overflow-y: auto;
transform: scale(0.95);
transition: transform 0.3s ease;
}
.modal-overlay.show .modal-container {
transform: scale(1);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
border-bottom: 1px solid var(--border-color);
background: linear-gradient(
135deg,
var(--accent-color) 0%,
#0066cc 100%
);
color: white;
border-radius: 12px 12px 0 0;
}
.modal-header h3 {
margin: 0;
display: flex;
align-items: center;
gap: 10px;
font-weight: 600;
}
.modal-close-btn {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
padding: 0;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
transition: all 0.2s ease;
}
.modal-close-btn:hover {
background: rgba(255, 255, 255, 0.2);
transform: scale(1.1);
}
.modal-body {
padding: 20px;
color: var(--primary-text-color);
}
.status-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 0;
border-bottom: 1px solid var(--border-color);
}
.status-item:last-child {
border-bottom: none;
}
.status-label {
font-weight: 600;
color: var(--secondary-text-color);
}
.status-value {
color: var(--primary-text-color);
font-weight: 500;
}
.status-value.small {
font-size: 0.9em;
font-family: "Courier New", monospace;
background: var(--bg-color);
padding: 4px 8px;
border-radius: 4px;
border: 1px solid var(--border-color);
}
.terminal-section {
animation: slideIn 0.8s ease-out;
}
.sidebar {
animation: slideIn 0.8s ease-out;
animation-delay: 0.2s;
animation-fill-mode: both;
width: 300px;
min-width: 280px;
transition: var(--transition);
}
/* Sidebar Header Styles */
.sidebar-header {
display: flex;
align-items: center;
justify-content: center;
padding: 15px 20px;
border-bottom: 1px solid var(--border-color);
position: sticky;
top: 0;
background: var(--surface-color);
z-index: 10;
}
.sidebar-title {
color: var(--accent-color);
margin: 0;
font-size: 1.3rem;
font-weight: 600;
transition: var(--transition);
white-space: nowrap;
overflow: hidden;
}
.sidebar-content {
overflow: hidden;
}
.sidebar-full-content {
padding: 20px;
transition: var(--transition);
}
.sidebar-quick-actions {
display: none;
flex-direction: column;
gap: 10px;
align-items: center;
padding: 15px 5px;
}
/* Container layout adjustments */
.container {
transition: var(--transition);
}
/* Responsive sidebar */
@media (max-width: 1400px) {
.sidebar {
width: 300px;
min-width: 280px;
}
}
@media (max-width: 1200px) {
.sidebar {
width: 280px;
min-width: 260px;
}
}
@media (max-width: 1000px) {
.sidebar {
width: 260px;
min-width: 240px;
}
}
.terminal-line {
animation: fadeIn 0.3s ease-in;
}
.loading {
animation: pulse 4s infinite ease-in-out;
}
/* เอฟเฟกต์พิเศษสำหรับ Header */
.header {
position: relative;
overflow: hidden;
}
/* ปิด animation แสงส่องผ่านที่ทำให้กะพริบ */
.header::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.1),
transparent
);
/* animation: progressShine 3s infinite; ← ปิดแล้ว */
}
.header h1 {
animation: fadeIn 1s ease-in-out;
}
.header p {
animation: fadeIn 1.2s ease-in-out;
}
/* เอฟเฟกต์การพิมพ์ */
.typing-effect {
width: 0;
white-space: nowrap;
overflow: hidden;
border-right: 2px solid #667eea;
animation: typing 3s steps(40, end), blink 1s infinite;
}
.action-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 8px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 0.85rem;
font-weight: 500;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
.action-btn::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.4),
transparent
);
transition: all 0.6s;
}
.action-btn:hover::before {
left: 100%;
}
.action-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}
.action-btn:active {
transform: translateY(0);
transition: all 0.1s;
}
.action-btn.info {
background: linear-gradient(135deg, #17a2b8, #138496);
}
.action-btn.copy {
background: linear-gradient(135deg, #28a745, #1e7e34);
}
.action-btn.help {
background: linear-gradient(135deg, #fd7e14, #e76500);
}
.action-btn.refresh {
background: linear-gradient(135deg, #6c757d, #495057);
}
/* เอฟเฟกต์ Floating สำหรับ Plugin Cards - ลบออกเพราะซ้ำกับ main hover */
/* สไตล์พิเศษสำหรับ Command Input */
.command-input {
position: relative;
}
.command-input:focus {
outline: none;
background: rgba(255, 255, 255, 0.1);
border-radius: 4px;
padding: 2px 8px;
margin: -2px -8px;
}
/* เอฟเฟกต์ Loading ที่สวยงาม */
.loading::after {
content: "...";
animation: dots 1.5s infinite;
}
@keyframes dots {
0%,
20% {
color: transparent;
text-shadow: 0.25em 0 0 transparent, 0.5em 0 0 transparent;
}
40% {
color: #6c757d;
text-shadow: 0.25em 0 0 transparent, 0.5em 0 0 transparent;
}
60% {
text-shadow: 0.25em 0 0 #6c757d, 0.5em 0 0 transparent;
}
80%,
100% {
text-shadow: 0.25em 0 0 #6c757d, 0.5em 0 0 #6c757d;
}
}
/* เอฟเฟกต์ Rainbow สำหรับ Header - ปิดแล้ว */
@keyframes rainbow {
0% {
filter: hue-rotate(0deg);
}
100% {
filter: hue-rotate(360deg);
}
}
.header:hover {
/* animation: rainbow 3s infinite; ← ปิดแล้ว เพื่อไม่ให้กะพริบ */
transition: all 0.3s ease;
}
/* เอฟเฟกต์ Success Animation */
.success-animation {
animation: successPulse 0.6s ease-in-out;
}
@keyframes successPulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.1);
background-color: rgba(40, 167, 69, 0.2);
}
100% {
transform: scale(1);
}
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 27: DEVELOPER MODE ║ */
/* ║ Developer Mode Controls ║ */
/* ║ [USAGE] ใช้แยก: Developer Mode Features เท่านั้น ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Developer Mode Controls */
.dev-only {
display: none !important;
}
body.dev-mode .dev-only {
display: inline-block !important;
position: relative;
overflow: hidden;
}
body.dev-mode .dev-only::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.1),
transparent
);
animation: devGlow 3s infinite;
}
@keyframes devGlow {
0% {
left: -100%;
}
50% {
left: 100%;
}
100% {
left: 100%;
}
}
body.dev-mode .dev-only::after {
content: "[DEV]";
position: absolute;
top: 2px;
right: 5px;
font-size: 9px;
color: rgba(255, 255, 255, 0.5);
font-weight: bold;
}
/* === Helpers for main page switching (plugins <-> store) === */
.hide {
display: none !important;
}
.fullwidth {
width: 100% !important;
min-width: 100% !important;
max-width: 100% !important;
flex: 1 1 auto !important;
}
/* Store mode: แสดงทั้งหมดปกติ */
/* ไม่ซ่อนอะไรเลย ให้แสดงเว็บเต็มรูปแบบ */
/* ซ่อนปุ่ม marketplace ที่อาจจะยังค้างอยู่ */
#show-marketplace-btn,
#refresh-marketplace-btn {
display: none !important;
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ CSS ZONE 28: AUTHENTICATION ║ */
/* ║ Authentication Header & Controls ║ */
/* ║ [USAGE] ใช้ร่วมกัน: Auth System ทั้งแอป ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
/* Auth Header Container */
.auth-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.75rem;
padding: 0.4rem 0.6rem;
background: var(--glass-bg);
border: 1px solid var(--glass-border);
border-radius: 12px;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
margin-bottom: 0.5rem;
box-shadow: var(--shadow-glow-card);
position: relative; /* เพื่อให้ dropdown positioning ทำงานถูกต้อง */
margin-left: auto; /* ดัน auth-header ไปขวาสุด */
}
.auth-user-info {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.3rem 0.5rem;
cursor: pointer;
border-radius: 8px;
transition: all 0.3s ease;
position: relative;
}
.auth-user-info:hover {
background: rgba(14, 165, 233, 0.1);
border: 1px solid var(--glass-border-hover);
}
.auth-user-avatar {
width: 36px;
height: 36px;
border-radius: 50%;
background: var(--gradient-blue);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
font-size: 0.9rem;
border: 2px solid var(--glass-border);
}
.auth-user-details {
display: flex;
flex-direction: column;
}
.auth-user-name {
color: var(--text-primary);
font-weight: 600;
font-size: 0.95rem;
}
.auth-user-role {
color: var(--text-secondary);
font-size: 0.8rem;
text-transform: capitalize;
}
.auth-login-btn {
padding: 0.5rem 1rem;
background: var(--gradient-blue);
color: white;
border: none;
border-radius: 8px;
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: var(--shadow-glow-subtle);
}
.auth-login-btn:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-glow-strong);
}
.auth-login-btn:disabled {
background: #555;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
/* Auth Dropdown Menu */
.auth-dropdown {
position: absolute; /* เปลี่ยนกลับเป็น absolute ตาม document order */
top: 100%; /* ใต้ parent element */
right: 0; /* ชิดขวา */
background: var(--bg-secondary);
border: 2px solid var(--glass-border);
border-radius: 12px;
padding: 0.5rem 0;
min-width: 220px;
box-shadow: var(--shadow-xl);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
z-index: 5000; /* แก้เป็น 5000 - สูงกว่า notification (3000) ต่ำกว่า security overlay (10000) */
display: none;
margin-top: 0.5rem;
}
.auth-dropdown.show {
display: block;
animation: fadeIn 0.3s ease;
}
.auth-dropdown-item {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.8rem 1rem;
color: var(--text-primary);
cursor: pointer;
transition: all 0.3s ease;
font-size: 0.9rem;
}
.auth-dropdown-item:hover {
background: rgba(14, 165, 233, 0.1);
color: var(--accent-blue);
}
.auth-dropdown-divider {
height: 1px;
background: var(--border-color);
margin: 0.5rem 0;
}
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
/* OFFLINE LOGIN FORM STYLES - เพิ่มใหม่ */
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.offline-login-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.85);
z-index: 5000;
display: flex;
align-items: center;
justify-content: center;
animation: fadeIn 0.3s ease;
backdrop-filter: blur(4px);
}
.offline-login-container {
background: linear-gradient(135deg, #111827 0%, #0d1117 100%);
border: 1px solid rgba(14, 165, 233, 0.3);
border-radius: 12px;
padding: 2.5rem;
width: 100%;
max-width: 420px;
box-shadow:
0 0 0 1px rgba(14, 165, 233, 0.2),
0 0 30px rgba(14, 165, 233, 0.2),
0 20px 40px rgba(0, 0, 0, 0.5);
animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.offline-login-header {
margin-bottom: 2rem;
text-align: center;
border-bottom: 2px solid rgba(14, 165, 233, 0.2);
padding-bottom: 1.5rem;
}
.offline-login-header h2 {
color: var(--text-primary);
font-size: 1.5rem;
margin-bottom: 0.5rem;
font-weight: 600;
}
.offline-login-header p {
color: var(--text-secondary);
font-size: 0.9rem;
}
.offline-login-form {
margin-bottom: 1.5rem;
}
.form-group {
margin-bottom: 1.5rem;
}
.form-group label {
display: block;
color: var(--text-primary);
font-size: 0.95rem;
font-weight: 500;
margin-bottom: 0.5rem;
}
.form-group input {
width: 100%;
padding: 0.75rem 1rem;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(14, 165, 233, 0.2);
border-radius: 6px;
color: var(--text-primary);
font-size: 1rem;
transition: all 0.3s ease;
}
.form-group input::placeholder {
color: var(--text-muted);
}
.form-group input:focus {
outline: none;
background: rgba(255, 255, 255, 0.08);
border-color: var(--accent-blue);
box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}
.form-group small {
display: block;
color: var(--text-muted);
font-size: 0.8rem;
margin-top: 0.3rem;
}
.form-actions {
display: flex;
gap: 1rem;
margin-bottom: 1.5rem;
}
.btn-login, .btn-cancel {
flex: 1;
padding: 0.9rem 1.5rem;
border: none;
border-radius: 6px;
font-size: 0.95rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.btn-login {
background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-dark) 100%);
color: white;
box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}
.btn-login:hover {
background: linear-gradient(135deg, var(--accent-light) 0%, var(--accent-blue) 100%);
box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
transform: translateY(-2px);
}
.btn-login:active {
transform: translateY(0);
}
.btn-cancel {
background: rgba(255, 255, 255, 0.05);
color: var(--text-secondary);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.btn-cancel:hover {
background: rgba(255, 255, 255, 0.1);
color: var(--text-primary);
border-color: rgba(255, 255, 255, 0.2);
}
.demo-users {
background: rgba(14, 165, 233, 0.1);
border-left: 3px solid var(--accent-blue);
padding: 1rem;
border-radius: 4px;
font-size: 0.85rem;
}
.demo-users p {
color: var(--text-primary);
margin-bottom: 0.7rem;
font-weight: 500;
}
.demo-users ul {
list-style: none;
padding: 0;
}
.demo-users li {
color: var(--text-secondary);
padding: 0.3rem 0;
}
.demo-users code {
background: rgba(0, 0, 0, 0.3);
padding: 0.2rem 0.4rem;
border-radius: 3px;
color: var(--accent-light);
font-family: 'Monaco', 'Courier New', monospace;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Loading States */
.auth-loading {
display: inline-flex;
align-items: center;
gap: 0.6rem;
color: var(--text-secondary);
font-size: 0.9rem;
padding: 0.7rem 1rem;
}
.auth-loading-spinner {
width: 18px;
height: 18px;
border: 2px solid var(--border-color);
border-top: 2px solid var(--accent-blue);
border-radius: 50%;
animation: spin 1s linear infinite;
}
/* Permission Dialog */
.permission-dialog {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
z-index: 3000;
display: none;
align-items: center;
justify-content: center;
animation: fadeIn 0.3s ease;
}
.permission-dialog.show {
display: flex;
}
.permission-dialog-content {
background: var(--bg-secondary);
border: 2px solid var(--accent-blue);
border-radius: 16px;
padding: 2rem;
width: 90%;
max-width: 500px;
animation: slideIn 0.3s ease;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
}
.permission-dialog-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
}
.permission-dialog-header h3 {
color: var(--accent-blue);
font-size: 1.4rem;
margin: 0;
font-weight: 600;
}
.permission-list {
list-style: none;
padding: 0;
margin: 1rem 0;
}
.permission-item {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.75rem 0;
color: var(--text-primary);
border-bottom: 1px solid var(--border-color);
}
.permission-item:last-child {
border-bottom: none;
}
.permission-icon {
width: 16px;
height: 16px;
border-radius: 4px;
background: var(--accent-blue);
flex-shrink: 0;
}
.permission-dialog-actions {
display: flex;
gap: 1rem;
margin-top: 2rem;
justify-content: flex-end;
}
.btn-permission {
padding: 0.8rem 1.6rem;
border: 2px solid var(--border-color);
border-radius: 8px;
background: var(--glass-bg);
color: var(--text-primary);
cursor: pointer;
font-size: 0.9rem;
font-weight: 500;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.btn-permission.primary {
background: var(--gradient-blue);
color: white;
border-color: var(--accent-blue);
}
.btn-permission:hover {
border-color: var(--accent-blue);
background: rgba(14, 165, 233, 0.1);
transform: translateY(-1px);
}
.btn-permission.primary:hover {
background: var(--accent-blue-hover);
box-shadow: var(--shadow-glow);
}
/* ======== OUTER TOPNAV (Home / App) ======== */
#outer-topnav {
position: fixed;
top: 0; left: 0; right: 0;
height: 44px;
display: flex;
align-items: center;
gap: 4px;
padding: 0 12px;
background: rgba(10, 14, 22, 0.97);
border-bottom: 1px solid rgba(255,255,255,0.08);
z-index: 9000;
-webkit-app-region: drag;
}
#outer-topnav .ont-brand {
font-size: 13px;
font-weight: 600;
color: var(--text-primary);
letter-spacing: 0.04em;
margin-right: 12px;
opacity: 0.9;
}
#outer-topnav .ont-sep {
width: 1px; height: 20px;
background: rgba(255,255,255,0.12);
margin: 0 4px;
}
#outer-topnav .ont-tab {
-webkit-app-region: no-drag;
background: transparent;
border: none;
color: rgba(249,250,251,0.55);
font-size: 13px;
font-weight: 500;
padding: 5px 14px;
border-radius: 7px;
cursor: pointer;
transition: background 0.15s, color 0.15s;
}
#outer-topnav .ont-tab:hover {
background: rgba(14,165,233,0.12);
color: var(--accent-blue);
}
#outer-topnav .ont-tab.active {
background: var(--accent-blue);
color: #fff;
font-weight: 600;
}
/* Home webview overlay */
#home-wv-wrap, #chat-wv-wrap {
position: fixed;
top: 44px; left: 0; right: 0; bottom: 0;
z-index: 8999;
display: none;
}
#home-wv-wrap.visible, #chat-wv-wrap.visible { display: block; }
#home-wv-wrap webview, #chat-wv-wrap webview {
width: 100%; height: 100%;
border: none;
}
/* Push app content below outer topnav */
body { padding-top: 44px !important; }
</style>
</head>
<body>
<!-- Outer topnav: Home / App switching -->
<div id="outer-topnav">
<span class="ont-brand">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:5px"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
CHAHUADEV FRAMEWORK
</span>
<span class="ont-sep"></span>
<button class="ont-tab active" id="ont-home" onclick="switchTopPage('home')">
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:4px"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>
Home
</button>
<button class="ont-tab" id="ont-app" onclick="switchTopPage('app')">
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:4px"><rect x="2" y="3" width="20" height="14" rx="2" ry="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>
App
</button>
<button class="ont-tab" id="ont-chat" onclick="switchTopPage('chat')">
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:4px"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/></svg>
Chat
</button>
</div>
<!-- Home landing page webview -->
<div id="home-wv-wrap" class="visible">
<webview src="./web/index.html" allowpopups></webview>
</div>
<!-- Chat landing page webview -->
<div id="chat-wv-wrap">
<webview src="./web/chat.html" allowpopups></webview>
</div>
<!-- ╔══════════════════════════════════════════════════════════════════════════════════╗ -->
<!-- ║ HTML ZONE 29: NAVIGATION ║ -->
<!-- ║ ส่วน Navigation หลักของแอป ║ -->
<!-- ║ [USAGE] Used together: Navigation Bar entire app ║ -->
<!-- ╚══════════════════════════════════════════════════════════════════════════════════╝ -->
<!-- === Top navigation for switching main pages === -->
<div class="view-switcher">
<div class="view-tabs">
<button id="nav-plugins" class="view-btn active">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="2" y="3" width="20" height="14" rx="2" ry="2" />
<line x1="8" y1="21" x2="16" y2="21" />
<line x1="12" y1="17" x2="12" y2="21" />
</svg>
<span>Plugin Management</span>
</button>
<button id="nav-store-new" class="dev-only">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="9" cy="21" r="1" />
<circle cx="20" cy="21" r="1" />
<path d="m1 1 4 4 13 0 1 6-13 0" />
<path
d="M16 8a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1V8z"
/>
</svg>
<span>Plugin Store</span>
</button>
</div>
<!-- Auth Header Component (VS Code Style) - ย้ายมาอยู่ขวาสุด -->
<div id="auth-header" class="auth-header">
<!-- Auth Status Display -->
<div id="auth-status-container">
<!-- Guest State -->
<div id="auth-guest" class="auth-user-info">
<div class="auth-user-avatar">G</div>
<div class="auth-user-details">
<div class="auth-user-name">Guest User</div>
<div class="auth-user-role">Guest</div>
</div>
</div>
<!-- Authenticated State -->
<div id="auth-user" class="auth-user-info" style="display: none;">
<div id="auth-user-avatar" class="auth-user-avatar">U</div>
<div class="auth-user-details">
<div id="auth-user-name" class="auth-user-name">Loading...</div>
<div id="auth-user-role" class="auth-user-role">loading</div>
</div>
<!-- Auth Dropdown Menu -->
<div id="auth-dropdown" class="auth-dropdown">
<div class="auth-dropdown-item" id="auth-profile">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/>
<circle cx="12" cy="7" r="4"/>
</svg>
Profile
</div>
<div class="auth-dropdown-item" id="auth-permissions">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
<circle cx="12" cy="16" r="1"/>
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
</svg>
Permissions
</div>
<div class="auth-dropdown-divider"></div>
<div class="auth-dropdown-item" id="auth-logout">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/>
<polyline points="16,17 21,12 16,7"/>
<line x1="21" y1="12" x2="9" y2="12"/>
</svg>
Logout
</div>
</div>
</div>
<!-- Loading State -->
<div id="auth-loading" class="auth-loading" style="display: none;">
<div class="auth-loading-spinner"></div>
Signing in...
</div>
</div>
<!-- Auth Actions -->
<button id="auth-login-btn" class="auth-login-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/>
<polyline points="10,17 15,12 10,7"/>
<line x1="15" y1="12" x2="3" y2="12"/>
</svg>
Sign In
</button>
</div>
<div class="view-actions">
<button
id="refresh-store-btn"
class="refresh-btn"
onclick="refreshStoreWebview()"
style="display: none"
>
<span class="refresh-icon">
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
>
<path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8" />
<path d="M21 3v5h-5" />
<path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16" />
<path d="M3 21v-5h5" />
</svg>
</span>
<span class="refresh-text">รีเฟรช</span>
</button>
</div>
</div>
<!-- ╔══════════════════════════════════════════════════════════════════════════════════╗ -->
<!-- ║ HTML ZONE 30: MAIN LAYOUT ║ -->
<!-- ║ Layout หลักของแอปพลิเคชัน ║ -->
<!-- ║ [USAGE] ใช้ร่วมกัน: Terminal + Plugin Manager Layout ║ -->
<!-- ║ พื้นที่สำหรับระบบใหม่ ║ -->
<!-- ╚══════════════════════════════════════════════════════════════════════════════════╝ -->
<!-- OLD: Original Container System (ยังคงไว้ก่อน) -->
<div class="container" id="original-system">
<!-- Left Panel - Terminal Section -->
<div class="terminal-section">
<div class="view-container">
<pre
id="log-viewer"
class="log-viewer-container view-panel active"
></pre>
<webview
id="store-webview"
src="about:blank"
class="view-panel"
style="width: 100%; height: 100%; border: none;"
partition="persist:store"
nodeintegration="false"
preload="./preload-webview.js"
></webview>
<webview
id="marketplace-webview"
class="marketplace-container view-panel"
src="about:blank"
preload="./preload.js"
></webview>
</div>
<!-- Resize Handle -->
<div class="resize-handle" id="resizeHandle"></div>
</div>
<!-- ╔══════════════════════════════════════════════════════════════════════════════════╗ -->
<!-- ║ HTML ZONE 31: SIDEBAR ║ -->
<!-- ║ Sidebar จัดการPluginด้านขวา ║ -->
<!-- ║ [USAGE] ใช้แยก: Plugin Manager Sidebar เท่านั้น ║ -->
<!-- ╚══════════════════════════════════════════════════════════════════════════════════╝ -->
<!-- Right Panel - Plugin Management -->
<div class="sidebar" id="sidebar">
<h2>Plugin & Project Management</h2>
<div class="plugin-tools">
<div class="plugin-buttons">
<button onclick="checkAuthAndExecute('runGeneratorAndRefresh')" class="scan-btn" id="scan-plugin-btn">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" style="width:16px; height:16px; margin-right: 5px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99" />
</svg>
<span>Scan Plugins</span>
</button>
<button onclick="checkAuthAndExecute('openPluginsFolder')" class="folder-btn" id="open-folder-btn">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" style="width:16px; height:16px; margin-right: 5px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12.75V12A2.25 2.25 0 014.5 9.75h15A2.25 2.25 0 0121.75 12v.75m-8.69-6.44-2.12-2.12a1.5 1.5 0 00-1.061-.44H4.5A2.25 2.25 0 002.25 6v12a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9a2.25 2.25 0 00-2.25-2.25H13.19l-2.12-2.12a1.5 1.5 0 00-1.061-.44z" />
</svg>
<span>Open Plugin Folder</span>
</button>
<button onclick="checkAuthAndExecute('runGenerateManifestOnly')" class="build-btn" id="generate-manifest-btn">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" style="width:16px; height:16px; margin-right: 5px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.325.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
<span>Generate Manifest</span>
</button>
</div>
</div>
<div id="plugin-container">
<div class="loading">Loading Plugins...</div>
</div>
</div>
</div>
<!-- ╔══════════════════════════════════════════════════════════════════════════════════╗ -->
<!-- ║ JAVASCRIPT ZONE 32: CORE SYSTEM ║ -->
<!-- ║ ระบบหลักและฟังก์ชันพื้นฐาน ║ -->
<!-- ║ [USAGE] ใช้ร่วมกัน: Core Functions สำหรับทั้ง Terminal และ Plugin ║ -->
<!-- ╚══════════════════════════════════════════════════════════════════════════════════╝ -->
<script>
// --- โหลดระบบ AuthDialog ---
const authDialogScript = document.createElement('script');
authDialogScript.src = './auth-dialog.js';
document.head.appendChild(authDialogScript);
// --- โหลดระบบ Resize Controller ---
const logViewer = document.getElementById("log-viewer");
const pluginContainer = document.getElementById("plugin-container");
const addTerminalLine = (text, type = "info") => {
if (!logViewer) return;
const timestamp = new Date();
const time = timestamp.toLocaleTimeString("th-TH", { hour12: false });
// สร้าง Element ใหม่สำหรับแต่ละบรรทัด Log
const logLine = document.createElement("span");
logLine.className = `log-line log-${type}`;
// สร้างข้อความ Log พร้อม timestamp
logLine.textContent = `[${time}] ${text}\n`;
// เพิ่มบรรทัดใหม่ลงใน Log Viewer
logViewer.appendChild(logLine);
// เลื่อนหน้าจอไปที่บรรทัดล่าสุดเสมอ
logViewer.scrollTop = logViewer.scrollHeight;
};
// Keyboard support (Escape key + Resize)
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
// Stop resize if active
if (window.resizeController && window.resizeController.isResizing) {
window.resizeController.stopResize();
}
}
});
// ======================================================================
// ฟังก์ชันคัดลอก Machine ID ไปยังคลิปบอร์ด
// ======================================================================
async function copyMachineID(machineID) {
try {
await navigator.clipboard.writeText(machineID);
addTerminalLine(` Machine ID copied: ${machineID}`, "success");
} catch (error) {
addTerminalLine(
`ERROR: Cannot copy: ${error.message}`,
"error"
);
}
}
// ======================================================================
// ฟังก์ชันสแกนและแสดงรายการPlugin
// ======================================================================
async function scanAndRenderPlugins() {
addTerminalLine(" Scanning plugins...", "command");
// แสดง loading animation
showLoadingAnimation(pluginContainer, "Scanning Plugins");
// Using correct API that exists in main.js
// preload.js ได้เตรียม window.electronAPI.plugins.getAll() ไว้ให้แล้ว
const result = await window.electronAPI.plugins.getAll();
console.log(
"--- Data from Main Process (get-available-plugins) ---",
result
);
if (result.success && result.plugins) {
pluginContainer.innerHTML = '<div class="plugin-grid"></div>';
const grid = pluginContainer.querySelector(".plugin-grid");
const plugins = result.plugins;
if (plugins.length === 0) {
grid.innerHTML = `<div class="loading">No plugins or projects found</div>`;
addTerminalLine(
" No projects available for button generation",
"info"
);
} else {
// เพิ่ม plugins ทีละตัวพร้อม animation delay
plugins.forEach((pluginData, index) => {
setTimeout(() => {
const card = document.createElement("div");
card.className = "plugin-card";
card.style.animationDelay = `${index * 0.1}s`;
card.innerHTML = `
${
pluginData.previewImage
? `<div class="plugin-image-container"><img src="${pluginData.previewImage}" class="plugin-preview-image" alt="Preview for ${pluginData.name}"></div>`
: ""
}
<h3>${getIconForType(pluginData)} ${
pluginData.name
}</h3>
<p>${
pluginData.description ||
`ประเภท: ${pluginData.type}`
}</p>
${
pluginData.debugInfo
? `
<div class="debug-info">
<div class="debug-stats">
<span class="stat-files"> ${
pluginData.debugInfo.totalFiles ||
0
} files</span>
<span class="stat-issues ${
pluginData.debugInfo.errors > 0
? "has-errors"
: ""
}">
${
pluginData.debugInfo.errors ||
0
} errors, ${
pluginData.debugInfo.warnings || 0
} warnings
</span>
</div>
</div>
`
: ""
}
<div class="plugin-buttons">
${createPluginButtons(pluginData)}
</div>
`;
grid.appendChild(card);
}, index * 100);
});
// แสดงผลลัพธ์หลังจาก animations เสร็จ
setTimeout(() => {
addTerminalLine(
`SUCCESS: Scanning complete. Found ${plugins.length} available projects`,
"success"
);
showNotification(
` พบ ${plugins.length} Pluginที่พร้อมใช้งาน!`,
"success"
);
}, plugins.length * 100 + 200);
}
} else {
pluginContainer.innerHTML = `<div class="loading">Error loading plugins</div>`;
addTerminalLine(
`ERROR: Plugin scan failed: ${
result.error || "No data received from Main Process"
}`,
"error"
);
showNotification("ERROR: Failed to scan plugins", "error");
}
}
// ======================================================================
// // ฟังก์ชันสแกนPluginพร้อมข้อมูล Debug
// ======================================================================
async function scanAndRenderPluginsWithDebug() {
addTerminalLine(" Scanning plugins with debug info...", "command");
// Show loading animation
showLoadingAnimation(pluginContainer, "Analyzing Plugins");
try {
// ใช้ IPC handler ที่เราสร้างใหม่ - แก้ไขใช้ API ที่ถูกต้อง
const result =
await window.electronAPI.projectInspector.scanWithDebug();
console.log("--- Enhanced Scan Result ---", result);
if (result.success && result.plugins) {
pluginContainer.innerHTML = '<div class="plugin-grid"></div>';
const grid = pluginContainer.querySelector(".plugin-grid");
const plugins = result.plugins;
if (plugins.length === 0) {
grid.innerHTML = `<div class="loading">No plugins or projects found</div>`;
addTerminalLine(
" No projects available for button generation",
"info"
);
} else {
let totalErrors = 0;
let totalWarnings = 0;
// เพิ่ม plugins ทีละตัวพร้อม animation delay
plugins.forEach((pluginData, index) => {
setTimeout(() => {
const card = document.createElement("div");
card.className = "plugin-card";
card.style.animationDelay = `${index * 0.1}s`;
card.innerHTML = `
${
pluginData.previewImage
? `<div class="plugin-image-container"><img src="${pluginData.previewImage}" class="plugin-preview-image" alt="Preview for ${pluginData.name}"></div>`
: ""
}
<h3>${getIconForType(pluginData)} ${
pluginData.name
}</h3>
<p>${
pluginData.description ||
`ประเภท: ${pluginData.type}`
}</p>
${
pluginData.debugInfo
? `
<div class="debug-info">
<div class="debug-stats">
<span class="stat-files"> ${
pluginData.debugInfo
.totalFiles || 0
} files</span>
<span class="stat-issues ${
pluginData.debugInfo.errors >
0
? "has-errors"
: ""
}">
${
pluginData.debugInfo
.errors || 0
} errors, ${
pluginData.debugInfo.warnings || 0
} warnings
</span>
</div>
</div>
`
: ""
}
<div class="plugin-buttons">
${createPluginButtons(pluginData)}
</div>
`;
grid.appendChild(card);
// รวมสถิติ
if (pluginData.debugInfo) {
totalErrors += pluginData.debugInfo.errors || 0;
totalWarnings += pluginData.debugInfo.warnings || 0;
}
}, index * 100);
});
// แสดงผลลัพธ์หลังจาก animations เสร็จ
setTimeout(() => {
addTerminalLine(
`SUCCESS: Enhanced scan complete: ${plugins.length} projects`,
"success"
);
addTerminalLine(
` Found issues: ${totalErrors} errors, ${totalWarnings} warnings`,
totalErrors > 0 ? "error" : "info"
);
showNotification(
` Scanned ${plugins.length} plugins with debug info!`,
"success"
);
}, plugins.length * 100 + 200);
}
} else {
pluginContainer.innerHTML = `<div class="loading">Error scanning with debug</div>`;
addTerminalLine(
`ERROR: Debug scan failed: ${
result.error || "No data received from Main Process"
}`,
"error"
);
showNotification("ERROR: Failed to scan with debug", "error");
}
} catch (error) {
console.error("Enhanced scan error:", error);
pluginContainer.innerHTML = `<div class="loading">Error during scan</div>`;
addTerminalLine(
`ERROR: Enhanced scan failed: ${error.message}`,
"error"
);
showNotification("ERROR: Failed to perform debug scan", "error");
}
}
// ======================================================================
// ฟังก์ชันสร้าง Manifest และรีเฟรชข้อมูลPlugin
// ======================================================================
async function runGeneratorAndRefresh() {
addTerminalLine(
" Scanning for new plugins and creating manifest...",
"command"
);
// Show loading in plugin container
showLoadingAnimation(pluginContainer, "Creating Manifest");
try {
const result = await window.electronAPI.runManifestGenerator();
if (result.success) {
addTerminalLine(
"SUCCESS: Manifest created! Loading plugin list...",
"success"
);
showNotification("SUCCESS: Manifest created successfully!", "success");
// โหลดรายการPluginใหม่หลังจากสร้างเสร็จ
setTimeout(async () => {
await scanAndRenderPlugins();
}, 500);
} else {
addTerminalLine(
`ERROR: Failed to create manifest: ${result.error}`,
"error"
);
showNotification(
"ERROR: Failed to create manifest",
"error"
);
pluginContainer.innerHTML = `<div class="loading">Error creating manifest</div>`;
}
} catch (error) {
addTerminalLine(
`ERROR: Severe IPC error: ${error.message}`,
"error"
);
showNotification("ERROR: Severe IPC error", "error");
pluginContainer.innerHTML = `<div class="loading">Critical error occurred</div>`;
}
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ JAVASCRIPT ZONE 32: PLUGIN MANAGEMENT ║ */
/* ║ ฟังก์ชันจัดการ Plugin และ Manifest ║ */
/* ║ [USAGE] ใช้แยก: Plugin Management Functions เท่านั้น ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
async function runGenerateManifestOnly() {
addTerminalLine("TOOL: Running Manifest Generator...", "command");
try {
const result = await window.electronAPI.runManifestGenerator();
if (result.success) {
addTerminalLine("SUCCESS: Manifest files created!", "success");
addTerminalLine(` Output:`, "info");
addTerminalLine(result.output, "stdout");
} else {
addTerminalLine(
`ERROR: Failed to create manifest: ${result.error}`,
"error"
);
}
} catch (error) {
addTerminalLine(
`ERROR: Critical IPC error: ${error.message}`,
"error"
);
}
}
// ======================================================================
//// ฟังก์ชันเปิดโฟลเดอร์Plugin (NEW)
// ======================================================================
async function openPluginsFolder() {
addTerminalLine(" Opening Plugin folder...", "command");
try {
const result = await window.electronAPI.openPluginsFolder();
if (result.success) {
addTerminalLine(
"SUCCESS: Plugin folder opened in File Explorer",
"success"
);
addTerminalLine(` Location: ${result.path}`, "info");
addTerminalLine(
' You can place plugin files in this folder and click "Refresh" to scan',
"info"
);
showNotification(" Plugin folder opened!", "success");
} else {
addTerminalLine(
`ERROR: Unable to open Plugin folder: ${result.error}`,
"error"
);
showNotification(
"ERROR: Unable to open Plugin folder",
"error"
);
}
} catch (error) {
addTerminalLine(`ERROR: IPC Error: ${error.message}`, "error");
showNotification("ERROR: IPC Error", "error");
}
}
// ======================================================================
// ฟังก์ชัน Build App (MSI/EXE) - NEW
// ======================================================================
async function startBuildProcess() {
addTerminalLine(
" Starting application build process...",
"command"
);
addTerminalLine(" Command: npx electron-builder --win --x64", "command");
addTerminalLine(
" Please wait, this process may take several minutes...",
"info"
);
addTerminalLine(
" Build will create MSI and EXE files for Windows installation",
"info"
);
// ======================================================================
// // แสดงการแจ้งเตือนและอนิเมชั่น
// ======================================================================
showNotification(" Starting Build Process...", "info");
// แสดง loading animation แบบพิเศษสำหรับ build process
const buildStatusDiv = document.createElement("div");
buildStatusDiv.id = "build-status";
buildStatusDiv.style.cssText = `
background: linear-gradient(135deg, #fd7e14, #e76500);
color: white;
padding: 15px;
margin: 10px 0;
border-radius: 8px;
border-left: 4px solid #fff;
animation: pulse 4s infinite ease-in-out;
`;
buildStatusDiv.innerHTML = `
<div style="display: flex; align-items: center; justify-content: center;">
<div style="
width: 20px;
height: 20px;
border: 3px solid rgba(255,255,255,0.3);
border-top: 3px solid white;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-right: 10px;
"></div>
<span>Building application...</span>
</div>
`;
try {
const result = await window.electronAPI.startBuild();
if (!result.success) {
addTerminalLine(
`ERROR: Unable to start build: ${result.error}`,
"error"
);
showNotification("ERROR: Unable to start build", "error");
// ลบ build status
buildStatusDiv.remove();
} else {
addTerminalLine("SUCCESS: Build process started successfully!", "success");
// เปลี่ยน build status เป็น running
buildStatusDiv.innerHTML = `
<div style="display: flex; align-items: center; justify-content: center;">
<div style="
width: 20px;
height: 20px;
border: 3px solid rgba(255,255,255,0.3);
border-top: 3px solid white;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-right: 10px;
"></div>
<span> Building in progress... (check logs below)</span>
</div>
`;
}
} catch (error) {
addTerminalLine(
`ERROR: Critical error: ${error.message}`,
"error"
);
showNotification("ERROR: Critical error", "error");
// ลบ build status
buildStatusDiv.remove();
}
}
// ======================================================================
// // ฟังก์ชันจัดการเมื่อ Build เสร็จสิ้น
// ======================================================================
function onBuildComplete(success) {
const buildStatusDiv = document.getElementById("build-status");
if (buildStatusDiv) {
if (success) {
buildStatusDiv.style.background =
"linear-gradient(135deg, #28a745, #1e7e34)";
buildStatusDiv.innerHTML = `
<div style="display: flex; align-items: center; justify-content: center;">
<span style="font-size: 1.2em; margin-right: 10px;">SUCCESS</span>
<span> Build complete! Check files in dist/ folder</span>
</div>
`;
showNotification(
" Build successful! MSI/EXE files ready",
"success"
);
} else {
buildStatusDiv.style.background =
"linear-gradient(135deg, #dc3545, #c82333)";
buildStatusDiv.innerHTML = `
<div style="display: flex; align-items: center; justify-content: center;">
<span style="font-size: 1.2em; margin-right: 10px;">ERROR</span>
<span> Build failed! Check logs for details</span>
</div>
`;
showNotification("ERROR: Build failed!", "error");
}
// ลบ build status หลังจาก 10 วินาที
setTimeout(() => {
buildStatusDiv.remove();
}, 10000);
}
}
// ======================================================================
// ฟังก์ชัน Helper Functions ที่จำเป็น
// ======================================================================
function showLoadingAnimation(container, message = "Loading...") {
if (!container) return;
container.innerHTML = `
<div class="loading" style="
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: var(--glass-bg);
border-radius: 12px;
border: 1px solid var(--glass-border);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
">
<div style="
width: 40px;
height: 40px;
border: 3px solid var(--border-color);
border-top: 3px solid var(--accent-blue);
border-radius: 50%;
animation: spin 1s linear infinite;
margin-bottom: 15px;
"></div>
<div style="
color: var(--text-secondary);
font-size: 0.9rem;
text-align: center;
">${message}</div>
</div>
<style>
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
`;
}
// ======================================================================
// // ฟังก์ชันแสดงการแจ้งเตือน (Notification)
// ======================================================================
function showNotification(message, type = "info") {
// ลบ notification เก่าถ้ามี
const existingNotification =
document.getElementById("app-notification");
if (existingNotification) {
existingNotification.remove();
}
const notification = document.createElement("div");
notification.id = "app-notification";
let bgColor, borderColor, textColor;
switch (type) {
case "success":
bgColor = "rgba(16, 185, 129, 0.9)";
borderColor = "#10b981";
textColor = "white";
break;
case "error":
bgColor = "rgba(239, 68, 68, 0.9)";
borderColor = "#ef4444";
textColor = "white";
break;
case "warning":
bgColor = "rgba(245, 158, 11, 0.9)";
borderColor = "#f59e0b";
textColor = "white";
break;
default:
bgColor = "rgba(59, 130, 246, 0.9)";
borderColor = "#3b82f6";
textColor = "white";
}
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
z-index: 3000; /* ลดจาก 10000 เป็น 3000 - notification level */
background: ${bgColor};
color: ${textColor};
padding: 12px 20px;
border-radius: 8px;
border-left: 4px solid ${borderColor};
box-shadow: var(--shadow-xl);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
transform: translateX(100%);
transition: transform 0.3s ease;
max-width: 350px;
font-weight: 500;
`;
notification.textContent = message;
document.body.appendChild(notification);
// แสดง notification
requestAnimationFrame(() => {
notification.style.transform = "translateX(0)";
});
// ซ่อน notification หลังจาก 4 วินาที
setTimeout(() => {
notification.style.transform = "translateX(100%)";
setTimeout(() => {
if (notification.parentNode) {
notification.remove();
}
}, 300);
}, 4000);
}
// ======================================================================
// // ฟังก์ชัน createPluginButtons เวอร์ชันใหม่ที่ง่ายกว่าเดิม
// ======================================================================
function createPluginButtons(pluginData) {
let buttonsHTML = "";
if (pluginData.buttons && pluginData.buttons.length > 0) {
pluginData.buttons.forEach((buttonInfo) => {
// ไม่ต้องเปลี่ยน command เพราะเราแก้ไข button-generator.js แล้ว
buttonsHTML += `
<button
onclick="checkAuthAndExecute('runPluginAction', '${pluginData.name}', '${
buttonInfo.command
}', '${pluginData.path.replace(/\\/g, "\\\\")}')"
title="${buttonInfo.tooltip || buttonInfo.name}"
>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-3 h-3 btn-icon">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
</svg> ${buttonInfo.name}
</button>
`;
});
}
buttonsHTML += `<button onclick="checkAuthAndExecute('runPluginAction', '${
pluginData.name
}', 'info', '${pluginData.path.replace(
/\\/g,
"\\\\"
)}')" title="แสดงข้อมูล">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-3 h-3 btn-icon">
<path stroke-linecap="round" stroke-linejoin="round" d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z" />
</svg> ข้อมูล
</button>`;
return buttonsHTML || "<span>ไม่มีคำสั่งที่ใช้ได้</span>";
}
// ======================================================================
// ฟังก์ชันจัดการไอคอนสำหรับประเภทPlugin
// ======================================================================
function getIconForType(pluginData) {
// ใช้ icon จาก manifest เป็นหลัก ถ้าไม่มีก็ใช้แบบเดิม
if (pluginData.icon) {
return pluginData.icon;
}
// Fallback icons ตาม type
const icons = {
node: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M12 1v6m0 6v6"/></svg>',
python:
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2C8 2 8 4 8 4v4h8V6s0-4-4-4zM8 10v4s0 4 4 4 4-4 4-4v-4"/></svg>',
java: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"/></svg>',
api: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><path d="M16 6l-4-4-4 4"/><path d="M12 2v15"/></svg>',
html: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16,18 22,12 16,6"/><polyline points="8,6 2,12 8,18"/></svg>',
project:
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg>',
batch_project:
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 9h6m-6 4h6m-6 4h4"/></svg>',
executable_project:
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5,3 19,12 5,21"/></svg>',
electron_app:
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M6 8h.01M10 8h.01M14 8h.01"/></svg>',
utility_tool:
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg>',
chahuadev_studio:
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><polygon points="10,8 16,12 10,16"/></svg>',
html_plugin:
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16,18 22,12 16,6"/><polyline points="8,6 2,12 8,18"/></svg>',
javascript_plugin:
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 4L8.12 15.88M14.47 14.48L20 20M8.12 8.12L12 12"/></svg>',
};
return (
icons[pluginData.type] ||
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>'
);
}
// ======================================================================
// // ฟังก์ชันสำหรับรันคำสั่งPlugin - ส่ง action ไปให้ validation_gateway.js
// ======================================================================
async function runPluginAction(pluginName, action, projectPath) {
// ตรวจสอบการล็อกอินก่อนรันคำสั่งPlugin
if (!authManager || !authManager.isUserAuthenticated()) {
if (window.authDialog) {
window.authDialog.show();
} else {
alert('กรุณาล็อกอินก่อนใช้งาน');
}
return;
}
addTerminalLine(
`RUNNING: กำลังรัน Action: "${action}" บนPlugin "${pluginName}"...`,
"command"
);
try {
// เรียกใช้ Gateway โดยตรงผ่านสะพานใหม่ที่เราสร้าง
const result = await window.electronAPI.processCommand({
action: action, // ส่ง action name ที่ถูกต้องไปให้ validation_gateway.js
pluginName: pluginName,
projectPath: projectPath,
});
if (result.success) {
addTerminalLine(`SUCCESS: Action completed!`, "success");
const output =
result.data?.output || result.data?.message || result.message;
if (output) {
addTerminalLine(output, "stdout");
}
} else {
addTerminalLine(`ERROR: Action failed: ${result.error}`, "error");
}
} catch (err) {
addTerminalLine(
`ERROR: Critical error (IPC): ${err.message}`,
"error"
);
}
}
// ทำให้ onclick เรียกใช้ได้
window.runPluginAction = runPluginAction;
// ======================================================================
// // ฟังก์ชันใหม่สำหรับรันคำสั่งภายนอกผ่าน Main Process
// ======================================================================
async function runExternalCommand(command) {
try {
// เรียกใช้ API ที่เราสร้างไว้ใน preload.js
// main.js จะรับคำสั่งนี้ไปรันใน shell ของเครื่อง
const result = await window.electronAPI.executeQuickCommand(command);
if (result.success) {
// ถ้าสำเร็จ ให้นำผลลัพธ์ (output) มาแสดง
addTerminalLine(result.data.output, "stdout");
} else {
// ถ้าล้มเหลว ให้แสดงข้อผิดพลาด
addTerminalLine(result.error, "error");
}
} catch (err) {
// กรณีที่การเชื่อมต่อกับ Main Process มีปัญหา
addTerminalLine(`ERROR: IPC Error: ${err.message}`, "error");
}
}
// ======================================================================
// ฟังก์ชันรันคำสั่งผ่าน ValidationGateway
// ======================================================================
async function runGatewayCommand(
action,
loadingMessage = "กำลังดำเนินการ..."
) {
try {
addTerminalLine(loadingMessage, "command");
const result = await window.electronAPI.processCommand({
action: action,
projectPath: process.cwd ? process.cwd() : ".",
});
if (result.success) {
addTerminalLine("SUCCESS: Command executed!", "success");
if (result.data && result.data.output) {
addTerminalLine(result.data.output, "stdout");
} else if (result.data && result.data.message) {
addTerminalLine(result.data.message, "info");
}
} else {
addTerminalLine(`ERROR: Command failed: ${result.error}`, "error");
}
} catch (error) {
addTerminalLine(`ERROR: Error: ${error.message}`, "error");
}
}
// ======================================================================
// ฟังก์ชันเอฟเฟกต์ Success Animation
// ======================================================================
function addSuccessEffect(element) {
element.classList.add("success-animation");
setTimeout(() => {
element.classList.remove("success-animation");
}, 600);
}
// ======================================================================
// ฟังก์ชันเอฟเฟกต์ Ripple เมื่อคลิก
// ======================================================================
function addClickEffect(event) {
const button = event.target;
// สร้าง ripple effect
const ripple = document.createElement("span");
const rect = button.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = event.clientX - rect.left - size / 2;
const y = event.clientY - rect.top - size / 2;
ripple.style.cssText = `
position: absolute;
width: ${size}px;
height: ${size}px;
left: ${x}px;
top: ${y}px;
background: rgba(255, 255, 255, 0.6);
border-radius: 50%;
transform: scale(0);
animation: ripple 0.6s linear;
pointer-events: none;
`;
// ======================================================================
// // เพิ่ม keyframe สำหรับ ripple animation
// ======================================================================
if (!document.querySelector("#ripple-style")) {
const style = document.createElement("style");
style.id = "ripple-style";
style.textContent = `
@keyframes ripple {
to {
transform: scale(4);
opacity: 0;
}
}
`;
document.head.appendChild(style);
}
button.style.position = "relative";
button.style.overflow = "hidden";
button.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
}
// ======================================================================
// // ฟังก์ชันเพิ่มเอฟเฟกต์การพิมพ์ทีละตัวอักษร
// ======================================================================
function addTypingEffect(element, text, speed = 50) {
element.textContent = "";
element.classList.add("typing-effect");
let i = 0;
const typeWriter = () => {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(typeWriter, speed);
} else {
element.classList.remove("typing-effect");
}
};
typeWriter();
}
// ======================================================================
// // เพิ่ม event listener สำหรับปุ่มทั้งหมด
// ======================================================================
function initializeButtonEffects() {
document.addEventListener("click", (event) => {
if (event.target.tagName === "BUTTON") {
addClickEffect(event);
}
});
}
// ======================================================================
// // ฟังก์ชันสำหรับเพิ่มอนิเมชั่นแบบ Stagger (เรียงลำดับ)
// ======================================================================
function animatePluginCards() {
const cards = document.querySelectorAll(".plugin-card");
cards.forEach((card, index) => {
card.style.animationDelay = `${index * 0.1}s`;
card.classList.add("fadeIn");
});
}
// ======================================================================
// // ฟังก์ชันสำหรับ Loading Animation - with safety check
// ======================================================================
function showLoadingAnimation(element, text = "กำลังโหลด") {
// Add safety check to prevent null element error
if (!element) {
console.warn(
"WARNING: showLoadingAnimation: Element is null or undefined"
);
return;
}
element.innerHTML = `
<div class="loading-container" style="text-align: center; padding: 20px;">
<div class="loading-spinner" style="
width: 40px;
height: 40px;
border: 4px solid #e9ecef;
border-top: 4px solid #667eea;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 10px;
"></div>
<div class="loading-text">${text}</div>
</div>
`;
// ======================================================================
// // เพิ่ม keyframe สำหรับ spinner
// ======================================================================
if (!document.querySelector("#spinner-style")) {
const style = document.createElement("style");
style.id = "spinner-style";
style.textContent = `
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
`;
document.head.appendChild(style);
}
}
// ======================================================================
// // ฟังก์ชันทดแทนเพื่อป้องกันข้อผิดพลาด - ไม่แสดง notification
// ======================================================================
function showNotification(message, type = "info") {
// DISABLED: ปิดการใช้งาน notification เพื่อไม่ให้บังระบบการทำงาน
// หากต้องการเปิดใช้งานอีกครั้ง ให้ uncomment บรรทัดด้านบน
console.log(` [Notification Disabled] ${message} (${type})`);
}
// ======================================================================
// // ฟังก์ชันตรวจสอบโหมด Development Mode Detection
// ======================================================================
function isDevMode() {
// Check multiple indicators for dev mode
const urlParams = new URLSearchParams(window.location.search);
const devParam = urlParams.get("dev") === "true";
const devStorage = localStorage.getItem("chahua_dev_mode") === "true";
const isLocalhost =
window.location.hostname === "localhost" ||
window.location.hostname === "127.0.0.1" ||
window.location.hostname === "";
return devParam || devStorage || isLocalhost;
}
// ======================================================================
// // ฟังก์ชันเริ่มต้นระบบรักษาSecurityแบบ Production Security Implementation
// ======================================================================
function initProductionSecurity() {
const isDev = isDevMode();
console.log(
"[SECURITY] Security Mode:",
isDev ? "DEVELOPMENT" : "PRODUCTION"
);
if (!isDev) {
// 1. Disable Console Methods
const consoleMethods = [
"log",
"debug",
"info",
"warn",
"error",
"assert",
"dir",
"dirxml",
"group",
"groupEnd",
"time",
"timeEnd",
"count",
"trace",
"profile",
"profileEnd",
];
consoleMethods.forEach((method) => {
console[method] = function () {
// Silent in production
};
});
// 2. Block Developer Shortcuts
document.addEventListener(
"keydown",
function (e) {
// Block F12
if (e.key === "F12") {
e.preventDefault();
e.stopPropagation();
return false;
}
// Block Ctrl+Shift+I (Developer Tools)
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === "I") {
e.preventDefault();
e.stopPropagation();
return false;
}
// Block Ctrl+Shift+J (Console)
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === "J") {
e.preventDefault();
e.stopPropagation();
return false;
}
// Block Ctrl+Shift+C (Element Inspector)
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === "C") {
e.preventDefault();
e.stopPropagation();
return false;
}
// Block Ctrl+U (View Source)
if ((e.ctrlKey || e.metaKey) && e.key === "u") {
e.preventDefault();
e.stopPropagation();
return false;
}
// Block Ctrl+S (Save)
if ((e.ctrlKey || e.metaKey) && e.key === "s") {
e.preventDefault();
e.stopPropagation();
return false;
}
},
true
);
// 3. Disable Right-Click Context Menu
document.addEventListener(
"contextmenu",
function (e) {
e.preventDefault();
e.stopPropagation();
return false;
},
true
);
// 4. Disable Text Selection and Drag
document.addEventListener(
"selectstart",
function (e) {
e.preventDefault();
return false;
},
true
);
document.addEventListener(
"dragstart",
function (e) {
e.preventDefault();
return false;
},
true
);
// 5. Developer Tools Detection
let devtools = {
open: false,
orientation: null,
};
const threshold = 160;
setInterval(() => {
if (
window.outerHeight - window.innerHeight > threshold ||
window.outerWidth - window.innerWidth > threshold
) {
if (!devtools.open) {
devtools.open = true;
showDeveloperToolsWarning();
}
} else {
devtools.open = false;
hideDeveloperToolsWarning();
}
}, 500);
// Additional detection methods
let startTime = new Date();
debugger;
let endTime = new Date();
if (endTime - startTime > 100) {
showDeveloperToolsWarning();
}
}
return isDev;
}
// ======================================================================
// // ฟังก์ชันแสดงคำเตือนเมื่อเปิด Developer Tools Warning System
// ======================================================================
function showDeveloperToolsWarning() {
if (document.getElementById("dev-tools-warning")) return;
const warningOverlay = document.createElement("div");
warningOverlay.id = "dev-tools-warning";
warningOverlay.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(220, 53, 69, 0.95);
color: white;
z-index: 10000; /* แก้จาก 999999 เป็น 10000 - security overlay (สูงสุด) */
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: 'Segoe UI', sans-serif;
font-size: 24px;
text-align: center;
backdrop-filter: blur(10px);
`;
warningOverlay.innerHTML = `
<div style="max-width: 600px; padding: 40px; background: rgba(0,0,0,0.8); border-radius: 20px; border: 3px solid #dc3545;">
<h1 style="color: #ff6b6b; margin-bottom: 20px; font-size: 2.5em;">ACCESS DENIED: การเข้าถึงถูกปฏิเสธ</h1>
<p style="font-size: 1.2em; margin-bottom: 20px; line-height: 1.6;">
ระบบตรวจพบการเปิด Developer Tools<br/>
แอปพลิเคชันนี้ได้รับการป้องกันเพื่อSecurity
</p>
<div style="background: rgba(255,255,255,0.1); padding: 20px; border-radius: 10px; margin: 20px 0;">
<p style="font-size: 1em; margin: 0;">
<svg style="display: inline-block; width: 16px; height: 16px; margin-right: 8px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
<circle cx="12" cy="16" r="1"/>
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
</svg>
Production Mode Active<br/>
SECURITY: Security Features Enabled<br/>
<svg style="display: inline-block; width: 16px; height: 16px; margin-right: 8px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
<circle cx="9" cy="7" r="4"/>
<path d="M23 21v-2a4 4 0 0 0-3-3.87"/>
<path d="M16 3.13a4 4 0 0 1 0 7.75"/>
</svg>
For End Users Only
</p>
</div>
<p style="font-size: 0.9em; color: #ffcccb;">
กรุณาปิด Developer Tools เพื่อใช้งานต่อ<br/>
หากคุณเป็นนักพัฒนา ให้เพิ่ม ?dev=true ใน URL
</p>
</div>
`;
document.body.appendChild(warningOverlay);
}
// ======================================================================
// // ฟังก์ชันซ่อนคำเตือน Developer Tools Warning Removal System
// ======================================================================
function hideDeveloperToolsWarning() {
const warning = document.getElementById("dev-tools-warning");
if (warning) {
warning.remove();
}
}
/* ╔══════════════════════════════════════════════════════════════════════════════════╗ */
/* ║ JAVASCRIPT ZONE 33: DEVELOPMENT TOOLS ║ */
/* ║ Development และ Debugging Functions ║ */
/* ║ [USAGE] ใช้แยก: Development Mode Functions เท่านั้น ║ */
/* ╚══════════════════════════════════════════════════════════════════════════════════╝ */
// ======================================================================
// /ฟังก์ชัน Enhanced Console Logging (Only in Dev Mode)
// ======================================================================
function devLog(...args) {
if (isDevMode()) {
console.log(...args);
}
}
// ======================================================================
// //ฟังก์ชัน Console Error สำหรับ Developer Mode เท่านั้น
// ======================================================================
function devError(...args) {
if (isDevMode()) {
console.error(...args);
}
}
// ======================================================================
// ฟังก์ชัน Console Warning สำหรับ Developer Mode เท่านั้น
// ======================================================================
function devWarn(...args) {
if (isDevMode()) {
console.warn(...args);
}
}
// =============================================================
// [SECURITY] END SECURITY SYSTEM
// =============================================================
document.addEventListener("DOMContentLoaded", async () => {
console.log("[CLEANUP] Skipping localStorage cleanup - handled by webview");
// จุดที่ 1: ตั้งค่า Preload สำหรับ webview
try {
if (window.electronAPI && window.electronAPI.getPreloadWebviewPath) {
window.webviewPreloadPath = await window.electronAPI.getPreloadWebviewPath();
console.log("[WEBVIEW] Preload path initialized:", window.webviewPreloadPath);
}
} catch (error) {
console.warn("[WEBVIEW] Failed to get preload path:", error);
}
// Setup token injection to webviews
if (window.electronAPI && window.electronAPI.onMessage) {
window.electronAPI.onMessage('auth:inject-to-webviews', (tokens) => {
console.log("[AUTH] Received tokens to inject to webviews:", tokens);
// Inject to store webview
const storeWebview = document.getElementById('store-webview');
if (storeWebview) {
storeWebview.send('auth:inject-tokens', tokens);
console.log("[AUTH] Tokens sent to store webview");
}
// Inject to marketplace webview
const marketplaceWebview = document.getElementById('marketplace-webview');
if (marketplaceWebview) {
marketplaceWebview.send('auth:inject-tokens', tokens);
console.log("[AUTH] Tokens sent to marketplace webview");
}
});
}
// Initialize Security System First
const isDev = initProductionSecurity();
// ประกาศตัวแปร isDev ใน scope ที่เข้าถึงได้
window.isDev = isDev;
addTerminalLine("Initializing system...", "info");
if (isDev) {
addTerminalLine(
"DEV MODE: Developer Mode: Security features disabled for development",
"warning"
);
document.body.classList.add("dev-mode");
} else {
addTerminalLine(
"[SECURE] Production Mode: Security features active",
"success"
);
document.body.classList.remove("dev-mode");
}
if (window.electronAPI) {
addTerminalLine(
"Script loaded successfully. Connected to main system.",
"success"
);
// Check operation mode (developer vs customer)
try {
const runMode = await window.electronAPI.getRunMode();
if (runMode.isDevMode) {
console.log("Running in Developer Mode - developer features enabled");
addTerminalLine(
"Developer Mode: Special developer tools enabled",
"success"
);
window.isDev = true; // Set isDev to true
document.body.classList.add("dev-mode");
showNotification(
"Developer Mode: Special tools available",
"info"
);
} else {
console.log("Running in Customer Mode - user features only");
addTerminalLine(
"Customer Mode: Only features for regular users",
"info"
);
document.body.classList.remove("dev-mode");
showNotification("Customer Version - Ready to use!", "success");
}
} catch (error) {
console.error("Unable to check operation mode:", error);
addTerminalLine(
"Unable to check operation mode - Using normal mode",
"warning"
);
// Default: if can't check, use customer mode (more secure)
document.body.classList.remove("dev-mode");
}
initializeButtonEffects();
// เพิ่มข้อความต้อนรับใน Log Viewer
addTerminalLine(
"===== Chahua Plugin Management System =====",
"success"
);
addTerminalLine("Plugin Management System - Log Viewer Mode", "info");
addTerminalLine("System messages and button actions will be displayed here", "info");
addTerminalLine("", "info");
setTimeout(() => {
scanAndRenderPlugins();
}, 1000);
// เพิ่ม: เฝ้าฟัง Log จากกระบวนการ Build แบบ Real-time
window.electronAPI.onBuildLog((log) => {
// ตรวจสอบว่าเป็น Error Log หรือไม่
if (log.includes("[ERROR]")) {
addTerminalLine(log.replace("[ERROR] ", ""), "error");
} else if (log.includes("SUCCESS") || log.includes("")) {
addTerminalLine(log, "success");
// เรียกฟังก์ชันเมื่อ Build สำเร็จ
if (log.includes("Build เสร็จสมบูรณ์")) {
onBuildComplete(true);
}
} else if (log.includes("ERROR") || log.includes("")) {
addTerminalLine(log, "error");
// เรียกฟังก์ชันเมื่อ Build ล้มเหลว
if (log.includes("Build ล้มเหลว")) {
onBuildComplete(false);
}
} else {
// Log ปกติ
addTerminalLine(log, "stdout");
}
});
// เพิ่ม: เฝ้าฟัง Enhanced Scan Complete จาก Menu
if (window.electronAPI && window.electronAPI.onEnhancedScanComplete) {
window.electronAPI.onEnhancedScanComplete((result) => {
console.log(" Enhanced scan complete from menu:", result);
if (result.success) {
addTerminalLine(
" Enhanced scan completed via keyboard shortcut",
"success"
);
// อัปเดตDisplayPlugin
scanAndRenderPluginsWithDebug();
} else {
addTerminalLine(
`ERROR: Enhanced scan failed: ${result.error}`,
"error"
);
}
});
}
// แสดง welcome notification
setTimeout(() => {
showNotification(
"ยินดีต้อนรับสู่ระบบจัดการPlugin Chahuadev!",
"success"
);
}, 2000);
// INIT: Initialize resize panel system
window.resizeController = new ResizePanelController();
// SYSTEM: System Check Button Event Listener
const systemCheckBtn = document.getElementById("runSystemCheckBtn");
if (systemCheckBtn) {
systemCheckBtn.addEventListener("click", async () => {
const scope = document.getElementById("diagnosticScope").value;
const selectedPlugins =
scope === "specific" ? getSelectedPlugins() : [];
addTerminalLine(
`→ กำลังเริ่มการวินิจฉัย (${getDiagnosticScopeText(scope)})...`,
"info"
);
try {
const result =
await window.electronAPI.runParameterizedSystemCheck({
scope: scope,
plugins: selectedPlugins,
});
if (result.success) {
addTerminalLine("SUCCESS: Diagnosis complete", "success");
if (result.message) {
addTerminalLine(result.message, "info");
}
if (result.fixed) {
addTerminalLine(
"TOOL: System has been repaired successfully",
"success"
);
}
if (
result.recommendations &&
result.recommendations.length > 0
) {
addTerminalLine(
`TIPS: คำแนะนำ: ${result.recommendations.join(", ")}`,
"info"
);
}
} else {
addTerminalLine(
`ERROR: Diagnosis failed: ${result.error}`,
"error"
);
}
} catch (error) {
addTerminalLine(
`ERROR: Unable to start diagnosis: ${error.message}`,
"error"
);
}
});
}
addTerminalLine(
"Enhanced Webview Bridge System initialized successfully",
"success"
);
} else {
addTerminalLine(
"Critical Error: Script loader not found (electronAPI)!",
"error"
);
}
});
// ======================================================================
//ฟังก์ชันเริ่มต้นระบบ DIAGNOSTIC: Parameterized Diagnostics Functions
// ======================================================================
function initParameterizedDiagnostics() {
const diagnosticScope = document.getElementById("diagnosticScope");
const specificPluginSelector = document.getElementById(
"specificPluginSelector"
);
if (diagnosticScope) {
diagnosticScope.addEventListener("change", function () {
if (this.value === "specific") {
specificPluginSelector.style.display = "block";
loadAvailablePlugins();
} else {
specificPluginSelector.style.display = "none";
}
// อัปเดตข้อความปุ่ม
updateDiagnosticButtonText(this.value);
});
}
}
// ======================================================================
// ฟังก์ชันโหลดPluginที่มีให้ใช้งาน (สำหรับการวินิจฉัยแบบเจาะจง)
// ======================================================================
async function loadAvailablePlugins() {
const pluginList = document.getElementById("pluginList");
if (!pluginList) return;
try {
// ดึงรายชื่อPluginที่ตรวจพบ
const result = await window.electronAPI.getAvailablePlugins();
if (result.success) {
pluginList.innerHTML = "";
result.plugins.forEach((plugin) => {
const option = document.createElement("option");
option.value = plugin.path;
option.textContent = `${plugin.name} (${plugin.type})`;
pluginList.appendChild(option);
});
if (result.plugins.length === 0) {
const option = document.createElement("option");
option.textContent = "No plugins found";
option.disabled = true;
pluginList.appendChild(option);
}
} else {
pluginList.innerHTML =
"<option disabled>ไม่สามารถโหลดรายชื่อPluginได้</option>";
}
} catch (error) {
console.error("Error loading plugins:", error);
pluginList.innerHTML =
"<option disabled>เกิดข้อผิดพลาดในการโหลด</option>";
}
}
// ======================================================================
// ฟังก์ชันดึงPluginที่ถูกเลือก (สำหรับการวินิจฉัยแบบเจาะจง)
// ======================================================================
function getSelectedPlugins() {
const pluginList = document.getElementById("pluginList");
if (!pluginList) return [];
const selected = [];
for (let option of pluginList.selectedOptions) {
selected.push(option.value);
}
return selected;
}
// ======================================================================
// ฟังก์ชันแปลง Diagnostic Scope เป็นข้อความไทย
// ======================================================================
function getDiagnosticScopeText(scope) {
const scopeTexts = {
all: "ทั้งระบบ",
plugins: "Pluginทั้งหมด",
core: "ระบบหลัก",
dependencies: "Dependencies",
specific: "Pluginที่เลือก",
};
return scopeTexts[scope] || "Not specified";
}
// ======================================================================
// ฟังก์ชันอัปเดตข้อความปุ่ม Diagnostic ตาม Scope
// ======================================================================
function updateDiagnosticButtonText(scope) {
const button = document.getElementById("runSystemCheckBtn");
if (!button) return;
const icon =
'<svg style="width: 16px; height: 16px; display: inline-block; margin-right: 8px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><circle cx="12" cy="16" r="1"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>';
const texts = {
all: `${icon} วินิจฉัยทั้งระบบ`,
plugins: `${icon} วินิจฉัยPlugin`,
core: `${icon} วินิจฉัยระบบหลัก`,
dependencies: `${icon} วินิจฉัย Dependencies`,
specific: `${icon} วินิจฉัยPluginที่เลือก`,
};
button.innerHTML = texts[scope] || `${icon} Start Diagnosis`;
}
// คลาสควบคุมระบบ [LAYOUT] Resize Panel System
class ResizePanelController {
constructor() {
this.isResizing = false;
this.startX = 0;
this.startWidth = 0;
this.sidebar = null;
this.container = null;
this.resizeHandle = null;
this.init();
}
init() {
this.terminalSection = document.querySelector(".terminal-section");
this.container = document.querySelector(".container");
this.resizeHandle = document.getElementById("resizeHandle");
if (!this.terminalSection || !this.container || !this.resizeHandle) {
console.error("ERROR: Resize elements not found");
return;
}
this.initializeResizePanel();
console.log("Resize panel system initialized");
}
initializeResizePanel() {
// ทำการ bind ฟังก์ชันเก็บไว้ในตัวแปร
this.boundHandleResize = this.handleResize.bind(this);
this.boundStopResize = this.stopResize.bind(this);
// เพิ่ม emergency cleanup function
this.emergencyCleanup = () => {
console.log(" Emergency cleanup triggered!");
this.stopResize();
};
// เพิ่ม bound function สำหรับ keydown event
this.boundKeydownHandler = (event) => {
if (event.key === "Escape") {
console.log(" Escape key pressed, stopping resize");
this.emergencyCleanup();
}
};
// เมื่อกดเมาส์ลงบนตัวลาก
this.resizeHandle.addEventListener("mousedown", (e) => {
// ป้องกันการทำงานเริ่มต้นของ browser
e.preventDefault();
e.stopPropagation();
console.log("RESIZE: Mouse down on resize handle");
// เพิ่ม event listener ที่ document เพื่อให้ลากได้ทั่วจอ
document.addEventListener("mousemove", this.boundHandleResize);
document.addEventListener("mouseup", this.boundStopResize);
// เพิ่ม emergency cleanup listeners
document.addEventListener("mouseleave", this.emergencyCleanup);
window.addEventListener("blur", this.emergencyCleanup);
document.addEventListener("keydown", this.boundKeydownHandler);
// --- เริ่มกระบวนการ Resize ---
this.isResizing = true;
this.startX = e.clientX;
// อ่านค่าความกว้างเริ่มต้นจาก element โดยตรง
this.startWidth = this.terminalSection.offsetWidth;
// เพิ่มคลาสเพื่อแสดงผลและปิด pointer-events
this.container.classList.add("resizing");
this.resizeHandle.classList.add("resizing");
// เพิ่ม timeout fallback - หากไม่มีการปล่อยเมาส์ภายใน 10 วินาที
this.resizeTimeout = setTimeout(() => {
console.log(" Resize timeout - forcing cleanup");
this.emergencyCleanup();
}, 10000);
});
}
startResize(e) {
e.preventDefault();
e.stopPropagation();
console.log("RESIZE: Starting resize");
// Add global event listeners
document.addEventListener("mousemove", this.boundHandleResize);
document.addEventListener("mouseup", this.boundStopResize);
document.addEventListener("mouseleave", this.boundEmergencyCleanup);
window.addEventListener("blur", this.boundEmergencyCleanup);
// Set initial values
this.isResizing = true;
this.startX = e.clientX;
this.startWidth = this.sidebar.offsetWidth;
// Add visual feedback
this.container.classList.add("resizing");
this.resizeHandle.classList.add("resizing");
// Safety timeout
this.resizeTimeout = setTimeout(() => {
console.log(" Resize timeout - forcing cleanup");
this.emergencyCleanup();
}, 10000);
}
handleResize(e) {
// ถ้าไม่ได้อยู่ในโหมด resizing ก็ไม่ต้องทำอะไร
if (!this.isResizing) return;
e.preventDefault();
// คำนวณความกว้างใหม่
const newWidth = this.startWidth + (e.clientX - this.startX);
// กำหนดขอบเขตความกว้าง
const minWidth = 400;
const maxWidth = this.container.offsetWidth * 0.75;
// ปรับความกว้างของ terminalSection โดยไม่ให้เกินขอบเขต
if (newWidth >= minWidth && newWidth <= maxWidth) {
this.terminalSection.style.width = newWidth + "px";
}
}
stopResize() {
console.log(
" stopResize() called, current isResizing:",
this.isResizing
);
// --- การันตีว่าส่วนนี้จะทำงานเสมอ ไม่ว่าจะเกิดอะไรขึ้น ---
try {
// ถ้าไม่ได้อยู่ในโหมด resizing แต่ยังมีคลาส resizing ติดอยู่ ให้ลบออก
if (
!this.isResizing &&
this.container.classList.contains("resizing")
) {
console.log(" Found orphaned resizing class, cleaning up...");
}
// แสดง notification เมื่อ resize สำเร็จ
if (this.isResizing && window.showNotification) {
const currentWidth = this.terminalSection.offsetWidth;
window.showNotification(
` ปรับขนาด Terminal เป็น ${currentWidth}px`,
"success"
);
}
} catch (error) {
console.error("Error during resize:", error);
} finally {
// --- การันตีว่าส่วนนี้จะทำงานเสมอ ไม่ว่าจะเกิด Error หรือไม่ ---
console.log(" Finally block: Cleaning up resize state...");
this.isResizing = false;
// นำคลาสที่บล็อกการทำงานออก (บังคับลบ)
this.container.classList.remove("resizing");
this.resizeHandle.classList.remove("resizing");
// ลบ event listener ที่ไม่ต้องการแล้วออกจาก document (บังคับลบ)
document.removeEventListener("mousemove", this.boundHandleResize);
document.removeEventListener("mouseup", this.boundStopResize);
// ลบ emergency cleanup listeners
document.removeEventListener("mouseleave", this.emergencyCleanup);
window.removeEventListener("blur", this.emergencyCleanup);
document.removeEventListener("keydown", this.boundKeydownHandler);
// Clear timeout
if (this.resizeTimeout) {
clearTimeout(this.resizeTimeout);
this.resizeTimeout = null;
}
console.log(
"SUCCESS: Resizing stopped and ALL listeners cleaned up."
);
}
}
}
// Initialize resize controller
window.resizeController = null;
// ======================================================================
// // THEME: Theme Dropdown Functions
// ======================================================================
function initializeThemeDropdown() {
const themeDropdown = document.getElementById("themeDropdown");
if (themeDropdown) {
const toggleBtn = themeDropdown.querySelector(".dropdown-toggle");
const menu = themeDropdown.querySelector(".dropdown-menu");
toggleBtn.addEventListener("click", (event) => {
event.stopPropagation();
menu.classList.toggle("show");
});
// Close dropdown when clicking outside
window.addEventListener("click", (event) => {
if (themeDropdown && !themeDropdown.contains(event.target)) {
menu.classList.remove("show");
}
});
// Close dropdown when theme is selected
const themeItems = menu.querySelectorAll(".dropdown-item");
themeItems.forEach((item) => {
item.addEventListener("click", () => {
menu.classList.remove("show");
});
});
}
console.log("SUCCESS: Theme dropdown initialized");
}
// ทำความสะอาด Event Listeners เมื่อปิดหน้าต่าง
window.addEventListener("beforeunload", () => {
if (window.electronAPI && window.electronAPI.removeBuildLogListeners) {
window.electronAPI.removeBuildLogListeners();
}
});
// ======================================================================
// [BRIDGE] WEBVIEW IPC BRIDGE - สะพานเชื่อม Webview กับแอป
// ======================================================================
const storeWebview = document.getElementById('store-webview');
if (storeWebview) {
// ดักฟังข้อความทั้งหมดที่ถูกส่งมาจาก preload-webview.js
storeWebview.addEventListener('ipc-message', (event) => {
const { channel, args } = event;
const data = args[0]; // ข้อมูลที่ส่งมา
console.log(`[HOST APP] Received message from webview via '${channel}'`, data);
// --- Routing Table: ตรวจสอบว่า webview ต้องการทำอะไร ---
// เพิ่ม action อื่นๆ ที่ต้องการได้ที่นี่
});
}
// ==========================================================
</script>
<script>
// ======================================================================
// // ฟังก์ชันสลับมุมมองระหว่าง Log Viewer กับ Marketplace Webview
// ======================================================================
document.addEventListener("DOMContentLoaded", () => {
const logPanel = document.getElementById("log-viewer");
const marketplacePanel = document.getElementById("marketplace-webview");
// URL ของร้านค้าเป็นไฟล์ store.html ในเครื่อง
const marketplaceUrl = "./store.html"; // <-- ใช้ไฟล์ store.html ภายในเครื่อง
let isMarketplaceLoaded = false;
// ======================================================================
// ฟังก์ชันสลับ View ระหว่าง Panel ต่างๆ
// ======================================================================
function switchView(viewToShow) {
console.log(`[VIEW] switchView(${viewToShow}) called`);
// ซ่อน Panel ทั้งหมดและเอา active class ออกจากปุ่ม
document
.querySelectorAll(".view-panel")
.forEach((p) => p.classList.remove("active"));
document
.querySelectorAll(".view-btn")
.forEach((b) => b.classList.remove("active"));
// ซ่อนระบบทั้งหมดก่อน
const originalSystem = document.getElementById("original-system");
const storeContainer = document.getElementById("store-container");
const refreshStoreBtn = document.getElementById("refresh-store-btn");
if (originalSystem) originalSystem.style.display = "none";
if (storeContainer) storeContainer.style.display = "none";
if (refreshStoreBtn) refreshStoreBtn.style.display = "none";
// แสดง Panel และปุ่มที่เลือก
if (viewToShow === "log") {
console.log("LOGS: Showing log panel");
if (logPanel) logPanel.classList.add("active");
if (originalSystem) originalSystem.style.display = "flex";
document.getElementById("nav-plugins")?.classList.add("active");
} else if (viewToShow === "marketplace-new") {
console.log("[STORE] Showing Store Webview System");
if (storeContainer) storeContainer.style.display = "block";
if (refreshStoreBtn) refreshStoreBtn.style.display = "block";
document.getElementById("nav-store-new")?.classList.add("active");
// Initialize webview for new store system
initializeStoreWebview();
}
}
// Native Store Helper Class (คล้ายกับ PluginsAPIHelper)
class NativeStoreHelper {
constructor() {
console.log(" NativeStoreHelper initialized for Desktop App");
this.plugins = [];
this.isLoading = false;
}
// PLUGINS: โหลดปลั่กอินจาก Desktop API
async loadPluginsFromAPI() {
try {
console.log("[PLUGIN] Loading plugins from store API...");
this.isLoading = true;
const result = await window.electronAPI.store.getPlugins();
if (result.success && result.plugins) {
console.log(
`[SUCCESS] Loaded ${result.plugins.length} plugins from store`
);
// แปลงข้อมูลให้เหมาะกับ frontend (เหมือน plugins-api-helper.js)
this.plugins = result.plugins.map((plugin) => {
return {
id: plugin.id,
title: plugin.name || plugin.title,
name: plugin.name || plugin.title,
category: plugin.category || "general",
description: plugin.description || "ไม่มีคำอธิบาย",
features: this.parseFeatures(plugin.features),
price: parseFloat(plugin.price || 0),
isFree: parseFloat(plugin.price || 0) === 0,
popularity: this.calculatePopularity(plugin),
image:
plugin.imagePath ||
plugin.image_path ||
plugin.image ||
this.getDefaultPluginImage(),
imagePath:
plugin.imagePath ||
plugin.image_path ||
plugin.image ||
this.getDefaultPluginImage(),
version: plugin.version || "1.0.0",
downloadCount: parseInt(
plugin.downloadCount || plugin.download_count || 0
),
downloadUrl: plugin.filePath || plugin.file_path || null,
isComingSoon:
plugin.status === "draft" ||
plugin.status === "coming_soon",
slug: plugin.slug,
avgRating: parseFloat(
plugin.avgRating || plugin.avg_rating || 0
),
reviewCount: parseInt(
plugin.reviewCount || plugin.review_count || 0
),
verifiedReviewCount: parseInt(
plugin.verifiedReviewCount ||
plugin.verified_review_count ||
0
),
uploadedBy: plugin.uploaded_by_username || "Admin",
createdAt: plugin.created_at,
updatedAt: plugin.updated_at,
};
});
this.isLoading = false;
return this.plugins;
} else {
throw new Error(
result.error || "Unable to load plugin data"
);
}
} catch (error) {
this.isLoading = false;
console.error("[ERROR] Failed to load plugins:", error);
throw error;
}
}
// [PARSE] แปลง features string เป็น array (เหมือน plugins-api-helper.js)
parseFeatures(features) {
if (!features) return [];
if (Array.isArray(features)) return features;
if (typeof features === "string") {
try {
// ลองแปลงเป็น JSON ก่อน
return JSON.parse(features);
} catch {
// ถ้าไม่ใช่ JSON ให้แยกด้วย comma
return features
.split(",")
.map((f) => f.trim())
.filter((f) => f);
}
}
return [];
}
// Calculate popularity (same as plugins-api-helper.js)
calculatePopularity(plugin) {
const downloads = parseInt(
plugin.downloadCount || plugin.download_count || 0
);
const rating = parseFloat(
plugin.avgRating || plugin.avg_rating || 0
);
const reviews = parseInt(
plugin.reviewCount || plugin.review_count || 0
);
// สูตรคำนวณความนิยม: (downloads * 0.4) + (rating * 20 * 0.3) + (reviews * 5 * 0.3)
const popularity =
downloads * 0.4 + rating * 20 * 0.3 + reviews * 5 * 0.3;
return Math.round(popularity);
}
// [IMAGE] รูปภาพเริ่มต้น (เหมือน plugins-api-helper.js)
getDefaultPluginImage() {
return 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect width="100" height="100" fill="%23334155"/><rect x="30" y="30" width="40" height="40" rx="4" fill="none" stroke="%23cbd5e1" stroke-width="2"/><circle cx="40" cy="40" r="2" fill="%23cbd5e1"/><circle cx="60" cy="60" r="2" fill="%23cbd5e1"/><path d="M40 40L60 60" stroke="%23cbd5e1" stroke-width="2"/></svg>';
}
// Create star rating HTML (same as plugins-api-helper.js)
generateStarRating(rating, reviewCount = 0) {
const fullStars = Math.floor(rating);
const hasHalfStar = rating % 1 >= 0.5;
const emptyStars = 5 - fullStars - (hasHalfStar ? 1 : 0);
const stars = [];
// Full stars
for (let i = 0; i < fullStars; i++) {
stars.push('<span class="star full">★</span>');
}
// Half star
if (hasHalfStar) {
stars.push('<span class="star half">☆</span>');
}
// Empty stars
for (let i = 0; i < emptyStars; i++) {
stars.push('<span class="star empty">☆</span>');
}
return `
<div class="plugin-rating" title="${rating.toFixed(
1
)} จาก 5 ดาว (${reviewCount} รีวิว)">
${stars.join("")}
<span class="rating-text">${rating.toFixed(
1
)} (${reviewCount})</span>
</div>
`;
}
}
// สร้าง instance ของ NativeStoreHelper
const nativeStoreHelper = new NativeStoreHelper();
// ╔══════════════════════════════════════════════════════════════════════════════════╗
// ║ NATIVE STORE SYSTEM ║
// ║ ระบบร้านปลั่กอินแบบ Native ║
// ║ Source: /chahua-web-store/public/index.html ║
// ╚══════════════════════════════════════════════════════════════════════════════════╝
// ======================================================================
// ฟังก์ชันเริ่มต้นระบบ Store Webview
// ======================================================================
function initializeStoreWebview() {
try {
console.log("Initializing Store Webview System...");
// ใช้ ID แทน class เพื่อความแน่นอน
const storeContainer = document.getElementById("store-container");
const webview = document.getElementById("store-webview");
if (!storeContainer || !webview) {
console.error(
"[ERROR] Store container or webview element not found"
);
addTerminalLine("[ERROR] Webview element not found", "error");
return;
}
// ตรวจสอบว่าโหลดแล้วหรือยัง
if (webview.src && webview.src !== "about:blank") {
console.log("[SUCCESS] Store webview already loaded");
return;
}
// URL ของร้านค้า - ปรับแต่งตาม server จริงของคุณ
let storeUrl = "https://chahuadev.com/index.html"; // ลบ ?view=app เพราะเราไม่ซ่อนแล้ว
console.log(" Loading store, letting webview handle");
console.log(`Loading store from: ${storeUrl}`);
webview.src = storeUrl;
// Event listeners for webview
webview.addEventListener("dom-ready", () => {
console.log("[SUCCESS] Store webview loaded successfully");
addTerminalLine("[SUCCESS] Store page loaded successfully", "success");
});
// ดักฟัง event ชื่อ 'ipc-message' ที่ถูกส่งมาจาก preload-webview.js
webview.addEventListener('ipc-message', (event) => {
const { channel, args } = event;
const data = args[0]; // ข้อมูลที่ส่งมาจะอยู่ใน args[0]
console.log(`[APP] Received message from webview on channel "${channel}"`, data);
// กรอง Channel ที่เราสนใจ
if (channel === 'install-plugin-request' && data && data.pluginId) {
addTerminalLine(`[STORE] Received install command for Plugin ID: ${data.pluginId} from web store`, 'command');
// ส่งคำสั่งต่อไปยัง main.js ผ่าน API ของแอปเอง
if (window.electronAPI && window.electronAPI.executeCommand) {
window.electronAPI.executeCommand('install-plugin', data.pluginId)
.then(result => {
if (result.success) {
addTerminalLine(`[SUCCESS] Plugin installed successfully! Path: ${result.installPath}`, 'success');
showNotification('Plugin installed successfully!', 'success');
// สั่งให้สแกนPluginใหม่เพื่ออัปเดต UI
scanAndRenderPlugins();
} else {
addTerminalLine(`[ERROR] Installation failed: ${result.error}`, 'error');
showNotification(`Installation failed: ${result.error}`, 'error');
}
})
.catch(error => {
addTerminalLine(`[ERROR] Error: ${error.message}`, 'error');
showNotification(`Error: ${error.message}`, 'error');
});
}
}
});
webview.addEventListener("did-fail-load", (event) => {
console.error("Store webview failed to load:", event);
console.error("[ERROR] Store webview failed to load:", event);
addTerminalLine(
"[ERROR] Unable to load store page. Please check your internet connection",
"error"
);
// แสดงข้อความ error ใน webview
webview.src = `data:text/html,
<div style="padding: 2rem; text-align: center; color: #e74c3c; font-family: Arial;">
<h2>[ERROR] Unable to load store</h2>
<p>กรุณาตรวจสอบการเชื่อมต่ออินเทอร์เน็ต</p>
<button onclick="location.reload()">ลองใหม่</button>
</div>
`;
});
// Event listener สำหรับการ navigate (จะใช้สำหรับดักจับการซื้อPlugin)
webview.addEventListener("will-navigate", (event) => {
console.log(" Webview navigating to:", event.url);
handleWebviewNavigation(event);
});
addTerminalLine(" Initializing web store system", "info");
} catch (error) {
console.error("[ERROR] Failed to initialize store webview:", error);
addTerminalLine(
`[ERROR] Error: ${error.message}`,
"error"
);
}
}
// ======================================================================
// ฟังก์ชันรีเฟรช Store Webview
// ======================================================================
function refreshStoreWebview() {
try {
const webview = document.getElementById("store-webview");
if (webview) {
console.log("[REFRESH] Refreshing store webview...");
addTerminalLine("[REFRESH] Refreshing store page...", "info");
webview.reload();
}
} catch (error) {
console.error("[ERROR] Failed to refresh webview:", error);
addTerminalLine(
`[ERROR] Unable to refresh: ${error.message}`,
"error"
);
}
}
// เพิ่มฟังก์ชันในขอบเขต global เพื่อให้เรียกจากปุ่มได้
window.refreshStoreWebview = refreshStoreWebview;
// ======================================================================
// ฟังก์ชันจัดการการ Navigate ของ Webview
// ======================================================================
function handleWebviewNavigation(event) {
try {
const url = new URL(event.url);
// ดักจับการชำระเงินสำเร็จ
if (
url.href.includes("chahua-dashboard/dashboard.html") ||
url.href.includes("payment-success")
) {
event.preventDefault();
console.log("[SUCCESS] Payment successful detected!");
addTerminalLine(
"[SUCCESS] Payment successful! Updating Plugin...",
"success"
);
// รีเฟรชหน้าร้านค้าหลังจากชำระเงินสำเร็จ
setTimeout(() => {
const webview = document.getElementById("store-webview");
if (webview) {
webview.reload();
}
}, 2000);
}
} catch (error) {
console.error("[ERROR] Error handling webview navigation:", error);
}
}
// ┌─────────────────────────────────────────────────────────────────────────────────┐
// │ [NAV] NAVIGATION SYSTEM - ระบบจัดการการสลับหน้าและปุ่มล็อกอิน │
// │ Navigation Control System - การจัดการระบบนำทางและปุ่มต่าง ๆ │
// │ [NO EMOJIS] Professional Navigation Zone - ห้ามใช้อิโมจิ │
// └─────────────────────────────────────────────────────────────────────────────────┘
// ======================================================================
// // [ADD] ระบบควบคุมการสลับหน้าระหว่าง "Pluginของฉัน" และ "ร้านPlugin"
// ======================================================================
document.addEventListener("DOMContentLoaded", async () => {
console.log("[NAVIGATION] Initializing Navigation System...");
// [เพิ่มใหม่] ตั้งค่า Preload สำหรับ Webview แบบไดนามิก
try {
const storeWebview = document.getElementById('store-webview');
if (storeWebview) {
console.log('[APP] Dynamically setting webview preload script...');
const preloadPath = await window.electronAPI.getPreloadPath();
if (preloadPath) {
// ใช้ 'file://' protocol เพื่อให้แน่ใจว่า Path ถูกต้องเสมอ
storeWebview.preload = `file://${preloadPath}`;
console.log(`[APP] Webview preload set to: ${storeWebview.preload}`);
} else {
console.error('[APP] Could not get preload path for webview.');
if (typeof addTerminalLine === 'function') {
addTerminalLine('ERROR: Unable to configure Webview Preload', 'error');
}
}
}
} catch (error) {
console.error('[APP] Error setting webview preload:', error);
if (typeof addTerminalLine === 'function') {
addTerminalLine(`ERROR: Webview Preload failed: ${error.message}`, 'error');
}
}
// ดึง Element ที่สำคัญทั้งหมด
const originalSystem = document.getElementById("original-system"); // หน้าPluginของฉัน
const storeContainer = document.getElementById("store-container"); // หน้าร้านPlugin
const storeWebview = document.getElementById("store-webview");
const navMyPluginsBtn = document.getElementById("nav-plugins");
const navStoreBtn = document.getElementById("nav-store-new");
const refreshStoreBtn = document.getElementById("refresh-store-btn");
// ตรวจสอบ elements ที่จำเป็น
if (
!originalSystem ||
!storeContainer ||
!navMyPluginsBtn ||
!navStoreBtn
) {
console.error("[ERROR] Required navigation elements not found");
return;
}
// ปิดร้านPluginให้แค่ DEV MODE
if (!window.isDev) {
console.log('[STORE] Store closed - Production Mode Only');
navStoreBtn.style.display = 'none';
storeContainer.style.display = 'none';
} else {
console.log('[STORE] Store opened - DEV MODE');
}
// --- ฟังก์ชันสำหรับสลับหน้า ---
// ======================================================================
// ฟังก์ชันแสดงหน้า My Plugins View
// ======================================================================
function showMyPluginsView() {
console.log("[NAVIGATION] Switching to My Plugins View");
// แสดง/ซ่อน containers
originalSystem.style.display = "flex";
storeContainer.style.display = "none";
// อัปเดตสไตล์ของปุ่ม navigation
navMyPluginsBtn.classList.add("active");
navStoreBtn.classList.remove("active");
// ซ่อนปุ่มรีเฟรชร้านค้า
if (refreshStoreBtn) refreshStoreBtn.style.display = "none";
// โหลดข้อมูลPluginของฉัน (ถ้ายังไม่มี)
if (typeof loadAndDisplayMyPlugins === "function") {
loadAndDisplayMyPlugins();
} else if (typeof runGeneratorAndRefresh === "function") {
// หรือใช้ฟังก์ชันสแกนPluginแทน
runGeneratorAndRefresh();
}
addTerminalLine("[MY_PLUGINS] Showing My Plugins", "info");
}
// ======================================================================
// ฟังก์ชันแสดงหน้า Store View
// ======================================================================
function showStoreView() {
console.log("[STORE] Switching to Store View");
// แสดง/ซ่อน containers
originalSystem.style.display = "none";
storeContainer.style.display = "block";
// อัปเดตสไตล์ของปุ่ม navigation
navMyPluginsBtn.classList.remove("active");
navStoreBtn.classList.add("active");
// แสดงปุ่มรีเฟรชร้านค้า
if (refreshStoreBtn) refreshStoreBtn.style.display = "block";
// โหลด URL ร้านค้าจาก VPS (ถ้ายังไม่เคยโหลด)
if (storeWebview) {
let storeUrl = "https://chahuadev.com/index.html";
// จุดที่ 2: ป้องกันการโหลดก่อนที่ preload จะพร้อม
const waitForPreload = async () => {
let retries = 0;
const maxRetries = 50; // รอสูงสุด 5 วินาที (50 x 100ms)
while (!window.webviewPreloadPath && retries < maxRetries) {
await new Promise(resolve => setTimeout(resolve, 100));
retries++;
}
if (window.webviewPreloadPath && storeWebview.getAttribute('preload') !== `file://${window.webviewPreloadPath}`) {
storeWebview.setAttribute('preload', `file://${window.webviewPreloadPath}`);
console.log("[WEBVIEW] Preload applied before loading store:", window.webviewPreloadPath);
}
return window.webviewPreloadPath;
};
if (storeWebview.src === "about:blank" || !storeWebview.src) {
console.log("[STORE] Loading store URL:", storeUrl);
// รอให้ preload พร้อมก่อนโหลด
waitForPreload().then(() => {
storeWebview.src = storeUrl;
}).catch(error => {
console.warn("[WEBVIEW] Preload wait failed, loading anyway:", error);
storeWebview.src = storeUrl;
});
}
}
addTerminalLine("[STORE] Showing Store page", "info");
}
// --- กำหนด Event Listeners ให้ปุ่ม ---
// ปุ่ม "Pluginของฉัน"
navMyPluginsBtn.addEventListener("click", (e) => {
e.preventDefault();
showMyPluginsView();
});
// ปุ่ม "ร้านPlugin"
navStoreBtn.addEventListener("click", (e) => {
e.preventDefault();
showStoreView();
});
// --- เปิดใช้งาน global functions ---
// ทำให้ฟังก์ชันเหล่านี้เรียกใช้จากที่อื่นได้
window.showMyPluginsView = showMyPluginsView;
window.showStoreView = showStoreView;
// --- ตั้งค่าหน้าเริ่มต้น ---
// เริ่มต้นด้วยหน้า "Pluginของฉัน"
showMyPluginsView();
console.log("[SUCCESS] Navigation system initialized successfully");
});
// เพิ่ม switchView ให้เป็น global function เพื่อให้ Top Nav ใช้ได้
window.switchView = switchView;
// ╔══════════════════════════════════════════════════════════════════════════════════╗
// ║ [NAV] PAGE NAVIGATION SYSTEM ║
// ║ ระบบสลับหน้าหลักของแอป ║
// ╚══════════════════════════════════════════════════════════════════════════════════╝
});
// ทำความสะอาด Event Listeners เมื่อปิดหน้าต่าง
window.addEventListener("beforeunload", () => {
if (window.electronAPI && window.electronAPI.removeBuildLogListeners) {
window.electronAPI.removeBuildLogListeners();
}
});
// ┌─────────────────────────────────────────────────────────────────────────────────┐
// │ [AUTH] ZONE 8: AUTHENTICATION SYSTEM - ระบบล็อกอิน และ Authentication │
// └─────────────────────────────────────────────────────────────────────────────────┘
class AuthManager {
constructor() {
this.currentUser = null;
this.isAuthenticated = false;
this.isLoading = false;
this.initializeElements();
this.setupEventListeners();
this.checkAuthStatus();
}
initializeElements() {
this.elements = {
authHeader: document.getElementById('auth-header'),
authGuest: document.getElementById('auth-guest'),
authUser: document.getElementById('auth-user'),
authLoading: document.getElementById('auth-loading'),
authLoginBtn: document.getElementById('auth-login-btn'),
authUserAvatar: document.getElementById('auth-user-avatar'),
authUserName: document.getElementById('auth-user-name'),
authUserRole: document.getElementById('auth-user-role'),
authDropdown: document.getElementById('auth-dropdown'),
authProfile: document.getElementById('auth-profile'),
authPermissions: document.getElementById('auth-permissions'),
authLogout: document.getElementById('auth-logout'),
permissionDialog: document.getElementById('permission-dialog'),
permissionAllow: document.getElementById('permission-allow'),
permissionDeny: document.getElementById('permission-deny')
};
}
setupEventListeners() {
// Login button
this.elements.authLoginBtn.addEventListener('click', () => this.startLogin());
// User info dropdown toggle
this.elements.authUser.addEventListener('click', () => this.toggleDropdown());
// Dropdown menu items
this.elements.authProfile.addEventListener('click', () => this.showProfile());
this.elements.authPermissions.addEventListener('click', () => this.showPermissions());
this.elements.authLogout.addEventListener('click', () => this.logout());
// Permission dialog
this.elements.permissionAllow.addEventListener('click', () => this.handlePermission(true));
this.elements.permissionDeny.addEventListener('click', () => this.handlePermission(false));
// Close dropdown when clicking outside
document.addEventListener('click', (e) => {
if (!this.elements.authUser.contains(e.target)) {
this.elements.authDropdown.classList.remove('show');
}
});
}
async checkAuthStatus() {
try {
this.setLoadingState(true);
console.log(' Checking login status...');
// ตรวจสอบว่า electronAPI พร้อมใช้งาน
if (!window.electronAPI || !window.electronAPI.auth) {
console.warn(' Authentication API not available');
this.setGuestState();
return;
}
// ตรวจสอบสถานะ authentication จาก main process
const result = await window.electronAPI.auth.checkStatus();
if (result.success && result.authenticated && result.user) {
console.log(' Found logged-in user:', result.user);
this.setAuthenticatedState(result.user);
} else {
console.log('ℹ No active login session:', result.error || 'No active session');
// AUTO-LOGIN: ลอง auto-login ด้วย demo credentials
await this.attemptAutoLogin();
}
} catch (error) {
console.error(' Auth check failed:', error);
this.setGuestState();
} finally {
this.setLoadingState(false);
}
}
async attemptAutoLogin() {
try {
console.log('[AUTO-LOGIN] Attempting auto-login with demo account...');
// ส่งคำขอ offline login ไปยัง main process
const result = await window.electronAPI.auth.offlineLogin('admin', 'demo123');
if (result.success && result.data) {
const user = result.data.user;
console.log('[AUTO-LOGIN] Success! User:', user.username);
this.setAuthenticatedState(user);
// แสดง demo dashboard หลังเข้าสู่ระบบ
setTimeout(() => this.showDemoDashboard(), 1500);
} else {
console.warn('[AUTO-LOGIN] Failed:', result.error);
this.setGuestState();
}
} catch (error) {
console.error('[AUTO-LOGIN] Error:', error);
this.setGuestState();
}
}
showDemoDashboard() {
try {
console.log('[DEMO-DASHBOARD] Showing dashboard...');
const existingDashboard = document.getElementById('demo-dashboard-modal');
if (existingDashboard) {
existingDashboard.remove();
}
const dashboard = document.createElement('div');
dashboard.id = 'demo-dashboard-modal';
dashboard.className = 'demo-dashboard-modal';
dashboard.innerHTML = `
<div class="demo-dashboard-container">
<div class="demo-dashboard-header">
<h2> Welcome to Chahuadev Framework!</h2>
<p>Demo Dashboard - Plugin Test Mode</p>
</div>
<div class="demo-dashboard-content">
<div class="feature-grid">
<div class="feature-card">
<h3> My Plugins</h3>
<p>Manage and control installed plugins</p>
<button onclick="document.getElementById('demo-dashboard-modal').remove();" class="feature-btn">Open</button>
</div>
<div class="feature-card">
<h3> Plugin Store</h3>
<p>Search and install new plugins</p>
<button onclick="document.getElementById('demo-dashboard-modal').remove();" class="feature-btn">Open</button>
</div>
<div class="feature-card">
<h3> Settings</h3>
<p>Customize system settings</p>
<button onclick="document.getElementById('demo-dashboard-modal').remove();" class="feature-btn">Open</button>
</div>
<div class="feature-card">
<h3> Statistics</h3>
<p>View plugin usage statistics</p>
<button onclick="document.getElementById('demo-dashboard-modal').remove();" class="feature-btn">Open</button>
</div>
</div>
</div>
<div class="demo-dashboard-footer">
<button onclick="document.getElementById('demo-dashboard-modal').remove();" class="btn-close">Close Dashboard</button>
</div>
</div>
`;
document.body.appendChild(dashboard);
// CSS สำหรับ dashboard
if (!document.getElementById('demo-dashboard-styles')) {
const styles = document.createElement('style');
styles.id = 'demo-dashboard-styles';
styles.textContent = `
.demo-dashboard-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
}
.demo-dashboard-container {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 12px;
padding: 30px;
max-width: 600px;
width: 90%;
box-shadow: 0 10px 40px rgba(0,0,0,0.3);
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from { transform: translateY(-20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.demo-dashboard-header {
color: white;
text-align: center;
margin-bottom: 30px;
border-bottom: 2px solid rgba(255,255,255,0.3);
padding-bottom: 15px;
}
.demo-dashboard-header h2 {
margin: 0;
font-size: 24px;
}
.demo-dashboard-header p {
margin: 10px 0 0 0;
opacity: 0.9;
}
.feature-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
margin-bottom: 20px;
}
.feature-card {
background: rgba(255,255,255,0.95);
padding: 15px;
border-radius: 8px;
text-align: center;
}
.feature-card h3 {
margin: 0 0 5px 0;
font-size: 14px;
}
.feature-card p {
margin: 0 0 10px 0;
font-size: 12px;
color: #666;
}
.feature-btn {
background: #667eea;
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
}
.feature-btn:hover {
background: #764ba2;
}
.demo-dashboard-footer {
text-align: center;
border-top: 2px solid rgba(255,255,255,0.3);
padding-top: 15px;
}
.btn-close {
background: rgba(255,255,255,0.2);
color: white;
border: 2px solid white;
padding: 10px 20px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
}
.btn-close:hover {
background: rgba(255,255,255,0.3);
}
`;
document.head.appendChild(styles);
}
console.log('[DEMO-DASHBOARD] Dashboard displayed successfully');
} catch (error) {
console.error('[DEMO-DASHBOARD] Error:', error);
}
}
async startLogin() {
try {
this.setLoadingState(true);
addTerminalLine("Starting login process...", "info");
addTerminalLine(" Offline Mode (Offline Demo Mode)", "warning");
addTerminalLine("Username: admin, developer, user", "info");
addTerminalLine("Password: demo123", "info");
if (!window.electronAPI || !window.electronAPI.auth) {
throw new Error('Authentication API not available');
}
// เรียก Device Flow API (จะแสดง login form)
const result = await window.electronAPI.auth.startDeviceFlow();
if (result.success && result.data) {
addTerminalLine(result.data.message || "Please enter login credentials", "info");
// แสดง offline login form
this.showOfflineLoginForm();
} else {
throw new Error(result.error || 'Unable to start login process');
}
} catch (error) {
console.error(' Login failed:', error);
addTerminalLine(` Error: ${error.message}`, "error");
this.setLoadingState(false);
}
}
/**
* แสดง Login Form แบบออฟไลน์
*/
showOfflineLoginForm() {
// สร้าง modal สำหรับ login
const existingModal = document.getElementById('offline-login-modal');
if (existingModal) {
existingModal.remove();
}
const modal = document.createElement('div');
modal.id = 'offline-login-modal';
modal.className = 'offline-login-modal';
modal.innerHTML = `
<div class="offline-login-container">
<div class="offline-login-header">
<h2> Sign In (Offline Demo)</h2>
<p>โหมดออฟไลน์ สำหรับการพัฒนา</p>
</div>
<form class="offline-login-form">
<div class="form-group">
<label for="username">ชื่อผู้ใช้:</label>
<input type="text" id="username" name="username" placeholder="admin / developer / user" required>
<small>Example: admin, developer, user</small>
</div>
<div class="form-group">
<label for="password">รหัสผ่าน:</label>
<input type="password" id="password" name="password" placeholder="demo123" value="demo123" required>
</div>
<div class="form-actions">
<button type="submit" class="btn-login">เข้าสู่ระบบ</button>
<button type="button" class="btn-cancel">ยกเลิก</button>
</div>
</form>
<div class="demo-users">
<p><strong> ผู้ใช้ทั้งหมด:</strong></p>
<ul>
<li><code>admin</code> - Administrator (Full permissions)</li>
<li><code>developer</code> - Developer (Read/Write)</li>
<li><code>user</code> - User (Read-only)</li>
</ul>
</div>
</div>
`;
document.body.appendChild(modal);
// Handle form submission
const form = modal.querySelector('.offline-login-form');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value;
await this.submitOfflineLogin(username, password);
modal.remove();
});
// Handle cancel button
const cancelBtn = modal.querySelector('.btn-cancel');
cancelBtn.addEventListener('click', () => {
modal.remove();
this.setLoadingState(false);
});
// Focus on username input
modal.querySelector('#username').focus();
}
/**
* ส่งคำขอ Offline Login
*/
async submitOfflineLogin(username, password) {
try {
addTerminalLine(` Validating: ${username}...`, "info");
const result = await window.electronAPI.auth.offlineLogin(username, password);
if (result.success && result.data) {
const user = result.data.user;
addTerminalLine("[SUCCESS] Login successful!", "success");
addTerminalLine(` Welcome: ${user.username}`, "success");
addTerminalLine(` Email: ${user.email}`, "info");
addTerminalLine(`[USER] Role: ${user.role}`, "info");
this.setAuthenticatedState(user);
this.setLoadingState(false);
} else {
throw new Error(result.error || 'Login failed');
}
} catch (error) {
console.error(' Offline login failed:', error);
addTerminalLine(` Error: ${error.message}`, "error");
this.setLoadingState(false);
}
}
async pollForAuth(deviceCode) {
try {
const result = await window.electronAPI.auth.pollDeviceAuth(deviceCode);
if (result.success && result.data) {
const { status, user, accessToken } = result.data;
if (status === 'approved' && user && accessToken) {
addTerminalLine(" Login successful!", "success");
addTerminalLine(` Welcome: ${user.username || user.name || 'User'}`, "success");
this.setAuthenticatedState(user);
this.setLoadingState(false);
return;
} else if (status === 'pending') {
// ยังรออยู่ ต่อ polling ทุก 3 วินาที
setTimeout(() => this.pollForAuth(deviceCode), 3000);
return;
} else if (status === 'denied') {
throw new Error('User denied login');
} else if (status === 'expired') {
throw new Error('Verification code expired. Please try again.');
}
}
throw new Error(result.error || 'Login failed');
} catch (error) {
console.error(' Polling failed:', error);
addTerminalLine(` Login failed: ${error.message}`, "error");
this.setLoadingState(false)
}
}
async logout() {
try {
this.setLoadingState(true);
addTerminalLine(" Logging out...", "info");
if (window.electronAPI && window.electronAPI.auth) {
const result = await window.electronAPI.auth.logout();
if (result.success) {
addTerminalLine(" Logged out", "info");
} else {
addTerminalLine(` Error: ${result.error}`, "warning");
}
}
this.setGuestState();
this.elements.authDropdown.classList.remove('show');
} catch (error) {
console.error(' Logout failed:', error);
addTerminalLine(` Logout failed: ${error.message}`, "error");
} finally {
this.setLoadingState(false);
}
}
setGuestState() {
this.isAuthenticated = false;
this.currentUser = null;
this.elements.authGuest.style.display = 'flex';
this.elements.authUser.style.display = 'none';
this.elements.authLoginBtn.style.display = 'block';
// ปิดใช้งานปุ่มที่ต้องการล็อกอิน
disableProtectedButtons();
}
setAuthenticatedState(user) {
this.isAuthenticated = true;
this.currentUser = user;
// Update user display
this.elements.authUserAvatar.textContent = user.username.charAt(0).toUpperCase();
this.elements.authUserName.textContent = user.username;
this.elements.authUserRole.textContent = user.role || 'user';
// Show/hide elements
this.elements.authGuest.style.display = 'none';
this.elements.authUser.style.display = 'flex';
this.elements.authLoginBtn.style.display = 'none';
// Enable protected features
this.enableAuthenticatedFeatures();
}
setLoadingState(loading) {
this.isLoading = loading;
if (loading) {
this.elements.authGuest.style.display = 'none';
this.elements.authUser.style.display = 'none';
this.elements.authLoading.style.display = 'flex';
this.elements.authLoginBtn.disabled = true;
} else {
this.elements.authLoading.style.display = 'none';
this.elements.authLoginBtn.disabled = false;
}
}
enableAuthenticatedFeatures() {
// Enable features that require authentication
// This will control access to plugins, store features, etc.
document.body.classList.add('authenticated');
// เปิดใช้งานปุ่มต่างๆ ที่ต้องการล็อกอิน
enableProtectedButtons();
}
toggleDropdown() {
if (!this.isAuthenticated) return;
this.elements.authDropdown.classList.toggle('show');
}
showProfile() {
// Close dropdown first
this.elements.authDropdown.classList.remove('show');
const existingProfile = document.getElementById('profile-modal');
if (existingProfile) {
existingProfile.remove();
}
const modal = document.createElement('div');
modal.id = 'profile-modal';
modal.className = 'profile-modal';
modal.innerHTML = `
<div class="profile-modal-content">
<div class="profile-header">
<div class="profile-avatar">
${this.currentUser.username.charAt(0).toUpperCase()}
</div>
<div class="profile-info">
<h2>${this.currentUser.username}</h2>
<p>${this.currentUser.role}</p>
</div>
<button onclick="document.getElementById('profile-modal').remove();" class="profile-close">✕</button>
</div>
<div class="profile-section">
<h3>General Information</h3>
<div class="profile-field">
<label>ชื่อผู้ใช้:</label>
<span>${this.currentUser.username}</span>
</div>
<div class="profile-field">
<label>อีเมล:</label>
<span>${this.currentUser.email || 'ไม่มี'}</span>
</div>
<div class="profile-field">
<label>บทบาท:</label>
<span>${this.currentUser.role}</span>
</div>
</div>
<div class="profile-section">
<h3>Permissions</h3>
<ul class="permission-list">
${this.currentUser.role === 'admin' ? `
<li>✓ Manage all Plugins</li>
<li>✓ System Configuration</li>
<li>✓ View Reports</li>
<li>✓ Manage Users</li>
` : this.currentUser.role === 'developer' ? `
<li>✓ Install Plugins</li>
<li>✓ Edit Plugins</li>
<li>✓ View Reports</li>
<li>✗ Manage Users</li>
` : `
<li>✓ View Plugins</li>
<li>✓ View Reports</li>
<li>✗ Edit Plugins</li>
<li>✗ System Configuration</li>
`}
</ul>
</div>
<div class="profile-actions">
<button onclick="document.getElementById('profile-modal').remove();" class="btn-close-profile">ปิด</button>
</div>
</div>
`;
document.body.appendChild(modal);
// Add CSS for profile modal
if (!document.getElementById('profile-modal-styles')) {
const styles = document.createElement('style');
styles.id = 'profile-modal-styles';
styles.textContent = `
.profile-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.profile-modal-content {
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
border-radius: 12px;
padding: 30px;
max-width: 500px;
width: 90%;
box-shadow: 0 15px 50px rgba(0,0,0,0.4);
color: white;
}
.profile-header {
display: flex;
align-items: center;
gap: 15px;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 2px solid rgba(255,255,255,0.2);
position: relative;
}
.profile-avatar {
width: 70px;
height: 70px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 28px;
font-weight: bold;
}
.profile-info {
flex: 1;
}
.profile-info h2 {
margin: 0;
font-size: 20px;
}
.profile-info p {
margin: 5px 0 0 0;
opacity: 0.8;
font-size: 14px;
}
.profile-close {
position: absolute;
right: 0;
top: 0;
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
opacity: 0.7;
}
.profile-close:hover {
opacity: 1;
}
.profile-section {
margin-bottom: 25px;
}
.profile-section h3 {
margin: 0 0 15px 0;
font-size: 16px;
color: #a8d5ff;
border-bottom: 1px solid rgba(255,255,255,0.2);
padding-bottom: 10px;
}
.profile-field {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0;
border-bottom: 1px solid rgba(255,255,255,0.1);
}
.profile-field label {
font-weight: 500;
opacity: 0.8;
}
.profile-field span {
background: rgba(255,255,255,0.1);
padding: 5px 12px;
border-radius: 4px;
font-family: monospace;
}
.permission-list {
list-style: none;
padding: 0;
margin: 0;
}
.permission-list li {
padding: 10px 0;
border-bottom: 1px solid rgba(255,255,255,0.1);
font-size: 14px;
}
.permission-list li:last-child {
border-bottom: none;
}
.profile-actions {
text-align: center;
margin-top: 25px;
}
.btn-close-profile {
background: rgba(255,255,255,0.2);
color: white;
border: 2px solid white;
padding: 12px 30px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
}
.btn-close-profile:hover {
background: rgba(255,255,255,0.3);
}
`;
document.head.appendChild(styles);
}
}
showPermissions() {
// Close dropdown first
this.elements.authDropdown.classList.remove('show');
const existingPermDialog = document.getElementById('perm-modal');
if (existingPermDialog) {
existingPermDialog.remove();
}
const modal = document.createElement('div');
modal.id = 'perm-modal';
modal.className = 'permission-modal';
modal.innerHTML = `
<div class="permission-modal-content">
<div class="perm-header">
<h2> Permission Configuration</h2>
<button onclick="document.getElementById('perm-modal').remove();" class="perm-close">✕</button>
</div>
<div class="perm-section">
<h3>Role: ${this.currentUser.role}</h3>
<p>Current user has the following permissions:</p>
</div>
<div class="perm-list">
${this.getCurrentPermissions().map(p => `
<div class="perm-item">
<span class="perm-check">✓</span>
<span class="perm-name">${p}</span>
</div>
`).join('')}
</div>
<div class="perm-footer">
<button onclick="document.getElementById('perm-modal').remove();" class="btn-close-perm">ปิด</button>
</div>
</div>
`;
document.body.appendChild(modal);
if (!document.getElementById('permission-modal-styles')) {
const styles = document.createElement('style');
styles.id = 'permission-modal-styles';
styles.textContent = `
.permission-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
}
.permission-modal-content {
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
border-radius: 12px;
padding: 30px;
max-width: 450px;
width: 90%;
box-shadow: 0 15px 50px rgba(0,0,0,0.4);
color: white;
}
.perm-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 25px;
padding-bottom: 15px;
border-bottom: 2px solid rgba(255,255,255,0.2);
}
.perm-header h2 {
margin: 0;
font-size: 20px;
}
.perm-close {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
opacity: 0.7;
}
.perm-close:hover {
opacity: 1;
}
.perm-section {
margin-bottom: 20px;
}
.perm-section h3 {
margin: 0 0 10px 0;
color: #a8d5ff;
}
.perm-section p {
margin: 0;
opacity: 0.8;
font-size: 14px;
}
.perm-list {
margin: 20px 0;
padding: 15px;
background: rgba(255,255,255,0.05);
border-radius: 8px;
}
.perm-item {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 0;
}
.perm-check {
color: #4ade80;
font-weight: bold;
}
.perm-name {
font-size: 14px;
}
.perm-footer {
text-align: center;
margin-top: 25px;
}
.btn-close-perm {
background: rgba(255,255,255,0.2);
color: white;
border: 2px solid white;
padding: 10px 25px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
}
.btn-close-perm:hover {
background: rgba(255,255,255,0.3);
}
`;
document.head.appendChild(styles);
}
}
getCurrentPermissions() {
const permissions = {
admin: [
'จัดการPluginทั้งหมด',
'ตั้งค่าระบบและการกำหนดค่า',
'ดูและส่งออกรายงาน',
'จัดการบัญชีผู้ใช้',
'เข้าถึงเดชบอร์ดผู้ดูแลระบบ'
],
developer: [
'ติดตั้งPluginใหม่',
'แก้ไขและอัปเดตPlugin',
'เข้าถึงหน้าทดสอบ',
'ดูรายงานการใช้งาน',
'เข้าถึง API สำหรับการพัฒนา'
],
user: [
'ดูPluginที่ติดตั้ง',
'ดูรายงานพื้นฐาน',
'เปลี่ยนรหัสผ่านส่วนตัว',
'ดูข้อมูลโปรไฟล์'
]
};
return permissions[this.currentUser.role] || permissions.user;
}
handlePermission(allowed) {
this.elements.permissionDialog.classList.remove('show');
addTerminalLine(`Permission: ${allowed ? 'Granted' : 'Denied'}`, allowed ? "success" : "warn");
}
// Public method to check if user is authenticated
isUserAuthenticated() {
return this.isAuthenticated;
}
// Public method to get current user
getCurrentUser() {
return this.currentUser;
}
}
// Initialize Auth Manager
let authManager;
// ┌─────────────────────────────────────────────────────────────────────────────────┐
// │ [SWITCH] ZONE 7: PAGE SWITCHING - ระบบสลับระหว่างหน้าPluginและร้านค้า │
// └─────────────────────────────────────────────────────────────────────────────────┘
// ┌─────────────────────────────────────────────────────────────────────────────────┐
// │ [AUTH] ZONE 9: AUTHENTICATION HELPER FUNCTIONS │
// └─────────────────────────────────────────────────────────────────────────────────┘
// ======================================================================
// ฟังก์ชันตรวจสอบการล็อกอินและดำเนินการ
// ======================================================================
function checkAuthAndExecute(functionName, ...args) {
if (authManager && authManager.isUserAuthenticated()) {
// ถ้าล็อกอินแล้ว ให้รันฟังก์ชันปกติ
if (typeof window[functionName] === 'function') {
window[functionName](...args);
}
} else {
// ถ้ายังไม่ล็อกอิน แสดงกล่องแจ้งเตือน
if (window.authDialog) {
window.authDialog.show();
} else {
// Fallback ถ้า authDialog ยังไม่พร้อม
alert('กรุณาล็อกอินก่อนใช้งาน');
}
}
}
// ======================================================================
// ฟังก์ชันปิดใช้งานปุ่มที่ต้องการล็อกอิน
// ======================================================================
function disableProtectedButtons() {
const protectedButtons = [
'scan-plugin-btn',
'open-folder-btn',
'generate-manifest-btn'
];
protectedButtons.forEach(buttonId => {
const button = document.getElementById(buttonId);
if (button) {
button.style.opacity = '0.5';
button.style.cursor = 'not-allowed';
button.style.filter = 'grayscale(1)';
}
});
// Disable plugin management section
const pluginContainer = document.getElementById('plugin-container');
if (pluginContainer) {
pluginContainer.style.opacity = '0.5';
pluginContainer.style.filter = 'grayscale(1)';
pluginContainer.innerHTML = `
<div class="login-required-message">
<div style="text-align: center; padding: 40px; color: #666;">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-bottom: 16px;">
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
<circle cx="12" cy="16" r="1"/>
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
</svg>
<h3 style="margin-bottom: 8px;">Sign in first to continue</h3>
<p style="color: #888;">Please sign in to access plugin management and project features</p>
<button onclick="authManager.startLogin()" style="
margin-top: 16px;
padding: 8px 16px;
background: linear-gradient(135deg, #0ea5e9, #0284c7);
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
">Sign In</button>
</div>
</div>
`;
}
}
// ======================================================================
// ฟังก์ชันเปิดใช้งานปุ่มที่ต้องการล็อกอิน
// ======================================================================
function enableProtectedButtons() {
const protectedButtons = [
'scan-plugin-btn',
'open-folder-btn',
'generate-manifest-btn'
];
protectedButtons.forEach(buttonId => {
const button = document.getElementById(buttonId);
if (button) {
button.style.opacity = '1';
button.style.cursor = 'pointer';
button.style.filter = 'none';
}
});
// Enable plugin management section
const pluginContainer = document.getElementById('plugin-container');
if (pluginContainer) {
pluginContainer.style.opacity = '1';
pluginContainer.style.filter = 'none';
pluginContainer.innerHTML = '<div class="loading">Loading plugins...</div>';
// Load plugins when login is successful
setTimeout(() => {
scanAndRenderPlugins();
}, 1000);
}
}
document.addEventListener("DOMContentLoaded", () => {
// Initialize Authentication System
authManager = new AuthManager();
// ดึง elements ที่จำเป็น
const logPanel = document.getElementById("log-viewer");
const storePanel = document.getElementById("store-webview"); // แก้เป็น ID ที่ถูกต้อง
const originalSystem = document.getElementById("original-system");
const navPluginsBtn = document.getElementById("nav-plugins");
const navStoreBtn = document.getElementById("nav-store-new");
const refreshStoreBtn = document.getElementById("refresh-store-btn");
let isStoreLoaded = false;
// ======================================================================
// ฟังก์ชันสลับ View หลักของแอปพลิเคชัน
// ======================================================================
function switchView(viewName) {
// ซ่อน/ล้าง active class ทั้งหมดก่อน
logPanel.classList.remove("active");
storePanel.classList.remove("active");
navPluginsBtn.classList.remove("active");
navStoreBtn.classList.remove("active");
refreshStoreBtn.style.display = "none";
if (viewName === 'plugins') {
// --- แสดงหน้า "Pluginของฉัน" ---
logPanel.classList.add("active");
navPluginsBtn.classList.add("active");
addTerminalLine("Showing My Plugins management page", "info");
} else if (viewName === 'store') {
// --- แสดงหน้า "ร้านค้าPlugin" ---
storePanel.classList.add("active");
navStoreBtn.classList.add("active");
refreshStoreBtn.style.display = "block"; // แสดงปุ่มรีเฟรช
addTerminalLine("Opening Chahua Plugin Store...", "info");
// โหลด URL ร้านค้าแค่ครั้งแรก
if (!isStoreLoaded) {
let storeUrl = "https://chahuadev.com/index.html";
storePanel.src = storeUrl;
isStoreLoaded = true;
}
}
}
// กำหนด Event Listener ให้ปุ่ม
navPluginsBtn.addEventListener('click', () => switchView('plugins'));
navStoreBtn.addEventListener('click', () => switchView('store'));
refreshStoreBtn.addEventListener('click', () => {
if (storePanel.classList.contains('active')) {
addTerminalLine("Refreshing store...", "command");
storePanel.reload();
}
});
// เริ่มต้นที่หน้า "Pluginของฉัน"
switchView('plugins');
// ตั้งเวลาเพื่อให้ authManager เริ่มต้นเสร็จก่อน
setTimeout(() => {
// ตรวจสอบสถานะการล็อกอิน และแสดงผลที่เหมาะสม
if (!authManager || !authManager.isUserAuthenticated()) {
disableProtectedButtons();
}
}, 500);
});
</script>
<!-- Permission Dialog -->
<div id="permission-dialog" class="permission-dialog">
<div class="permission-dialog-content">
<div class="permission-dialog-header">
<h3>Plugin Access Control</h3>
</div>
<div class="permission-dialog-body">
<p id="permission-plugin-name">Plugin ต้องการอนุญาตการเข้าถึงข้อมูลต่อไปนี้:</p>
<ul id="permission-list" class="permission-list">
<!-- Permissions will be populated dynamically -->
</ul>
</div>
<div class="permission-dialog-actions">
<button id="permission-deny" class="btn-permission">ปฏิเสธ</button>
<button id="permission-allow" class="btn-permission primary">อนุญาต</button>
</div>
</div>
</div>
<script>
// Outer topnav: switch between Home landing page, App, and Chat
function switchTopPage(page) {
if (page === 'chat' && window.isDev) {
page = 'home';
}
var homeWrap = document.getElementById('home-wv-wrap');
var chatWrap = document.getElementById('chat-wv-wrap');
var ontHome = document.getElementById('ont-home');
var ontApp = document.getElementById('ont-app');
var ontChat = document.getElementById('ont-chat');
// Reset all
homeWrap.classList.remove('visible');
if (chatWrap) chatWrap.classList.remove('visible');
ontHome.classList.remove('active');
ontApp.classList.remove('active');
if (ontChat) ontChat.classList.remove('active');
if (page === 'home') {
homeWrap.classList.add('visible');
ontHome.classList.add('active');
} else if (page === 'chat') {
if (chatWrap) chatWrap.classList.add('visible');
if (ontChat) ontChat.classList.add('active');
} else {
ontApp.classList.add('active');
}
}
// Disable chat tab in development mode.
(function applyChatModePolicy() {
if (!window.isDev) return;
var chatTab = document.getElementById('ont-chat');
var chatWrap = document.getElementById('chat-wv-wrap');
if (chatTab) chatTab.style.display = 'none';
if (chatWrap) chatWrap.classList.remove('visible');
})();
</script>
</body>
</html>