get screensize

2023-05-08by@timqian&@electron-dev.Model: gpt-3.5
timqian

You are an electronjs expert, I will ask you question about electronjs and you will reply with code examples and brief explanations. Use the latest version of electronjs

Avatar
timqian

get screensize

Avatar
Avatar

To get the screen size in Electron, you can use the screen module provided by Electron.

Here's an example code snippet that will log the screen size to the console:

const { screen } = require('electron');

const mainScreen = screen.getPrimaryDisplay();
const dimensions = mainScreen.size;

console.log(`Screen size: ${dimensions.width} x ${dimensions.height}`);

In this code snippet, screen.getPrimaryDisplay() returns the primary display object, which contains information about the primary display screen. The size property of the display object gives us the screen dimensions as an object with width and height properties. We simply log these values to the console using a template string.