Created
February 5, 2025 01:21
-
-
Save NgocHaiSE/7c9174d8f0b99fcce1a643c9443909d3 to your computer and use it in GitHub Desktop.
Electron Fiddle
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> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" /> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
<p> | |
We are using Node.js <span id="node-version"></span>, | |
Chromium <span id="chrome-version"></span>, | |
and Electron <span id="electron-version"></span>. | |
</p> | |
</body> | |
</html> |
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/main') | |
const path = require('node:path') | |
function 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 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": "evanescent-analyst-contract-18hgz", | |
"productName": "evanescent-analyst-contract-18hgz", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "ProDHai", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "34.0.2" | |
} | |
} |
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 | |
} | |
for (const type of ['chrome', 'node', 'electron']) { | |
replaceText(`${type}-version`, process.versions[type]) | |
} | |
}) |
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
/** | |
* This file is loaded via the <script> tag in the index.html file and will | |
* be executed in the renderer process for that window. No Node.js APIs are | |
* available in this process because `nodeIntegration` is turned off and | |
* `contextIsolation` is turned on. Use the contextBridge API in `preload.js` | |
* to expose Node.js functionality from the main process. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment