Skip to content

Instantly share code, notes, and snippets.

@erickzhao
Created April 2, 2020 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erickzhao/4ebfa3b722fbd39f9eb11456d9c513ae to your computer and use it in GitHub Desktop.
Save erickzhao/4ebfa3b722fbd39f9eb11456d9c513ae to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
</body>
</html>
// Modules to control application life and create native browser window
const { app, BrowserWindow, Notification, ipcMain } = require('electron')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
}
ipcMain.on('notification', () => {
const n = new Notification({
title: "Notification",
body: "Not blocked by alert!"
});
n.show()
})
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
const { ipcRenderer } = require('electron')
ipcRenderer.send('notification')
alert('I am an alert.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment