|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| const safeExternalCommands = new Set([ |
| 'ping', |
| 'tracert', |
| 'ipconfig', |
| 'ifconfig', |
| 'getmac', |
| 'node', |
| 'npm' |
| ]); |
| |
|
|
| 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 }); |
| |
| |
| const logLine = document.createElement('span'); |
| logLine.className = `log-line log-${type}`; |
| |
| |
| logLine.textContent = `[${time}] ${text}\n`; |
|
|
| |
| logViewer.appendChild(logLine); |
|
|
| |
| logViewer.scrollTop = logViewer.scrollHeight; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function openDebugWindow() { |
| addTerminalLine(' กำลังเปิดหน้าต่าง Debug...', 'command'); |
| try { |
| |
| await window.electronAPI.openDebugWindow(); |
| addTerminalLine(' เปิดหน้าต่าง Debug สำเร็จ', 'success'); |
| } catch (error) { |
| addTerminalLine(` ไม่สามารถเปิดหน้าต่าง Debug ได้: ${error.message}`, 'error'); |
| } |
| } |
|
|
| |
| document.addEventListener('keydown', (event) => { |
| if (event.key === 'Escape') { |
| |
| if (window.resizeController && window.resizeController.isResizing) { |
| window.resizeController.stopResize(); |
| } |
| } |
| }); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function copyMachineID(machineID) { |
| try { |
| await navigator.clipboard.writeText(machineID); |
| addTerminalLine(` คัดลอกรหัสเครื่องแล้ว: ${machineID}`, 'success'); |
| } catch (error) { |
| addTerminalLine(` ไม่สามารถคัดลอกได้: ${error.message}`, 'error'); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function scanAndRenderPlugins() { |
| addTerminalLine(' กำลังสแกนปลั๊กอิน...', 'command'); |
| |
| |
| showLoadingAnimation(pluginContainer, 'กำลังสแกนปลั๊กอิน'); |
|
|
| |
| |
| 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">ไม่พบปลั๊กอินหรือโปรเจกต์ที่ทำงานได้</div>`; |
| addTerminalLine(' ไม่พบโปรเจกต์ที่สามารถสร้างปุ่มการทำงานได้', 'info'); |
| } else { |
| |
| 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 ? `<img src="${pluginData.previewImage}" class="plugin-preview-image" alt="Preview for ${pluginData.name}">` : ''} |
| <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); |
| }); |
| |
| |
| setTimeout(() => { |
| addTerminalLine(` สแกนเสร็จสิ้น พบ ${plugins.length} โปรเจกต์ที่พร้อมใช้งาน`, 'success'); |
| showNotification(` พบ ${plugins.length} ปลั๊กอินที่พร้อมใช้งาน!`, 'success'); |
| }, (plugins.length * 100) + 200); |
| } |
| } else { |
| pluginContainer.innerHTML = `<div class="loading">เกิดข้อผิดพลาดในการโหลดปลั๊กอิน</div>`; |
| addTerminalLine(` ข้อผิดพลาดในการสแกนปลั๊กอิน: ${result.error || 'ไม่ได้รับข้อมูลจาก Main Process'}`, 'error'); |
| showNotification(' เกิดข้อผิดพลาดในการสแกนปลั๊กอิน', 'error'); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function scanAndRenderPluginsWithDebug() { |
| addTerminalLine(' กำลังสแกนปลั๊กอินพร้อมข้อมูล Debug...', 'command'); |
| |
| |
| showLoadingAnimation(pluginContainer, 'กำลังวิเคราะห์ปลั๊กอิน'); |
|
|
| try { |
| |
| 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">ไม่พบปลั๊กอินหรือโปรเจกต์ที่ทำงานได้</div>`; |
| addTerminalLine(' ไม่พบโปรเจกต์ที่สามารถสร้างปุ่มการทำงานได้', 'info'); |
| } else { |
| let totalErrors = 0; |
| let totalWarnings = 0; |
| |
| |
| 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 ? `<img src="${pluginData.previewImage}" class="plugin-preview-image" alt="Preview for ${pluginData.name}">` : ''} |
| <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); |
| }); |
| |
| |
| setTimeout(() => { |
| addTerminalLine(` Enhanced scan เสร็จสิ้น: ${plugins.length} projects`, 'success'); |
| addTerminalLine(` พบปัญหา: ${totalErrors} errors, ${totalWarnings} warnings`, |
| totalErrors > 0 ? 'error' : 'info'); |
| showNotification(` สแกน ${plugins.length} ปลั๊กอิน พร้อมข้อมูล Debug!`, 'success'); |
| }, (plugins.length * 100) + 200); |
| } |
| } else { |
| pluginContainer.innerHTML = `<div class="loading">เกิดข้อผิดพลาดในการสแกน Debug</div>`; |
| addTerminalLine(` ข้อผิดพลาดในการสแกน Debug: ${result.error || 'ไม่ได้รับข้อมูลจาก Main Process'}`, 'error'); |
| showNotification(' เกิดข้อผิดพลาดในการสแกน Debug', 'error'); |
| } |
| } catch (error) { |
| console.error('Enhanced scan error:', error); |
| pluginContainer.innerHTML = `<div class="loading">เกิดข้อผิดพลาดในการสแกน Debug</div>`; |
| addTerminalLine(` Enhanced scan failed: ${error.message}`, 'error'); |
| showNotification(' เกิดข้อผิดพลาดในการสแกน Debug', 'error'); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function runGeneratorAndRefresh() { |
| addTerminalLine(' กำลังสั่งให้ระบบสแกนหาปลั๊กอินใหม่และสร้าง Manifest...', 'command'); |
| |
| |
| showLoadingAnimation(pluginContainer, 'กำลังสร้าง Manifest'); |
| |
| try { |
| const result = await window.electronAPI.runManifestGenerator(); |
| if (result.success) { |
| addTerminalLine(' สร้าง Manifest สำเร็จ! กำลังโหลดรายการปลั๊กอินใหม่...', 'success'); |
| showNotification(' สร้าง Manifest สำเร็จ!', 'success'); |
| |
| |
| setTimeout(async () => { |
| await scanAndRenderPlugins(); |
| }, 500); |
| } else { |
| addTerminalLine(` เกิดข้อผิดพลาดในการสร้าง Manifest: ${result.error}`, 'error'); |
| showNotification(' เกิดข้อผิดพลาดในการสร้าง Manifest', 'error'); |
| pluginContainer.innerHTML = `<div class="loading">เกิดข้อผิดพลาดในการสร้าง Manifest</div>`; |
| } |
| } catch (error) { |
| addTerminalLine(` ข้อผิดพลาด IPC ร้ายแรง: ${error.message}`, 'error'); |
| showNotification(' ข้อผิดพลาด IPC ร้ายแรง', 'error'); |
| pluginContainer.innerHTML = `<div class="loading">เกิดข้อผิดพลาดร้ายแรง</div>`; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function runGenerateManifestOnly() { |
| addTerminalLine(' กำลังรันตัวสร้าง Manifest Files...', 'command'); |
| try { |
| const result = await window.electronAPI.runManifestGenerator(); |
| if (result.success) { |
| addTerminalLine(' สร้าง Manifest Files สำเร็จ!', 'success'); |
| addTerminalLine(` ผลลัพธ์:`, 'info'); |
| addTerminalLine(result.output, 'stdout'); |
| } else { |
| addTerminalLine(` เกิดข้อผิดพลาดในการสร้าง Manifest: ${result.error}`, 'error'); |
| } |
| } catch (error) { |
| addTerminalLine(` ข้อผิดพลาด IPC ร้ายแรง: ${error.message}`, 'error'); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function openPluginsFolder() { |
| addTerminalLine(' กำลังเปิดโฟลเดอร์ปลั๊กอิน...', 'command'); |
| try { |
| const result = await window.electronAPI.openPluginsFolder(); |
| if (result.success) { |
| addTerminalLine(' เปิดโฟลเดอร์ปลั๊กอินใน File Explorer แล้ว', 'success'); |
| addTerminalLine(` ตำแหน่ง: ${result.path}`, 'info'); |
| addTerminalLine(' คุณสามารถวางไฟล์ปลั๊กอินของคุณในโฟลเดอร์นี้แล้วกดปุ่ม " สแกนหาปลั๊กอินใหม่"', 'info'); |
| showNotification(' เปิดโฟลเดอร์ปลั๊กอินแล้ว!', 'success'); |
| } else { |
| addTerminalLine(` ไม่สามารถเปิดโฟลเดอร์ปลั๊กอินได้: ${result.error}`, 'error'); |
| showNotification(' ไม่สามารถเปิดโฟลเดอร์ปลั๊กอินได้', 'error'); |
| } |
| } catch (error) { |
| addTerminalLine(` ข้อผิดพลาด IPC: ${error.message}`, 'error'); |
| showNotification(' ข้อผิดพลาด IPC', 'error'); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function startBuildProcess() { |
| addTerminalLine(' กำลังเริ่มต้นกระบวนการ Build แอปพลิเคชัน...', 'command'); |
| addTerminalLine(' คำสั่ง: npx electron-builder --win --x64', 'command'); |
| addTerminalLine(' กรุณารอสักครู่ กระบวนการนี้อาจใช้เวลาหลายนาที...', 'info'); |
| addTerminalLine(' การ Build จะสร้างไฟล์ MSI และ EXE สำหรับติดตั้งบน Windows', 'info'); |
| |
| |
| showNotification(' เริ่มต้น Build Process...', 'info'); |
| |
| |
| 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 2s infinite; |
| `; |
| 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> กำลัง Build แอปพลิเคชัน...</span> |
| </div> |
| `; |
| |
| |
| const licenseStatus = document.getElementById('license-status'); |
| licenseStatus.parentNode.insertBefore(buildStatusDiv, licenseStatus.nextSibling); |
| |
| try { |
| const result = await window.electronAPI.startBuild(); |
| if (!result.success) { |
| addTerminalLine(` ไม่สามารถเริ่ม Build ได้: ${result.error}`, 'error'); |
| showNotification(' ไม่สามารถเริ่ม Build ได้', 'error'); |
| |
| |
| buildStatusDiv.remove(); |
| } else { |
| addTerminalLine(' เริ่มกระบวนการ Build สำเร็จ!', 'success'); |
| |
| |
| 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> กำลังดำเนินการ Build... (ตรวจสอบ Log ด้านล่าง)</span> |
| </div> |
| `; |
| } |
| } catch (error) { |
| addTerminalLine(` เกิดข้อผิดพลาดร้ายแรง: ${error.message}`, 'error'); |
| showNotification(' เกิดข้อผิดพลาดร้ายแรง', 'error'); |
| |
| |
| buildStatusDiv.remove(); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| 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;"></span> |
| <span> Build เสร็จสมบูรณ์! ตรวจสอบไฟล์ในโฟลเดอร์ dist/</span> |
| </div> |
| `; |
| showNotification(' Build สำเร็จ! ไฟล์ MSI/EXE พร้อมใช้งาน', '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;"></span> |
| <span> Build ล้มเหลว! ตรวจสอบ Log เพื่อดูรายละเอียด</span> |
| </div> |
| `; |
| showNotification(' Build ล้มเหลว!', 'error'); |
| } |
| |
| |
| setTimeout(() => { |
| buildStatusDiv.remove(); |
| }, 10000); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function createPluginButtons(pluginData) { |
| let buttonsHTML = ''; |
| if (pluginData.buttons && pluginData.buttons.length > 0) { |
| pluginData.buttons.forEach(buttonInfo => { |
| |
| buttonsHTML += ` |
| <button |
| onclick="runPluginAction('${pluginData.name}', '${buttonInfo.command}', '${pluginData.path.replace(/\\/g, '\\\\')}')" |
| title="${buttonInfo.tooltip || buttonInfo.name}" |
| > |
| ${buttonInfo.icon || ''} ${buttonInfo.name} |
| </button> |
| `; |
| }); |
| } |
| buttonsHTML += `<button onclick="runPluginAction('${pluginData.name}', 'info', '${pluginData.path.replace(/\\/g, '\\\\')}')" title="แสดงข้อมูล">ℹ ข้อมูล</button>`; |
| return buttonsHTML || '<span>ไม่มีคำสั่งที่ใช้ได้</span>'; |
| } |
| |
| |
| function getIconForType(pluginData) { |
| |
| if (pluginData.icon) { |
| return pluginData.icon; |
| } |
| |
| |
| const icons = { |
| 'node': '', |
| 'python': '', |
| 'java': '', |
| 'api': '', |
| 'html': '', |
| 'project': '', |
| 'batch_project': '', |
| 'executable_project': '', |
| 'electron_app': '', |
| 'utility_tool': '', |
| 'chahuadev_studio': '', |
| 'html_plugin': '', |
| 'javascript_plugin': '' |
| }; |
| return icons[pluginData.type] || ''; |
| } |
|
|
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function runPluginAction(pluginName, action, projectPath) { |
| addTerminalLine(` กำลังรัน Action: "${action}" บนปลั๊กอิน "${pluginName}"...`, 'command'); |
| |
| try { |
| |
| const result = await window.electronAPI.processCommand({ |
| action: action, |
| pluginName: pluginName, |
| projectPath: projectPath |
| }); |
| |
| if (result.success) { |
| addTerminalLine(` Action สำเร็จ!`, 'success'); |
| const output = result.data?.output || result.data?.message || result.message; |
| if (output) { |
| addTerminalLine(output, 'stdout'); |
| } |
| } else { |
| addTerminalLine(` Action ล้มเหลว: ${result.error}`, 'error'); |
| } |
| } catch (err) { |
| addTerminalLine(` ข้อผิดพลาดร้ายแรง (IPC): ${err.message}`, 'error'); |
| } |
| } |
| |
| window.runPluginAction = runPluginAction; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function runExternalCommand(command) { |
| try { |
| |
| |
| const result = await window.electronAPI.executeQuickCommand(command); |
|
|
| if (result.success) { |
| |
| addTerminalLine(result.data.output, 'stdout'); |
| } else { |
| |
| addTerminalLine(result.error, 'error'); |
| } |
| } catch (err) { |
| |
| addTerminalLine(` IPC Error: ${err.message}`, 'error'); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| 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'); |
| 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(` คำสั่งล้มเหลว: ${result.error}`, 'error'); |
| } |
| } catch (error) { |
| addTerminalLine(` ข้อผิดพลาด: ${error.message}`, 'error'); |
| } |
| } |
|
|
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function addSuccessEffect(element) { |
| element.classList.add('success-animation'); |
| setTimeout(() => { |
| element.classList.remove('success-animation'); |
| }, 600); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function addClickEffect(event) { |
| const button = event.target; |
| |
| |
| 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; |
| `; |
| |
| |
| 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(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function initializeButtonEffects() { |
| document.addEventListener('click', (event) => { |
| if (event.target.tagName === 'BUTTON') { |
| addClickEffect(event); |
| } |
| }); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function animatePluginCards() { |
| const cards = document.querySelectorAll('.plugin-card'); |
| cards.forEach((card, index) => { |
| card.style.animationDelay = `${index * 0.1}s`; |
| card.classList.add('fadeIn'); |
| }); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function showLoadingAnimation(element, text = 'กำลังโหลด') { |
| |
| if (!element) { |
| console.warn(' 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> |
| `; |
| |
| |
| 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); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function showNotification(message, type = 'info') { |
| |
| |
| console.log(` [Notification Disabled] ${message} (${type})`); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function isDevMode() { |
| |
| 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; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function initProductionSecurity() { |
| const isDev = isDevMode(); |
| console.log(' Security Mode:', isDev ? 'DEVELOPMENT' : 'PRODUCTION'); |
| |
| if (!isDev) { |
| |
| const consoleMethods = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', |
| 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd']; |
| |
| consoleMethods.forEach(method => { |
| console[method] = function() { |
| |
| }; |
| }); |
| |
| |
| document.addEventListener('keydown', function(e) { |
| |
| if (e.key === 'F12') { |
| e.preventDefault(); |
| e.stopPropagation(); |
| return false; |
| } |
| |
| |
| if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'I') { |
| e.preventDefault(); |
| e.stopPropagation(); |
| return false; |
| } |
| |
| |
| if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'J') { |
| e.preventDefault(); |
| e.stopPropagation(); |
| return false; |
| } |
| |
| |
| if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'C') { |
| e.preventDefault(); |
| e.stopPropagation(); |
| return false; |
| } |
| |
| |
| if ((e.ctrlKey || e.metaKey) && e.key === 'u') { |
| e.preventDefault(); |
| e.stopPropagation(); |
| return false; |
| } |
| |
| |
| if ((e.ctrlKey || e.metaKey) && e.key === 's') { |
| e.preventDefault(); |
| e.stopPropagation(); |
| return false; |
| } |
| }, true); |
| |
| |
| document.addEventListener('contextmenu', function(e) { |
| e.preventDefault(); |
| e.stopPropagation(); |
| return false; |
| }, true); |
| |
| |
| document.addEventListener('selectstart', function(e) { |
| e.preventDefault(); |
| return false; |
| }, true); |
| |
| document.addEventListener('dragstart', function(e) { |
| e.preventDefault(); |
| return false; |
| }, true); |
| |
| |
| 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); |
| |
| |
| let startTime = new Date(); |
| debugger; |
| let endTime = new Date(); |
| if (endTime - startTime > 100) { |
| showDeveloperToolsWarning(); |
| } |
| } |
| |
| return isDev; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| 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: 999999; |
| 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;"> การเข้าถึงถูกปฏิเสธ</h1> |
| <p style="font-size: 1.2em; margin-bottom: 20px; line-height: 1.6;"> |
| ระบบตรวจพบการเปิด Developer Tools<br/> |
| แอปพลิเคชันนี้ได้รับการป้องกันเพื่อความปลอดภัย |
| </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;"> |
| Production Mode Active<br/> |
| Security Features Enabled<br/> |
| 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); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function hideDeveloperToolsWarning() { |
| const warning = document.getElementById('dev-tools-warning'); |
| if (warning) { |
| warning.remove(); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function devLog(...args) { |
| if (isDevMode()) { |
| console.log(...args); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function devError(...args) { |
| if (isDevMode()) { |
| console.error(...args); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function devWarn(...args) { |
| if (isDevMode()) { |
| console.warn(...args); |
| } |
| } |
|
|
| |
| |
| |
|
|
| document.addEventListener('DOMContentLoaded', async () => { |
| |
| const isDev = initProductionSecurity(); |
| |
| |
| window.isDev = isDev; |
| |
| addTerminalLine('กำลังเริ่มต้นระบบ...', 'info'); |
| |
| if (isDev) { |
| addTerminalLine(' Developer Mode: Security features disabled for development', 'warning'); |
| document.body.classList.add('dev-mode'); |
| } else { |
| addTerminalLine(' Production Mode: Security features active', 'success'); |
| document.body.classList.remove('dev-mode'); |
| } |
| |
| if (window.electronAPI) { |
| addTerminalLine('สคริปต์โหลดเสร็จสิ้น เชื่อมต่อกับระบบหลักแล้ว', 'success'); |
| |
| |
| try { |
| const runMode = await window.electronAPI.getRunMode(); |
| if (runMode.isDevMode) { |
| console.log('ทำงานในโหมดนักพัฒนา - แสดงฟีเจอร์สำหรับนักพัฒนา'); |
| addTerminalLine('โหมดนักพัฒนา: เปิดใช้งานฟีเจอร์สำหรับนักพัฒนา', 'success'); |
| window.isDev = true; |
| document.body.classList.add('dev-mode'); |
| |
| showNotification('โหมดนักพัฒนา: เครื่องมือพิเศษพร้อมใช้งาน', 'info'); |
| } else { |
| console.log('ทำงานในโหมดลูกค้า - ซ่อนฟีเจอร์สำหรับนักพัฒนา'); |
| addTerminalLine('โหมดลูกค้า: เฉพาะฟีเจอร์สำหรับผู้ใช้ทั่วไป', 'info'); |
| document.body.classList.remove('dev-mode'); |
| |
| showNotification('เวอร์ชันลูกค้า - พร้อมใช้งาน!', 'success'); |
| } |
| } catch (error) { |
| console.error('ไม่สามารถตรวจสอบโหมดการทำงานได้:', error); |
| addTerminalLine('ไม่สามารถตรวจสอบโหมดการทำงาน - ใช้โหมดปกติ', 'warning'); |
| |
| document.body.classList.remove('dev-mode'); |
| } |
| |
| |
| initializeButtonEffects(); |
| |
| |
| |
| |
| |
| addTerminalLine('===== Chahua Plugin Management System =====', 'success'); |
| addTerminalLine('ระบบจัดการปลั๊กอิน - โหมด Log Viewer', 'info'); |
| addTerminalLine('ข้อความจากระบบและปุ่มต่างๆ จะแสดงที่นี่', 'info'); |
| addTerminalLine('', 'info'); |
|
|
| setTimeout(() => { |
| scanAndRenderPlugins(); |
| }, 1000); |
| |
| |
| window.electronAPI.onBuildLog((log) => { |
| |
| if (log.includes('[ERROR]')) { |
| addTerminalLine(log.replace('[ERROR] ', ''), 'error'); |
| } else if (log.includes('') || log.includes('')) { |
| addTerminalLine(log, 'success'); |
| |
| if (log.includes('Build เสร็จสมบูรณ์')) { |
| onBuildComplete(true); |
| } |
| } else if (log.includes('') || log.includes('')) { |
| addTerminalLine(log, 'error'); |
| |
| if (log.includes('Build ล้มเหลว')) { |
| onBuildComplete(false); |
| } |
| } else { |
| |
| addTerminalLine(log, 'stdout'); |
| } |
| }); |
| |
| |
| 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'); |
| |
| scanAndRenderPluginsWithDebug(); |
| } else { |
| addTerminalLine(` Enhanced scan failed: ${result.error}`, 'error'); |
| } |
| }); |
| } |
| |
| |
| setTimeout(() => { |
| showNotification('ยินดีต้อนรับสู่ระบบจัดการปลั๊กอิน Chahuadev!', 'success'); |
| }, 2000); |
| |
|
|
| |
| |
| initializeLicenseDropdown(); |
| |
| |
| window.resizeController = new ResizePanelController(); |
| |
| |
| initParameterizedDiagnostics(); |
| |
| |
| 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'); |
| if (result.message) { |
| addTerminalLine(result.message, 'info'); |
| } |
| if (result.fixed) { |
| addTerminalLine(' ระบบได้รับการซ่อมแซมเรียบร้อยแล้ว', 'success'); |
| } |
| if (result.recommendations && result.recommendations.length > 0) { |
| addTerminalLine(` คำแนะนำ: ${result.recommendations.join(', ')}`, 'info'); |
| } |
| } else { |
| addTerminalLine(` การวินิจฉัยล้มเหลว: ${result.error}`, 'error'); |
| } |
| } catch (error) { |
| addTerminalLine(` ไม่สามารถเริ่มการวินิจฉัยได้: ${error.message}`, 'error'); |
| } |
| }); |
| } |
| |
| } else { |
| addTerminalLine('ข้อผิดพลาดร้ายแรง: ไม่พบสคริปต์โหลด (electronAPI)!', 'error'); |
| } |
| }); |
| |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| 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); |
| }); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function loadAvailablePlugins() { |
| const pluginList = document.getElementById('pluginList'); |
| if (!pluginList) return; |
| |
| try { |
| |
| 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 = 'ไม่พบปลั๊กอิน'; |
| option.disabled = true; |
| pluginList.appendChild(option); |
| } |
| } else { |
| pluginList.innerHTML = '<option disabled>ไม่สามารถโหลดรายชื่อปลั๊กอินได้</option>'; |
| } |
| } catch (error) { |
| console.error('Error loading plugins:', error); |
| pluginList.innerHTML = '<option disabled>เกิดข้อผิดพลาดในการโหลด</option>'; |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function getSelectedPlugins() { |
| const pluginList = document.getElementById('pluginList'); |
| if (!pluginList) return []; |
| |
| const selected = []; |
| for (let option of pluginList.selectedOptions) { |
| selected.push(option.value); |
| } |
| return selected; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function getDiagnosticScopeText(scope) { |
| const scopeTexts = { |
| 'all': 'ทั้งระบบ', |
| 'plugins': 'ปลั๊กอินทั้งหมด', |
| 'core': 'ระบบหลัก', |
| 'dependencies': 'Dependencies', |
| 'specific': 'ปลั๊กอินที่เลือก' |
| }; |
| return scopeTexts[scope] || 'ไม่ระบุ'; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function updateDiagnosticButtonText(scope) { |
| const button = document.getElementById('runSystemCheckBtn'); |
| if (!button) return; |
| |
| const icon = '<i class="fas fa-shield-alt"></i>'; |
| const texts = { |
| 'all': `${icon} วินิจฉัยทั้งระบบ`, |
| 'plugins': `${icon} วินิจฉัยปลั๊กอิน`, |
| 'core': `${icon} วินิจฉัยระบบหลัก`, |
| 'dependencies': `${icon} วินิจฉัย Dependencies`, |
| 'specific': `${icon} วินิจฉัยปลั๊กอินที่เลือก` |
| }; |
| |
| button.innerHTML = texts[scope] || `${icon} เริ่มการวินิจฉัย`; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| 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(' Resize elements not found'); |
| return; |
| } |
| |
| this.initializeResizePanel(); |
| console.log(' Resize panel system initialized'); |
| } |
| |
| initializeResizePanel() { |
| |
| this.boundHandleResize = this.handleResize.bind(this); |
| this.boundStopResize = this.stopResize.bind(this); |
| |
| |
| this.emergencyCleanup = () => { |
| console.log(" Emergency cleanup triggered!"); |
| this.stopResize(); |
| }; |
| |
| |
| this.boundKeydownHandler = (event) => { |
| if (event.key === 'Escape') { |
| console.log(" Escape key pressed, stopping resize"); |
| this.emergencyCleanup(); |
| } |
| }; |
| |
| |
| this.resizeHandle.addEventListener('mousedown', (e) => { |
| |
| e.preventDefault(); |
| e.stopPropagation(); |
| |
| console.log(" Mouse down on resize handle"); |
| |
| |
| document.addEventListener('mousemove', this.boundHandleResize); |
| document.addEventListener('mouseup', this.boundStopResize); |
| |
| |
| document.addEventListener('mouseleave', this.emergencyCleanup); |
| window.addEventListener('blur', this.emergencyCleanup); |
| document.addEventListener('keydown', this.boundKeydownHandler); |
| |
| |
| this.isResizing = true; |
| this.startX = e.clientX; |
| |
| this.startWidth = this.terminalSection.offsetWidth; |
| |
| |
| this.container.classList.add('resizing'); |
| this.resizeHandle.classList.add('resizing'); |
| |
| |
| this.resizeTimeout = setTimeout(() => { |
| console.log(" Resize timeout - forcing cleanup"); |
| this.emergencyCleanup(); |
| }, 10000); |
| }); |
| } |
| |
| startResize(e) { |
| e.preventDefault(); |
| e.stopPropagation(); |
| |
| console.log(' Starting resize'); |
| |
| |
| document.addEventListener('mousemove', this.boundHandleResize); |
| document.addEventListener('mouseup', this.boundStopResize); |
| document.addEventListener('mouseleave', this.boundEmergencyCleanup); |
| window.addEventListener('blur', this.boundEmergencyCleanup); |
| |
| |
| this.isResizing = true; |
| this.startX = e.clientX; |
| this.startWidth = this.sidebar.offsetWidth; |
| |
| |
| this.container.classList.add('resizing'); |
| this.resizeHandle.classList.add('resizing'); |
| |
| |
| this.resizeTimeout = setTimeout(() => { |
| console.log(' Resize timeout - forcing cleanup'); |
| this.emergencyCleanup(); |
| }, 10000); |
| } |
| |
| handleResize(e) { |
| |
| if (!this.isResizing) return; |
| |
| e.preventDefault(); |
| |
| |
| const newWidth = this.startWidth + (e.clientX - this.startX); |
| |
| |
| const minWidth = 400; |
| const maxWidth = this.container.offsetWidth * 0.75; |
| |
| |
| if (newWidth >= minWidth && newWidth <= maxWidth) { |
| this.terminalSection.style.width = newWidth + 'px'; |
| } |
| } |
| |
| stopResize() { |
| console.log(" stopResize() called, current isResizing:", this.isResizing); |
| |
| |
| try { |
| |
| if (!this.isResizing && this.container.classList.contains('resizing')) { |
| console.log(" Found orphaned resizing class, cleaning up..."); |
| } |
| |
| |
| if (this.isResizing && window.showNotification) { |
| const currentWidth = this.terminalSection.offsetWidth; |
| window.showNotification(` ปรับขนาด Terminal เป็น ${currentWidth}px`, 'success'); |
| } |
| } catch (error) { |
| console.error("เกิดข้อผิดพลาดระหว่าง resize:", error); |
| } finally { |
| |
| console.log(" Finally block: Cleaning up resize state..."); |
| |
| this.isResizing = false; |
| |
| |
| this.container.classList.remove('resizing'); |
| this.resizeHandle.classList.remove('resizing'); |
| |
| |
| document.removeEventListener('mousemove', this.boundHandleResize); |
| document.removeEventListener('mouseup', this.boundStopResize); |
| |
| |
| document.removeEventListener('mouseleave', this.emergencyCleanup); |
| window.removeEventListener('blur', this.emergencyCleanup); |
| document.removeEventListener('keydown', this.boundKeydownHandler); |
| |
| |
| if (this.resizeTimeout) { |
| clearTimeout(this.resizeTimeout); |
| this.resizeTimeout = null; |
| } |
| |
| console.log(" Resizing stopped and ALL listeners cleaned up."); |
| } |
| } |
| } |
| |
| |
| window.resizeController = null; |
|
|
| |
| function initializeLicenseDropdown() { |
| const licenseDropdown = document.getElementById('licenseDropdown'); |
| const checkLicenseBtn = document.getElementById('checkLicenseBtn'); |
| const licenseModalOverlay = document.getElementById('licenseModalOverlay'); |
| const licenseModalCloseBtn = document.getElementById('licenseModalCloseBtn'); |
|
|
| if (licenseDropdown) { |
| const toggleBtn = licenseDropdown.querySelector('.dropdown-toggle'); |
| const menu = licenseDropdown.querySelector('.dropdown-menu'); |
|
|
| toggleBtn.addEventListener('click', (event) => { |
| event.stopPropagation(); |
| menu.classList.toggle('show'); |
| }); |
|
|
| checkLicenseBtn.addEventListener('click', (event) => { |
| event.preventDefault(); |
| checkMyLicense(); |
| menu.classList.remove('show'); |
| }); |
|
|
| |
| window.addEventListener('click', (event) => { |
| if (licenseDropdown && !licenseDropdown.contains(event.target)) { |
| menu.classList.remove('show'); |
| } |
| }); |
| } |
|
|
| |
| if (licenseModalOverlay) { |
| const closeModal = () => licenseModalOverlay.classList.remove('show'); |
| licenseModalCloseBtn.addEventListener('click', closeModal); |
| licenseModalOverlay.addEventListener('click', (event) => { |
| if (event.target === licenseModalOverlay) { |
| closeModal(); |
| } |
| }); |
| } |
|
|
| console.log(' License dropdown initialized'); |
| } |
| |
| |
| 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'); |
| }); |
| |
| |
| window.addEventListener('click', (event) => { |
| if (themeDropdown && !themeDropdown.contains(event.target)) { |
| menu.classList.remove('show'); |
| } |
| }); |
| |
| |
| const themeItems = menu.querySelectorAll('.dropdown-item'); |
| themeItems.forEach(item => { |
| item.addEventListener('click', () => { |
| menu.classList.remove('show'); |
| }); |
| }); |
| } |
| |
| console.log(' Theme dropdown initialized'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| async function showLicensePopup(title, message, type = 'info') { |
| try { |
| if (window.electronAPI && window.electronAPI.showLicensePopup) { |
| const result = await window.electronAPI.showLicensePopup(title, message, type); |
| console.log(' License popup result:', result); |
| return result; |
| } else { |
| |
| alert(`${title}\n\n${message}`); |
| return { success: true, method: 'fallback' }; |
| } |
| } catch (error) { |
| console.error(' Error showing license popup:', error); |
| alert(`Error: ${title}\n\n${message}`); |
| return { success: false, error: error.message }; |
| } |
| } |
|
|
| |
| async function showLicenseStatusPopup() { |
| try { |
| const status = await window.electronAPI.getLicenseStatus(); |
| |
| if (status && status.success) { |
| const data = status.data; |
| const message = `ประเภทไลเซนส์: ${data.type || 'ไม่ระบุ'}\n` + |
| `สถานะ: ${data.message || 'ใช้งานได้'}\n` + |
| `วันที่สร้าง: ${data.generatedAt ? new Date(data.generatedAt).toLocaleString('th-TH') : 'ไม่ระบุ'}\n` + |
| `เวลาคงเหลือ: ${data.daysRemaining > 365 ? 'ไม่จำกัด' : data.daysRemaining + ' วัน'}\n` + |
| `รหัส License: ${data.licenseId || 'AUTO-GENERATED'}`; |
| |
| await showLicensePopup(' ข้อมูลสถานะไลเซนส์', message, 'info'); |
| addTerminalLine(` License Status: ${data.type} (${data.status})`, 'success'); |
| } else { |
| await showLicensePopup(' ข้อผิดพลาดไลเซนส์', status.error || 'ไม่สามารถตรวจสอบสถานะไลเซนส์ได้', 'error'); |
| addTerminalLine(` License Error: ${status.error || 'ไม่พบ License'}`, 'error'); |
| } |
| } catch (error) { |
| await showLicensePopup(' ข้อผิดพลาดระบบ', `เกิดข้อผิดพลาดในการตรวจสอบไลเซนส์:\n${error.message}`, 'error'); |
| addTerminalLine(` ข้อผิดพลาดในการตรวจสอบ License: ${error.message}`, 'error'); |
| } |
| } |
|
|
| |
| async function showLicenseActivationHelp() { |
| const helpMessage = ` วิธีการ Activate License:\n\n` + |
| `1. ติดต่อ: chahuadev@gmail.com\n` + |
| `2. เยี่ยมชม: www.chahuadev.com\n` + |
| `3. แฟนเพจ: Chahua Development Thailand\n\n` + |
| ` สำหรับการสนับสนุนและขอไลเซนส์`; |
| |
| await showLicensePopup(' ช่วยเหลือการ Activate License', helpMessage, 'info'); |
| } |
|
|
| |
| async function testLicensePopups() { |
| console.log(' เริ่มทดสอบระบบป๊อปอัพ License...'); |
| addTerminalLine(' เริ่มทดสอบระบบป๊อปอัพ License...', 'info'); |
| |
| await showLicensePopup(' ทดสอบ Info', 'นี่คือป๊อปอัพแสดงข้อมูลทั่วไป\nระบบทำงานปกติ', 'info'); |
| |
| setTimeout(async () => { |
| await showLicensePopup(' ทดสอบ Success', 'นี่คือป๊อปอัพแสดงความสำเร็จ\nการทำงานสำเร็จลุล่วง', 'success'); |
| }, 1500); |
| |
| setTimeout(async () => { |
| await showLicensePopup(' ทดสอบ Warning', 'นี่คือป๊อปอัพแสดงคำเตือน\nกรุณาตรวจสอบระบบ', 'warning'); |
| }, 3000); |
| |
| setTimeout(async () => { |
| await showLicensePopup(' ทดสอบ Error', 'นี่คือป๊อปอัพแสดงข้อผิดพลาด\nระบบพบปัญหาบางอย่าง', 'error'); |
| addTerminalLine(' ทดสอบระบบป๊อปอัพเสร็จสิ้น', 'success'); |
| }, 4500); |
| } |
|
|
| |
| async function showLicenseSystemInfo() { |
| const systemInfo = ` Chahua License Framework v3.0\n\n` + |
| ` Integration: Chahuadev Framework\n` + |
| ` Security: Validation Gateway\n` + |
| ` Protection: Hardware Fingerprint Binding\n` + |
| ` Performance: Zero External Dependencies\n` + |
| ` Architecture: Electron + Node.js\n\n` + |
| ` Chahua Development Thailand\n` + |
| ` CEO: Saharath C.\n` + |
| ` Website: www.chahuadev.com\n` + |
| ` Email: chahuadev@gmail.com`; |
| |
| await showLicensePopup(' ข้อมูลระบบ License Framework', systemInfo, 'info'); |
| } |
|
|
| |
| function showDeveloperLicenseMenu() { |
| const choice = prompt(` Developer License Tools:\n\n` + |
| `1. ทดสอบป๊อปอัพทุกประเภท\n` + |
| `2. แสดงข้อมูลระบบ License\n` + |
| `3. ตรวจสอบสถานะ License (Popup)\n` + |
| `4. แสดงช่วยเหลือ Activation\n\n` + |
| `เลือกหมายเลข (1-4):`); |
| |
| switch(choice) { |
| case '1': |
| testLicensePopups(); |
| break; |
| case '2': |
| showLicenseSystemInfo(); |
| break; |
| case '3': |
| showLicenseStatusPopup(); |
| break; |
| case '4': |
| showLicenseActivationHelp(); |
| break; |
| default: |
| if (choice !== null) { |
| alert(' กรุณาเลือกหมายเลข 1-4'); |
| } |
| } |
| } |
|
|
| |
| async function checkMyLicense() { |
| |
| await showLicenseStatusPopup(); |
| } |
|
|
| |
| document.addEventListener('DOMContentLoaded', () => { |
| const logPanel = document.getElementById('log-viewer'); |
| const marketplacePanel = document.getElementById('marketplace-webview'); |
|
|
| |
| const marketplaceUrl = 'https://chahuadev.com'; |
|
|
| let isMarketplaceLoaded = false; |
|
|
| function switchView(viewToShow) { |
| |
| document.querySelectorAll('.view-panel').forEach(p => p.classList.remove('active')); |
| document.querySelectorAll('.view-btn').forEach(b => b.classList.remove('active')); |
|
|
| |
| if (viewToShow === 'log') { |
| if (logPanel) logPanel.classList.add('active'); |
| } else if (viewToShow === 'marketplace') { |
| if (marketplacePanel) marketplacePanel.classList.add('active'); |
|
|
| |
| if (!isMarketplaceLoaded && marketplacePanel) { |
| addTerminalLine(`กำลังเชื่อมต่อกับร้านค้าที่ ${marketplaceUrl}...`, 'command'); |
| marketplacePanel.src = marketplaceUrl; |
| isMarketplaceLoaded = true; |
|
|
| marketplacePanel.addEventListener('did-finish-load', () => { |
| addTerminalLine(' เชื่อมต่อร้านค้าสำเร็จ!', 'success'); |
| }); |
| marketplacePanel.addEventListener('did-fail-load', (error) => { |
| addTerminalLine(` ไม่สามารถเชื่อมต่อร้านค้าได้: ${error.errorDescription}`, 'error'); |
| }); |
| } |
| } |
| } |
|
|
| |
| window.switchView = switchView; |
| }); |
|
|
| |
| window.addEventListener('beforeunload', () => { |
| if (window.electronAPI && window.electronAPI.removeBuildLogListeners) { |
| window.electronAPI.removeBuildLogListeners(); |
| } |
| }); |
|
|
|
|