From c6d9bba8379349b9a3f0a0a08133b00e3b731902 Mon Sep 17 00:00:00 2001 From: kimsseTheWolf Date: Mon, 8 Jan 2024 11:07:16 -0500 Subject: [PATCH] Executor Update and Github CI/CD Update --- .github/workflows/auto_build.yaml | 4 +-- .gitignore | 3 +- assets/execute.svg | 1 + index.html | 4 +++ main.js | 57 +++++++++++++++++++++++++++++++ renderer.js | 24 +++++++++++++ shellExecutor.html | 34 ++++++++++++++++++ shellExecutor.js | 11 ++++++ 8 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 assets/execute.svg create mode 100644 shellExecutor.html create mode 100644 shellExecutor.js diff --git a/.github/workflows/auto_build.yaml b/.github/workflows/auto_build.yaml index f572606..81fc365 100644 --- a/.github/workflows/auto_build.yaml +++ b/.github/workflows/auto_build.yaml @@ -30,7 +30,7 @@ jobs: id: create_release uses: actions/create-release@v1 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} with: tag_name: ${{ steps.get_version.outputs.VERSION }} release_name: Release ${{ steps.get_version.outputs.VERSION }} @@ -41,7 +41,7 @@ jobs: id: upload_release_asset uses: actions/upload-release-asset@v1 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ./dist/your-app-setup-${{ steps.get_version.outputs.VERSION }}.exe diff --git a/.gitignore b/.gitignore index 8f9d799..c462f9f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/* -dist/* \ No newline at end of file +dist/* +a.exe diff --git a/assets/execute.svg b/assets/execute.svg new file mode 100644 index 0000000..eb90a1a --- /dev/null +++ b/assets/execute.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/index.html b/index.html index 595f2b1..5e17e96 100644 --- a/index.html +++ b/index.html @@ -53,6 +53,10 @@
+
+ +
Run
+
Row: 0, Column: 0
diff --git a/main.js b/main.js index 9a6ca2f..b3100a9 100644 --- a/main.js +++ b/main.js @@ -126,6 +126,63 @@ app.on('ready', () => { }); }) + // execute the code + ipcMain.on("execute-code", (event, lang, fileLoc) => { + const outputWindow = new BrowserWindow({ + webPreferences: { + preload: path.join(__dirname, 'preload.js'), + contextIsolation: false, + }, + width: 1000, + height: 600, + autoHideMenuBar: true, + icon: path.join(__dirname, 'icon.ico') + }); + outputWindow.loadFile('shellExecutor.html'); + event.reply("executing-code"); + let command = ""; + if (lang === "python") { + command = `python "${fileLoc}"`; + } + else if (lang === "javascript") { + command = `node "${fileLoc}"`; + } + else if (lang === "cpp") { + command = `gcc "${fileLoc}" -o "${fileLoc}.exe" && "${fileLoc}.exe"`; + } + else if (lang === "java") { + command = `javac "${fileLoc}" && java "${fileLoc}"`; + } + else { + event.reply("code-executed", undefined); + } + + const commandProcess = exec(command, (err, stdout, stderr) => { + if (err) { + console.log(err); + event.reply("code-executed", err); + } + }); + + commandProcess.stdout.on('data', (data) => { + console.log(data); + outputWindow.webContents.send("output", data.toString()); + }); + + commandProcess.stderr.on('data', (data) => { + console.log(data); + outputWindow.webContents.send("output", data.toString()); + }); + + commandProcess.on('close', (code) => { + event.reply("code-executed", code); + }); + + ipcMain.on("input", (event, data) => { + commandProcess.stdin.write(data + "\n"); + }); + }); + }); app.on('window-all-closed', function () { diff --git a/renderer.js b/renderer.js index 8065426..1ec9038 100644 --- a/renderer.js +++ b/renderer.js @@ -3,6 +3,7 @@ let editor; let currentFilePath; let client; let isSaved = false; +let isExecutingCode = false; let currentTextSize = 16; const defaultTheme = { @@ -408,6 +409,11 @@ require(['vs/editor/editor.main'], function() { document.getElementById("pathDisplay").innerText = fileName; }); + window.ipcRenderer.on("code-executed", (event) => { + setExecutionStatus(false); + isExecutingCode = false; + }); + document.getElementById('textSize').textContent = currentTextSize; }); @@ -472,6 +478,23 @@ function openWithCode() { window.ipcRenderer.send("open-with-code", currentFilePath); } +function setExecutionStatus(status) { + if (status) { + document.getElementById("footerMenu").style.backgroundColor = "dodgerblue"; + } + else { + document.getElementById("footerMenu").style.backgroundColor = "rgba(0,0,0,0)"; + } +} + +function executeCode() { + if (currentFilePath !== undefined && !isExecutingCode) { + let selectedLang = document.getElementById("language").value; + window.ipcRenderer.send("execute-code", selectedLang, currentFilePath); + setExecutionStatus(true); + } +} + document.getElementById("pathDisplay").innerText = currentFilePath; document.getElementById('openFileButton').addEventListener('click', openFile); @@ -481,6 +504,7 @@ document.getElementById('renameFileButton').addEventListener('click', renameFile document.getElementById('increaseFontSizeButton').addEventListener('click', increaseTextSize); document.getElementById('decreaseFontSizeButton').addEventListener('click', decreaseTextSize); document.getElementById('openWithCode').addEventListener('click', openWithCode); +document.getElementById('execBtn').addEventListener('click', executeCode); window.addEventListener('resize', function () { editor.layout(); diff --git a/shellExecutor.html b/shellExecutor.html new file mode 100644 index 0000000..c03c56a --- /dev/null +++ b/shellExecutor.html @@ -0,0 +1,34 @@ + + + + + + SnapCode Terminal + + + +
+ + + + \ No newline at end of file diff --git a/shellExecutor.js b/shellExecutor.js new file mode 100644 index 0000000..420d836 --- /dev/null +++ b/shellExecutor.js @@ -0,0 +1,11 @@ + +window.ipcRenderer.on("output", (event, data) => { + document.getElementById("output").textContent += (data + "\n"); +}) + +document.getElementById("input").addEventListener("keypress", (event) => { + if (event.key === "Enter") { + window.ipcRenderer.send("input", document.getElementById("input").value); + document.getElementById("input").value = ""; + } +})