Skip to content

Instantly share code, notes, and snippets.

@mlaurencin
Last active October 27, 2020 01:49
Show Gist options
  • Save mlaurencin/cbd3096126cab1f5c99108f1b623fa5f to your computer and use it in GitHub Desktop.
Save mlaurencin/cbd3096126cab1f5c99108f1b623fa5f to your computer and use it in GitHub Desktop.
BrowserWindow.getContentSize() does not behave the same as expected #25295
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<h1>Hello World!</h1>
<button id="click">Click to Get Window Size</button>
We are using Node.js <script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
</body>
</html>
const {app, BrowserWindow, ipcMain} = require('electron')
function createWindow () {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
}
})
mainWindow.loadFile('index.html')
// Open the DevTools.
mainWindow.webContents.openDevTools()
}
app.on('ready', createWindow)
//IPC Method
///*
ipcMain.on('change-sub-height', (event, arg) => {
let window = BrowserWindow.getAllWindows()[0]
let subWinSize = window.getSize()
window.setSize(Math.floor(subWinSize[0]), subWinSize[1])
console.log("In main: " + subWinSize)
})
//*/
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
//IPC Method
const { ipcRenderer } = require('electron')
function outputSize(){
// Remote Method
/*
const win = require('electron').remote.BrowserWindow.getFocusedWindow()
if (win) {
const [ width, height ] = win.getSize()
console.log("In renderer: " + width, height)
}
*/
// IPC Method
ipcRenderer.send('change-sub-height', 'sent')
}
document.querySelector("#click").addEventListener("mousedown", outputSize)
@mlaurencin
Copy link
Author

BrowserWindow.getContentSize() does not behave the same as expected #25295

electron/electron#25295

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment