Skip to content

Instantly share code, notes, and snippets.

@jrieken
Last active May 27, 2019
Embed
What would you like to do?
Electron Fiddle - Timer
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h3>Versions</h3>
<!-- 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>,
Electron <script>document.write(process.versions.electron)</script>,
and V8 <script>document.write(process.versions.v8)</script>
<h3>Times</h3>
<pre id="timers"></pre>
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
</body>
</html>
const marks = [];
marks.push('appStarted', Date.now());
const { join } = require('path');
const { app, BrowserWindow } = require('electron')
let mainWindow
function createWindow() {
marks.push('appReady', Date.now());
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: { nodeIntegration: true }
})
marks.push('pageLoad', Date.now());
mainWindow.loadURL(`file:///${join(__dirname, 'index.html')}?${encodeURIComponent(JSON.stringify(marks))}`);
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
})
const data = JSON.parse(decodeURIComponent(window.location.search.slice(1)));
data.push('pageReady', Date.now());
let value = '';
for (let i = 2; i < data.length; i += 2) {
value += `${data[i - 2]} -> ${data[i]}: ${data[i + 1] - data[1]}ms (+${data[i + 1] - data[i - 1]}ms)\n`;
}
document.getElementById('timers').innerText = value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment