Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #38 from nashaofu/dev
Browse files Browse the repository at this point in the history
优化截图,减少一次屏幕截图
  • Loading branch information
nashaofu authored Dec 31, 2017
2 parents 38fe576 + a33a1ac commit 9a56d4d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
16 changes: 8 additions & 8 deletions app/shortcut-capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ function createWindow (source) {
const { display } = source
const $win = new BrowserWindow({
title: '截图',
width: display.size.width,
height: display.size.height,
x: display.bounds.x,
y: display.bounds.y,
width: display.width,
height: display.height,
x: display.x,
y: display.y,
frame: false,
show: false,
transparent: true,
Expand Down Expand Up @@ -82,10 +82,10 @@ function createWindow (source) {

function setFullScreen ($win, display) {
$win.setBounds({
width: display.size.width,
height: display.size.height,
x: display.bounds.x,
y: display.bounds.y
width: display.width,
height: display.height,
x: display.x,
y: display.y
})
$win.setAlwaysOnTop(true)
$win.setFullScreen(true)
Expand Down
49 changes: 31 additions & 18 deletions app/window/js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const fs = require('fs')
const path = require('path')
const _ = require('lodash')

const {
ipcRenderer,
webFrame,
Expand Down Expand Up @@ -338,27 +340,38 @@ class Injector {
onShortcutCapture () {
ipcRenderer.on('shortcut-capture', () => {
const displays = screen.getAllDisplays()
const getDesktopCapturer = displays.map((display, i) => {
return new Promise((resolve, reject) => {
desktopCapturer.getSources({
types: ['screen'],
thumbnailSize: display.size
}, (error, sources) => {
if (!error) {
return resolve({
display,
thumbnail: sources[i].thumbnail.toDataURL()
})
.map(item => ({
width: item.size.width,
height: item.size.height,
x: item.bounds.x,
y: item.bounds.y,
scaleFactor: item.scaleFactor
}))

// 用最大的屏幕去截屏,保证图片高清
const max = _.maxBy(displays, item => item.width * item.height)
desktopCapturer.getSources({
types: ['screen'],
thumbnailSize: {
width: max.width,
height: max.height
}
}, (error, sources) => {
if (!error) {
sources = sources.map((item, i) => {
const display = displays[i]
return {
display,
thumbnail: item.thumbnail.resize({
width: display.width,
height: display.height,
quality: 'best'
}).toDataURL()
}
return reject(error)
})
})
}
ipcRenderer.send('shortcut-capture', sources)
})
Promise.all(getDesktopCapturer)
.then(sources => {
ipcRenderer.send('shortcut-capture', sources)
})
.catch(error => console.log(error))
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dingtalk",
"version": "1.4.3",
"version": "1.4.4",
"description": "钉钉linux桌面版",
"main": "./app/index.js",
"scripts": {
Expand Down

0 comments on commit 9a56d4d

Please sign in to comment.