Skip to content

Instantly share code, notes, and snippets.

@ckerr
Last active March 3, 2021 16:18
Show Gist options
  • Save ckerr/f05c4c6b78a714cdf6a7857f2b151435 to your computer and use it in GitHub Desktop.
Save ckerr/f05c4c6b78a714cdf6a7857f2b151435 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title></title>
</head>
<body>
Display is <span id="size"></span>
<script src="renderer.js"></script>
</body>
</html>
const { app, ipcMain, BrowserWindow } = require("electron");
app.whenReady().then(() => {
const mainWindow = new BrowserWindow({
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
},
});
mainWindow.loadFile("index.html");
mainWindow.webContents.openDevTools();
});
app.on("window-all-closed", () => app.quit());
// test harness
function finishTest(success, text) {
if (success) {
console.log('test passed');
app.exit(0);
} else {
console.log(`test failed: ${text}`);
app.exit(1);
}
}
ipcMain.on('test-passed', (event, ...args) => finishTest(true, ...args));
ipcMain.on('test-failed', (event, ...args) => finishTest(false, ...args));
ipcMain.on('test-finished', (event, ...args) => finishTest(...args));
process.on('uncaughtException', (error) => finishTest(false, error.toString()));
const { app, ipcRenderer, remote } = require("electron");
try {
// confirm that `remote.screen` is defined
const primaryDisplay = remote.screen.getPrimaryDisplay();
const { width, height } = primaryDisplay.workAreaSize;
document.querySelector("#size").textContent = `${width}×${height}`;
ipcRenderer.send('test-passed');
} catch (e) {
ipcRenderer.send('test-failed', e.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment