Skip to content

Commit

Permalink
Executor Update and Github CI/CD Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsseTheWolf committed Jan 8, 2024
1 parent 09de659 commit c6d9bba
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/auto_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/*
dist/*
dist/*
a.exe
1 change: 1 addition & 0 deletions assets/execute.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<div class="button" id="decreaseFontSizeButton">
<img src="assets/minus-bold.svg" width="16px" height="16px"/>
</div>
<div class="button" id="execBtn">
<img src="assets/execute.svg" width="16px" height="16px" style="margin-right: 5px;"/>
<div>Run</div>
</div>
</div>
<div id="cursorPosition" style="font-size: small;">Row: 0, Column: 0</div>
</div>
Expand Down
57 changes: 57 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
24 changes: 24 additions & 0 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let editor;
let currentFilePath;
let client;
let isSaved = false;
let isExecutingCode = false;
let currentTextSize = 16;

const defaultTheme = {
Expand Down Expand Up @@ -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;
});

Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
34 changes: 34 additions & 0 deletions shellExecutor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SnapCode Terminal</title>
</head>
<script src="shellExecutor.js"></script>
<body>
<div id="output"></div>
<input type="text" id="input" placeholder="Input everything here...">
</body>
<style>
body {
display: flex;
flex-direction: column;
margin: 0px;
padding: 15px;
background-color: #252b30;
color: white;
font-family: consolas, monospace;
font-size: 14px;
}
#input {
margin-top: 10px;
background-color: #252b30;
color: white;
border: none;
outline: none;
font-family: consolas, monospace;
font-size: 14px;
}
</style>
</html>
11 changes: 11 additions & 0 deletions shellExecutor.js
Original file line number Diff line number Diff line change
@@ -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 = "";
}
})

0 comments on commit c6d9bba

Please sign in to comment.