# electron-win-app-rect

> electron 通过desktopCapturer.getSources返回的source.id获取桌面窗口坐标

Latest version **1.0.6** (published 2020-08-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install electron-win-app-rect
pnpm add electron-win-app-rect
yarn add electron-win-app-rect
bun add electron-win-app-rect
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2020-08-05 |
| First published | 2020-08-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | eagle |
| Maintainers | chinaqiao |
| Keywords | electron |

## Links

- npm: https://www.npmjs.com/package/electron-win-app-rect
- Repository: https://github.com/chinaqiao/electron-win-app-rect
- Homepage: https://github.com/chinaqiao/electron-win-app-rect#readme
- Issues: https://github.com/chinaqiao/electron-win-app-rect/issues
- npm.io page: https://npm.io/package/electron-win-app-rect

## Recent versions

- 1.0.6 (latest) — 2020-08-05
- 1.0.5 — 2020-08-05
- 1.0.4 — 2020-08-05
- 1.0.3 — 2020-08-05
- 1.0.2 — 2020-08-05
- 1.0.1 — 2020-08-05
- 1.0.0 — 2020-08-05

## README

# Electron-Win-App-Rect

需要配合 **desktopCapturer.getSources** 返回的source.id 获取桌面应用的窗口坐标

## 安装

根据需要修改 install 

```
    npm i -s electron-win-app-rect
```

## Electron 版本对应

如果使用 **NODE_MODULE_VERSION** 版本不一致，则需要进入目录手动编译，同时指定electron版本

> --target 为指定electron版本

```
     "node-gyp rebuild --arch=x64 --target=6.1.12 --dist-url=https://atom.io/download/electron"
```
如果需要修改main.cc代码，修改完成后，在执行build


## 使用

**注意：**

source.id 返回的格式为  window:18238:0
调用时，需要传入 其中的 18238 并且为 Number类型

```
    const sourceId = source.id.split(':')[1];
    const appId = parseInt(appId);
    const rect = Eagle.getWindowRect(appId);
    console.log(rect);
```


```
const Eagle = require('electron-win-app-rect');

// In the renderer process.
const { desktopCapturer } = require('electron')

desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources => {
  for (const source of sources) {
    if (source.name === 'Electron') {
      try {
        const stream = await navigator.mediaDevices.getUserMedia({
          audio: false,
          video: {
            mandatory: {
              chromeMediaSource: 'desktop',
              chromeMediaSourceId: source.id,
              minWidth: 1280,
              maxWidth: 1280,
              minHeight: 720,
              maxHeight: 720
            }
          }
        })
        const sourceId = source.id.split(':')[1];
        const appId = parseInt(appId);
        const rect = Eagle.getWindowRect(appId);
        handleStream(stream)
      } catch (e) {
        handleError(e)
      }
      return
    }
  }
})

function handleStream (stream) {
  const video = document.querySelector('video')
  video.srcObject = stream
  video.onloadedmetadata = (e) => video.play()
}

function handleError (e) {
  console.log(e)
}

```

---
_Source: https://npm.io/package/electron-win-app-rect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
