Reputation: 10965
How can I get the monitor's refresh rate in my electron app?
The electron.screen module provides some info about the display, but not refresh rate. I couldn't find any node packages that do this either.
Upvotes: 0
Views: 568
Reputation: 1376
Untested
For a MAC, What I would probably do is to use a combination of Node, Electron and the command line.
In the main process, I would use the child_process module in NodeJS like so:
const exec = require('child_process').exec;
exec('defaults read /Library/Preferences/com.apple.windowserver.plist', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
The exe command gets the monitor information from the OS, and would run when your main process is read.
After that, I would use the Electron screen command screen.getPrimaryDisplay()
in the render process (so you can click a button on your view or something) and parse the output of that command for the ID you want.
Send it back to the main process via IPC. If you want all the ID’s then use the getAllDisplays variant.
I would then parse the results from the above exe command,and match the ID’s together to make sure you have what you want. Then, re-run the command to get the refresh rate with your results filtered via GREP/AWK/SED.
An alternative would be to use the plist package in Node, and filter the /Library/Preferences/com.apple.windowserver.plist
file that way.
Upvotes: 2