Skip to content

Commit fa123f5

Browse files
YanDevDebencevans
authored andcommitted
fix: multiple screens detection [Windows] (#13)
1 parent 2fe3e0a commit fa123f5

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

lib/win32/index.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ const fs = require('fs')
55
const path = require('path')
66
const utils = require('../utils')
77

8-
const { unlinkP, readAndUnlinkP, defaultAll } = utils
8+
const {
9+
unlinkP,
10+
readAndUnlinkP,
11+
defaultAll
12+
} = utils
913

10-
function windowsSnapshot (options = {}) {
14+
function windowsSnapshot(options = {}) {
1115
return new Promise((resolve, reject) => {
1216
const displayName = options.screen
13-
const tmpPath = temp.path({ suffix: '.jpg' })
17+
const tmpPath = temp.path({
18+
suffix: '.jpg'
19+
})
1420
const imgPath = path.resolve(options.filename || tmpPath)
1521

1622
const displayChoice = displayName ? ` /d "${displayName}"` : ''
@@ -38,21 +44,33 @@ const EXAMPLE_DISPLAYS_OUTPUT = '\r\nC:\Users\devetry\screenshot-desktop\lib\win
3844
function parseDisplaysOutput(output) {
3945
const
4046
displaysStartPattern = /2>nul \|\| /,
41-
{ 0: match, index } = displaysStartPattern.exec(output)
47+
{
48+
0: match,
49+
index
50+
} = displaysStartPattern.exec(output)
4251
return output.slice(index + match.length)
4352
.split('\n')
4453
.map(s => s.replace(/[\n\r]/g, ''))
45-
.map(s => s.match(/(.*?);(\d+);(\d+);(\d+);(\d+)/))
54+
.map(s => s.match(/(.*?);(.?\d+);(.?\d+);(.?\d+);(.?\d+)/))
4655
.filter(s => s)
47-
.map(m => ({ id: m[1], name: m[1], top: +m[2], right: +m[3], bottom: +m[4], left: +m[5] }))
48-
.map(d => Object.assign(d, { height: d.bottom - d.top, width: d.right - d.left }))
56+
.map(m => ({
57+
id: m[1],
58+
name: m[1],
59+
top: +m[2],
60+
right: +m[3],
61+
bottom: +m[4],
62+
left: +m[5]
63+
}))
64+
.map(d => Object.assign(d, {
65+
height: d.bottom - d.top,
66+
width: d.right - d.left
67+
}))
4968
}
5069

5170
function listDisplays() {
5271
return new Promise((resolve, reject) => {
5372
exec(
54-
'"' + path.join(__dirname, 'screenCapture_1.3.1.bat') + '" /list',
55-
{
73+
'"' + path.join(__dirname, 'screenCapture_1.3.1.bat') + '" /list', {
5674
cwd: __dirname
5775
},
5876
(err, stdout) => {
@@ -70,4 +88,4 @@ windowsSnapshot.parseDisplaysOutput = parseDisplaysOutput
7088
windowsSnapshot.EXAMPLE_DISPLAYS_OUTPUT = EXAMPLE_DISPLAYS_OUTPUT
7189
windowsSnapshot.all = () => defaultAll(windowsSnapshot)
7290

73-
module.exports = windowsSnapshot
91+
module.exports = windowsSnapshot

0 commit comments

Comments
 (0)