Created
March 26, 2019 21:35
-
-
Save folksilva/81f4956655cd6245717f9bb4292f8e57 to your computer and use it in GitHub Desktop.
Iteração da página web remota com o Electron
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
// 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!'; | |
} |
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
<!-- | |
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