Skip to content

Instantly share code, notes, and snippets.

@folksilva
Created March 26, 2019 21:35
Show Gist options
  • Save folksilva/81f4956655cd6245717f9bb4292f8e57 to your computer and use it in GitHub Desktop.
Save folksilva/81f4956655cd6245717f9bb4292f8e57 to your computer and use it in GitHub Desktop.
Iteração da página web remota com o Electron
// main.js - Arquivo principal do electron
// executado via npm start
const { app, BrowserWindow } = require('electron')
function createWindow () {
let win = new BrowserWindow({width: 800, height: 600})
win.loadURL("http://localhost:8000/teste.html")
}
app.on("ready", createWindow)
app.teste = function(msg) {
console.log(msg);
return 'Funcionando do Electron!';
}
<!--
Pagina externa de exemplo.
Possível rodar com o Python3: python -m http.server 8000
-->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Teste</title>
</head>
<body>
<output id="output"></output>
<script>
if (typeof require !== 'undefined') {
const {remote} = require('electron');
document.getElementById('output').innerHTML = remote.app.teste('Ola!');
} else {
document.getElementById('output').innerHTML = 'Funcionando da web!';
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment