Skip to content

Instantly share code, notes, and snippets.

@wasit-shafi
Created July 27, 2021 19:46
Show Gist options
  • Save wasit-shafi/62e2189d0e698dfdd55d979bfbac102e to your computer and use it in GitHub Desktop.
Save wasit-shafi/62e2189d0e698dfdd55d979bfbac102e to your computer and use it in GitHub Desktop.
Electron Fiddle Gist for aspect ratio issue #30277
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<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>
I am using Node.js <span id="node-version"></span>,
Chromium <span id="chrome-version"></span>,
and Electron <span id="electron-version"></span>.
<!-- I am using Node.js 14.16.0, Chromium 91.0.4472.124, and Electron 13.1.5. -->
<div>
<h2>Steps:</h2>
<ul>
<li>Run App</li>
<li>Move window to top left</li>
<li>Resize window to maximum possible</li>
<li>Double Click Title bar/zoom button(window width will increase)</li>
</ul>
<div>
<script src="./renderer.js"></script>
</body>
</html>
const {app, BrowserWindow} = require('electron')
const path = require('path')
function createWindow () {
const mainWindow = new BrowserWindow({
width: 500,
height: 500,
fullscreenable: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.loadFile('index.html')
mainWindow.setAspectRatio(1)
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
{
"name": "rich-frog-pay-un5ss",
"productName": "rich-frog-pay-un5ss",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "wasit-vs",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "13.1.5"
}
}
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