Skip to content

Commit

Permalink
修正了当系统设置了DPI缩放时截图不完整的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
iamapig120 committed Jan 24, 2019
1 parent 2429ef8 commit 06d8c34
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
28 changes: 27 additions & 1 deletion bin/main/mainLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const configs = require('../../configs')
const userConfigs = require(configs.USER_CONFIG_PATH)

const clipboard = remote.clipboard
const electronScreen = electron.screen

/**
* @type {Electron.WebviewTag}
Expand Down Expand Up @@ -36,6 +37,11 @@ let executeScriptsCodes = []
*/
let serverPort

/**
* @type {ClientRectList | DOMRectList}
*/
let clientRect

const probuildExecuteCode = executeScriptInfo => {
let codeEntry = executeScriptInfo.entry
if (!codeEntry) {
Expand Down Expand Up @@ -95,14 +101,34 @@ ipcRenderer.on('load-url', (event, ...args) => {
mainWindowBox.style.transform = 'none'
})

ipcRenderer.on('window-resize', (event, ...args) => {
clientRect = args[0]
})

ipcRenderer.on('take-screenshot', () => {
if (webContents) {
webContents.capturePage(image => {
const callbackFunction = image => {
ipcRenderer.send('application-message', 'take-screenshot', image.toPNG())
const dataURL = image.toDataURL()
showScreenshotLabel(dataURL)
clipboard.writeImage(image)
}
const rect = clientRect
const display = electronScreen.getDisplayMatching({
x: parseInt(rect.x),
y: parseInt(rect.y),
width: parseInt(rect.width),
height: parseInt(rect.height)
})
webContents.capturePage(
{
x: 0,
y: 0,
width: parseInt(mainWindow.clientWidth * display.scaleFactor),
height: parseInt(mainWindow.clientHeight * display.scaleFactor)
},
callbackFunction
)
}
})

Expand Down
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ const windowControl = {
}
const gameWindow = new BrowserWindow(config)
gameWindow.on('page-title-updated', event => event.preventDefault())
gameWindow.on('resize', () => {
gameWindow.webContents.send('window-resize', gameWindow.getBounds())
})
gameWindow.on('move', () => {
gameWindow.webContents.send('window-resize', gameWindow.getBounds())
})
gameWindow.on('moved', () => {
gameWindow.webContents.send('window-resize', gameWindow.getBounds())
})
gameWindow.on('closed', () => {
Util.shutoffPlayer()
})
Expand Down Expand Up @@ -339,10 +348,7 @@ const windowControl = {
break
}
case 'update-user-config': {
userConfigs = JSON.parse(
fs.readFileSync(configs.USER_CONFIG_PATH)
)

userConfigs = JSON.parse(fs.readFileSync(configs.USER_CONFIG_PATH))
windowControl.windowMap['manager'].setContentSize(
configs.MANAGER_WINDOW_CONFIG.width *
userConfigs.window.zoomFactor,
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": "majsoul-plus-client",
"version": "1.8.8",
"version": "1.8.9",
"productName": "Majsoul Plus",
"author": "MajsoulPlus Team",
"description": "Majsoul Plus",
Expand Down

0 comments on commit 06d8c34

Please sign in to comment.