// renderer.js const { ipcRenderer } = require('electron'); document.getElementById('btnSelect').addEventListener('click', async () => { console.log('🟢 clicked select'); // Debug const filePath = await ipcRenderer.invoke('select-file'); console.log('📁 File selected:', filePath); if (filePath) document.getElementById('filePath').value = filePath; }); document.getElementById('btnRun').addEventListener('click', async () => { const filePath = document.getElementById('filePath').value; const mode = document.getElementById('mode').value; if (!filePath) { document.getElementById('status').innerText = '⚠️ กรุณาเลือกไฟล์ Excel ก่อน'; return; } document.getElementById('status').innerText = 'กำลังประมวลผล...'; try { const resultMessage = await ipcRenderer.invoke('run-script', { script: mode, filePath }); // ตรวจสอบข้อความที่ส่งกลับมาจาก main process if (resultMessage === 'ยกเลิกการบันทึก') { document.getElementById('status').innerText = 'สถานะ: ยกเลิกโดยผู้ใช้'; } else { document.getElementById('status').innerText = `✅ ${resultMessage}`; // แสดงข้อความสำเร็จที่ได้รับ } } catch (err) { document.getElementById('status').innerText = '❌ เกิดข้อผิดพลาด: ' + err; } });