Skip to content

Instantly share code, notes, and snippets.

@ckerr
Created December 3, 2020 18:23
Show Gist options
  • Save ckerr/43138b431ecca2472b9ed42bcdb186f3 to your computer and use it in GitHub Desktop.
Save ckerr/43138b431ecca2472b9ed42bcdb186f3 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Electron test</title>
<style>
html, body {
margin: 0;
padding: 0;
}
div {
background-color: blue;
}
div:hover {
background-color: #fff;
}
</style>
</head>
<body>
<div title="Some title">Some element</div>
</body>
</html>
// main.js
const { app, BrowserWindow } = require('electron')
function createWindow() {
// Required frame and resizable options to reproduce this behavior
const win = new BrowserWindow({
frame: false,
resizable: false,
webPreferences: {
nodeIntegration: true,
},
})
win.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()
})
{
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"repository": "https://github.com/electron/electron-quick-start",
"keywords": [
"Electron",
"quick",
"start",
"tutorial",
"demo"
],
"author": "GitHub",
"license": "CC0-1.0",
"devDependencies": {
"electron": "^11.0.3"
}
}
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
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 is required by 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. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment