Skip to content

Commit

Permalink
Update run.js
Browse files Browse the repository at this point in the history
  • Loading branch information
supechicken authored Nov 30, 2021
1 parent e3bb7aa commit 2e810ea
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@

chrome.storage.local.get('debug', (debug) => {
chrome.storage.local.get('start', (cmd) => {
chrome.terminalPrivate.onProcessOutput.addListener(processListener);
// open a terminal
chrome.terminalPrivate.openTerminalProcess('crosh', (pid) => {
if (pid < 0) { alert('Error: cannot open crosh!') }
chrome.terminalPrivate.onProcessOutput.addListener( (pid, type, output) => {
// print terminal output in console
if (output.split("\n").includes("__ext_close__\r") && !debug.debug) {
// close terminal process
chrome.terminalPrivate.closeTerminalProcess(pid);

chrome.terminalPrivate.sendInput(pid, 'shell\n');
chrome.terminalPrivate.sendInput(pid,
// prevent unexpected newline
`exec nohup bash <<_CMD_\n${cmd.start}\n_CMD_\n`
);
// close self after sending commands to terminal
chrome.windows.getCurrent( (window) => {
chrome.windows.remove(window.id);
});
}
console.log(output);
});

function processListener(pid, type, output) {
// print terminal output in console
console.log(output);
}

// close self after sending commands to terminal
if (!debug.debug) {
setTimeout( () => {
chrome.windows.getCurrent( (window) => {
chrome.windows.remove(window.id)
} )
}, 1000);
}
// open a terminal process
chrome.terminalPrivate.openTerminalProcess('crosh', (pid) => {
if (pid < 0) { alert('Error: cannot open crosh!'); }
chrome.terminalPrivate.sendInput(pid, 'shell\n');
chrome.terminalPrivate.sendInput(pid, `nohup bash <<_CMD_&\n${cmd.start}\n_CMD_\n`); // prevent unexpected newline
chrome.terminalPrivate.sendInput(pid, 'echo "__ext_close__"\n');
});
});
});

0 comments on commit 2e810ea

Please sign in to comment.