| 378 | } |
| 379 | |
| 380 | std::string getJavaScript() |
| 381 | { |
| 382 | return R"JS( |
| 383 | let autoUpdateInterval = null; |
| 384 | |
| 385 | async function getSystemInfo() { |
| 386 | try { |
| 387 | const info = await cpp_getSystemInfo(); |
| 388 | const infoDiv = document.getElementById ('systemInfo'); |
| 389 | infoDiv.className = 'info-box success'; |
| 390 | infoDiv.textContent = `Platform: ${info.platform} |
| 391 | Timestamp: ${info.timestamp} |
| 392 | Features: ${info.features.join (', ')}`; |
| 393 | } catch(error) { |
| 394 | showError ('systemInfo', 'Failed to get system info: ' + error.message); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | async function getCurrentTime() { |
| 399 | try { |
| 400 | const time = await cpp_getCurrentTime(); |
| 401 | const timeDiv = document.getElementById ('timeDisplay'); |
| 402 | timeDiv.className = 'info-box success'; |
| 403 | const date = new Date (parseInt (time) * 1000); |
| 404 | timeDiv.textContent = `Current time: ${date.toLocaleString()} |
| 405 | Unix timestamp: ${time}`; |
| 406 | } catch(error) { |
| 407 | showError ('timeDisplay', 'Failed to get current time: ' + error.message); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | async function calculate() { |
| 412 | try { |
| 413 | const num1 = parseFloat (document.getElementById ('num1').value) || 0; |
| 414 | const operation = document.getElementById ('operation').value; |
| 415 | const num2 = parseFloat (document.getElementById ('num2').value) || 0; |
| 416 | |
| 417 | const result = await cpp_calculate (num1, operation, num2); |
| 418 | const resultDiv = document.getElementById ('calcResult'); |
| 419 | resultDiv.className = 'info-box success'; |
| 420 | resultDiv.textContent = `${result.expression} = ${result.value}`; |
| 421 | } catch(error) { |
| 422 | showError ('calcResult', 'Calculation failed: ' + error.message); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | async function sendAlert() { |
| 427 | try { |
| 428 | const message = document.getElementById ('alertMessage').value || 'Hello from JavaScript!'; |
| 429 | await cpp_showAlert ([message]); |
| 430 | |
| 431 | // Show confirmation in the UI |
| 432 | const alertSection = document.querySelector ('input#alertMessage').parentElement; |
| 433 | const feedback = document.createElement ('div'); |
| 434 | feedback.className = 'info-box success'; |
| 435 | feedback.textContent = `Alert sent to C++: "${message}"`; |
| 436 | feedback.style.marginTop = '10px'; |
| 437 |
nothing calls this directly
no outgoing calls
no test coverage detected