48
loading...
This website collects cookies to deliver better user experience
nodeIntegration
and contextIsolation
:let { app, BrowserWindow } = require("electron")
function createWindow() {
let win = new BrowserWindow({
height: 600,
width: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
})
win.loadFile(`${__dirname}/public/index.html`)
}
app.on("ready", createWindow)
app.on("window-all-closed", () => {
app.quit()
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ruby Opal Application</title>
<link href="app.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Very amazing terminal app</h1>
<div id="terminal">
<div id="history">
</div>
<div class="input-line">
<span class="prompt">$</span>
<form>
<input type="text" autofocus />
</form>
</div>
</div>
<script src="./build/app.js"></script>
</body>
</html>
body {
background-color: #444;
color: #fff;
}
h1 {
font-family: monospace;
}
#terminal {
font-family: monospace;
}
.input-line {
display: flex;
}
.input-line > * {
flex: 1;
}
.input-line > .prompt {
flex: 0;
padding-right: 0.5rem;
}
.output {
padding-bottom: 0.5rem;
}
.input {
color: #ffa;
}
.output {
color: #afa;
white-space: pre;
}
form {
display: flex;
}
input {
flex: 1;
font-family: monospace;
background-color: #444;
color: #fff;
border: none;
}
require "native"
ChildProcess = Native(`require("child_process")`)
def element(query)
$$.document.querySelector(query)
end
def create_element(tag, className=nil, children=[])
el = $$.document.createElement(tag)
el.className = className if className
children.each do |child|
el.append child
end
el
end
def create_input_line(command)
create_element("div", "input-line", [
create_element("span", "prompt", ["$"]),
create_element("span", "input", [command])
])
end
def create_terminal_history_entry(command, output)
terminal_history = element("#history")
terminal_history.append(create_input_line(command))
terminal_history.append(
create_element("div", "output", [output])
)
end
element("form").addEventListener("submit") do |e|
Native(e).preventDefault
input = element("input")
command = input.value
output = ChildProcess.execSync(command).toString
create_terminal_history_entry(command, output)
input.value = ""
input.scrollIntoView
end
instance_eval
on Native
object, and that silently didn't work), and you pretty much need to understand Opal Ruby internals to figure things out. Source maps still pointed to incorrect places.