-
-
Save marekharanczyk/eec01457cf39fb999b6e6ce775912476 to your computer and use it in GitHub Desktop.
EventEmitter properties test
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"> | |
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | |
<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>EventEmitter properties test</title> | |
</head> | |
<body> | |
</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
// Modules to control application life and create native browser window | |
const { app, BrowserWindow, ipcMain } = require('electron') | |
const path = require('path') | |
function createWindow () { | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
mainWindow.loadFile('index.html') | |
} | |
app.whenReady().then(() => { | |
ipcMain.on('dump-properties', (event) => { | |
const { EventEmitter } = require('events') | |
const emitter = new EventEmitter() | |
let properties = "" | |
currentObj = emitter | |
do { | |
Object.getOwnPropertyNames(currentObj).map(item => properties += item + ';') | |
} while ((currentObj = Object.getPrototypeOf(currentObj))) | |
event.sender.send('properties-dump-browser', properties) | |
}) | |
createWindow() | |
app.on('activate', function () { | |
if (BrowserWindow.getAllWindows().length === 0) createWindow() | |
}) | |
}) | |
app.on('window-all-closed', function () { | |
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": "dispensable-vest-convince-6ejhb", | |
"productName": "dispensable-vest-convince-6ejhb", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "Markus", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron-nightly": "22.0.0-nightly.20220830" | |
} | |
} |
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 { EventEmitter } = require('events') | |
const emitter = new EventEmitter() | |
let properties = "" | |
currentObj = emitter | |
do { | |
Object.getOwnPropertyNames(currentObj).map(item => properties += item + ';') | |
} while ((currentObj = Object.getPrototypeOf(currentObj))) | |
console.log(properties) | |
const { ipcRenderer } = require('electron') | |
ipcRenderer.send('dump-properties') | |
ipcRenderer.on('properties-dump-browser', (event, dump) => { | |
console.log(dump) | |
console.log(dump === properties) | |
window.document.body.style.background = dump === properties ? 'green' : 'red'; | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment