From 2b3d1e0d066485fcb99d4b14cb3ee1446ffe1ad4 Mon Sep 17 00:00:00 2001 From: pradeepkumara Date: Wed, 11 Dec 2024 22:52:12 +1100 Subject: [PATCH 1/4] Add "End Program" Function-pradeep --- Browser_IDE/executionEnvironment.js | 31 ++++++++++++++++++++++++++++- Browser_IDE/index.html | 8 ++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Browser_IDE/executionEnvironment.js b/Browser_IDE/executionEnvironment.js index 50e7b942..51bbd0e7 100644 --- a/Browser_IDE/executionEnvironment.js +++ b/Browser_IDE/executionEnvironment.js @@ -312,4 +312,33 @@ class ExecutionEnvironment extends EventTarget{ return iframe; } -} \ No newline at end of file +} + +document.getElementById("stopProgram").addEventListener("click", () => { + terminateProgram(); +}); + +document.getElementById("collapsedStopProgram").addEventListener("click", () => { + terminateProgram(); +}); + +function terminateProgram() { + if (!isProgramRunning()) return; + + try { + // Logic to terminate the running process + runtimeManager.terminate(); + showNotification("Program stopped successfully.", "info"); + updateRuntimeButtons(false); // Disable runtime buttons + } catch (error) { + console.error("Failed to stop the program:", error); + showNotification("Failed to stop the program. Please try again.", "error"); + } +} + +function updateRuntimeButtons(isRunning) { + const stopButton = document.getElementById("stopProgram"); + const collapsedStopButton = document.getElementById("collapsedStopProgram"); + stopButton.disabled = !isRunning; + collapsedStopButton.disabled = !isRunning; +} diff --git a/Browser_IDE/index.html b/Browser_IDE/index.html index 4571c577..77821f26 100644 --- a/Browser_IDE/index.html +++ b/Browser_IDE/index.html @@ -100,6 +100,14 @@

Let's write some code!

Build and Run + + +
From 463e63512e4269b0efd1894fd356033380b3c769 Mon Sep 17 00:00:00 2001 From: pradeepkumara Date: Sat, 14 Dec 2024 22:04:13 +1100 Subject: [PATCH 2/4] added error handling -pradep --- Browser_IDE/executionEnvironment.js | 81 +++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 10 deletions(-) diff --git a/Browser_IDE/executionEnvironment.js b/Browser_IDE/executionEnvironment.js index 51bbd0e7..93e34b39 100644 --- a/Browser_IDE/executionEnvironment.js +++ b/Browser_IDE/executionEnvironment.js @@ -322,23 +322,84 @@ document.getElementById("collapsedStopProgram").addEventListener("click", () => terminateProgram(); }); -function terminateProgram() { - if (!isProgramRunning()) return; +// Attach event listeners for Stop buttons +initializeEventListeners(); + +function initializeEventListeners() { + const stopButton = document.getElementById("stopProgram"); + const collapsedStopButton = document.getElementById("collapsedStopProgram"); + + stopButton.addEventListener("click", handleStopProgram); + collapsedStopButton.addEventListener("click", handleStopProgram); +} + +/** + * Handles the stop button click event + */ +function handleStopProgram() { + if (!isProgramRunning()) { + showNotification("No program is currently running.", "warning"); + return; + } try { - // Logic to terminate the running process - runtimeManager.terminate(); + terminateProgram(); showNotification("Program stopped successfully.", "info"); - updateRuntimeButtons(false); // Disable runtime buttons } catch (error) { - console.error("Failed to stop the program:", error); + console.error("Error while stopping the program:", error); showNotification("Failed to stop the program. Please try again.", "error"); } } +/** + * Terminates the currently running program + */ +function terminateProgram() { + try { + // Logic to terminate the running process + runtimeManager.terminate(); + updateRuntimeButtons(false); // Disable runtime buttons after stopping + } catch (error) { + throw new Error("Program termination failed: " + error.message); + } +} + +/** + * Updates the runtime control buttons based on the program state + * @param {boolean} isRunning - Whether the program is currently running + */ function updateRuntimeButtons(isRunning) { - const stopButton = document.getElementById("stopProgram"); - const collapsedStopButton = document.getElementById("collapsedStopProgram"); - stopButton.disabled = !isRunning; - collapsedStopButton.disabled = !isRunning; + toggleButtonState("stopProgram", isRunning); + toggleButtonState("collapsedStopProgram", isRunning); +} + +/** + * Toggles the disabled state of a button + * @param {string} buttonId - The ID of the button to toggle + * @param {boolean} isEnabled - Whether the button should be enabled + */ +function toggleButtonState(buttonId, isEnabled) { + const button = document.getElementById(buttonId); + if (button) { + button.disabled = !isEnabled; + } +} + +/** + * Checks if a program is currently running + * @returns {boolean} - True if a program is running, false otherwise + */ +function isProgramRunning() { + // Replace this with the actual logic to check program state + return runtimeManager.isRunning(); +} + +/** + * Displays a notification to the user + * @param {string} message - The message to display + * @param {string} type - The type of the notification ("info", "warning", "error") + */ +function showNotification(message, type) { + // Replace this with your actual notification logic + console.log(`[${type.toUpperCase()}] ${message}`); } From 7c4700125600f9492cbbca6202f8e6717ae9b415 Mon Sep 17 00:00:00 2001 From: pradeepkumara Date: Sat, 21 Dec 2024 16:07:23 +1100 Subject: [PATCH 3/4] Terminate and stop funtion --- Browser_IDE/editorMain.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Browser_IDE/editorMain.js b/Browser_IDE/editorMain.js index b6b2c832..84b06d38 100644 --- a/Browser_IDE/editorMain.js +++ b/Browser_IDE/editorMain.js @@ -809,15 +809,18 @@ async function pauseProgram(){ } } -async function stopProgram(){ +async function stopProgram() { try { await executionEnviroment.stopProgram(); - } - catch (err) { - displayEditorNotification("Failed to stop program!", NotificationIcons.ERROR); + await executionEnviroment.cleanEnvironment(); // Clear resources or locks + displayEditorNotification("Program has been stopped successfully.", NotificationIcons.INFO); + } catch (err) { + displayEditorNotification("Failed to stop program!
" + err.toString(), NotificationIcons.ERROR); } } + + async function restartProgram(){ clearErrorLines(); From 7a55d22e8eee429ffb429055ee47c21615770c65 Mon Sep 17 00:00:00 2001 From: pradeepkumara Date: Sat, 21 Dec 2024 16:12:15 +1100 Subject: [PATCH 4/4] terminate function --- Browser_IDE/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Browser_IDE/index.html b/Browser_IDE/index.html index 77821f26..994bd8c8 100644 --- a/Browser_IDE/index.html +++ b/Browser_IDE/index.html @@ -105,7 +105,7 @@

Let's write some code!

Stop