Skip to content

Instantly share code, notes, and snippets.

@lakshyamunjal
Last active October 21, 2021 08:39
Show Gist options
  • Save lakshyamunjal/c7ac335bbb7ca83d485b2d22bc4f527f to your computer and use it in GitHub Desktop.
Save lakshyamunjal/c7ac335bbb7ca83d485b2d22bc4f527f to your computer and use it in GitHub Desktop.
Window width increasing after clicking maximize, minimize, alt+tab to focus the window.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'"
/>
<meta
http-equiv="X-Content-Security-Policy"
content="default-src 'self'; script-src 'self'"
/>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using Node.js <span id="node-version"></span>, Chromium
<span id="chrome-version"></span>, and Electron
<span id="electron-version"></span>.
<h2>Steps to reproduce:</h2>
<ol>
<li>Click on Maximize button.</li>
<li>Click on Minimize button</li>
<li>Click Alt+Tab to bring window to focus.</li>
</ol>
<strong>Note:</strong>
<span
>Window width has grown more than max-width defined while creating
BrowserWindow object</span
>
<!-- You can also require other files to run in this process -->
<script src="./renderer.js"></script>
</body>
</html>
const { app, BrowserWindow } = require('electron');
const createWindow = () => {
const win = new BrowserWindow({
width: 700,
height: 500,
maximizable: true,
minimizable: true,
maxWidth: 1040,
maxHeight: 900,
fullscreenable: false,
});
win.on('focus', () => {
console.log('Focus :: ', win.getBounds())
})
win.setAspectRatio(700 / 530);
win.loadFile('index.html');
};
app
.whenReady()
.then(() => {
createWindow();
})
.catch((e) => {
console.log('error : ', e);
});
{
"name": "actual-umbrella-reply-zdhft",
"productName": "actual-umbrella-reply-zdhft",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "lakshya",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "13.1.2"
}
}
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment