Last active
October 26, 2022 15:50
-
-
Save rudifa/ef8e02dc7518ae5af1541591a557215e to your computer and use it in GitHub Desktop.
A variant of DOCS/FIDDLES/TUTORIAL-PRELOAD (21.2.0)
This file contains hidden or 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
// 1. in preload, the contextBridge exposes a copy of a process variable for info | |
// 2. the renderer inserts the info into the view |
This file contains hidden or 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> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta | |
http-equiv="Content-Security-Policy" | |
content="default-src 'self'; script-src 'self'" | |
/> | |
<meta | |
http-equiv="X-Content-Security-Policy" | |
content="default-src 'self'; script-src 'self'" | |
/> | |
<title>Hello from Electron renderer!</title> | |
</head> | |
<body> | |
<h1>Hello from Electron renderer!</h1> | |
<p>👋</p> | |
<p id="info"></p> | |
</body> | |
<script src="./renderer.js"></script> | |
</html> |
This file contains hidden or 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'); | |
const createWindow = () => { | |
const win = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js'), | |
}, | |
}); | |
win.loadFile('index.html'); | |
}; | |
app.whenReady().then(() => { | |
createWindow(); | |
app.on('activate', () => { | |
if (BrowserWindow.getAllWindows().length === 0) { | |
createWindow(); | |
} | |
}); | |
}); | |
app.on('window-all-closed', () => { | |
if (process.platform !== 'darwin') { | |
app.quit(); | |
} | |
}); |
This file contains hidden or 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
{ | |
"name": "five-chocolate-verify-9v1cn", | |
"productName": "five-chocolate-verify-9v1cn", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "rudifarkas", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "21.2.0" | |
} | |
} |
This file contains hidden or 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
// 1. in preload, the contextBridge exposes a copy of a process variable for info | |
const { contextBridge } = require('electron'); | |
contextBridge.exposeInMainWorld('versions', { | |
versions: () => process.versions | |
}); |
This file contains hidden or 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
// 2. the renderer inserts the info into the view | |
const information = document.getElementById('info'); | |
const {chrome, node, electron} = versions.versions() | |
information.innerText = `This app is using Chrome (v${chrome}), Node.js (v${node}), and Electron (v${electron})`; |
This file contains hidden or 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
/* styles.css */ | |
/* Add styles here to customize the appearance of your app */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment