Skip to content

Instantly share code, notes, and snippets.

@jrieken
Last active May 27, 2019 12:55
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 jrieken/3d4909b7a1fc1664b962fb108de2d150 to your computer and use it in GitHub Desktop.
Save jrieken/3d4909b7a1fc1664b962fb108de2d150 to your computer and use it in GitHub Desktop.
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