Created
July 28, 2020 03:55
-
-
Save usagi/913f6ae1c9905c77508f9864d469d835 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<title>Issue-#17 repro.</title> | |
<div> | |
<div>test-result = <span id="test-result">????</span></div> | |
<div>exception: <pre id="test-exception">(No exceptions.)</pre></div> | |
</div> | |
<hr /> | |
<aside> | |
<ul> | |
<li>Node.js = <span id="misc-node">????</span></li> | |
<li>Chrome = <span id="misc-chrome">????</span></li> | |
<li>Electron = <span id="misc-electron">????</span></li> | |
</ul> | |
</aside> | |
<script src="./renderer.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { app, BrowserWindow } = require("electron"); | |
const path = require("path"); | |
function createWindow() { | |
const mainWindow = new BrowserWindow({ | |
width: 1920>>1, | |
height: 1080>>1, | |
webPreferences: { | |
preload: path.join(__dirname, "preload.js"), | |
}, | |
}); | |
mainWindow.loadFile("index.html"); | |
} | |
app.whenReady().then(() => { | |
createWindow(); | |
app.on("activate", function () { | |
if (BrowserWindow.getAllWindows().length === 0) createWindow(); | |
}); | |
}); | |
app.on("window-all-closed", function () { | |
if (process.platform !== "darwin") app.quit(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener("DOMContentLoaded", () => { | |
const replaceText = (selector, text) => { | |
const element = document.getElementById(selector); | |
if (element) element.innerText = text; | |
}; | |
try { | |
const from_rust = require("./dist/index.node"); | |
replaceText("test-result", from_rust.sum(123, 456)); | |
replaceText("test-exception", "(No exceptions. It works good, maybe.)"); | |
} catch (e) { | |
replaceText("test-exception", e); | |
} | |
for (const type of ["chrome", "node", "electron"]) { | |
replaceText(`misc-${type}`, process.versions[type]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment