Last active
March 3, 2021 16:18
-
-
Save ckerr/f05c4c6b78a714cdf6a7857f2b151435 to your computer and use it in GitHub Desktop.
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" /> | |
<title></title> | |
</head> | |
<body> | |
Display is <span id="size"></span> | |
<script src="renderer.js"></script> | |
</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
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())); |
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
// Empty |
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
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()); | |
} |
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
/* Empty */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment