Skip to content

Commit

Permalink
Add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
supechicken authored May 1, 2021
1 parent c8de7ee commit b0a85fa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions onstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chrome.runtime.onStartup.addListener(function() {
chrome.windows.create({url: "/run.html", type: 'popup', state: 'minimized'})
});
chrome.runtime.onInstalled.addListener(function(i) {
if (i.reason == 'install') {
chrome.windows.create({url: '/option.html', type: 'popup'})
}})
5 changes: 5 additions & 0 deletions run.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- run.html: wrapper for run.js -->

<html>
<script src='/run.js'></script>
</html>
31 changes: 31 additions & 0 deletions run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// run.js: execute command set in option page

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!") }

chrome.terminalPrivate.sendInput(pid, '\n\nshell\n\nexport PS1="$ "\n\n');
chrome.terminalPrivate.sendInput(pid,
// prevent unexpected newline
`\n\nsh -c "$(tr -d '\n' <<< '${cmd.start}')"\n`
);
});

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);
}
});
});

0 comments on commit b0a85fa

Please sign in to comment.