Skip to content

Instantly share code, notes, and snippets.

@RushingAlien
Created September 16, 2024 13:07
Show Gist options
  • Save RushingAlien/251199d0bd7c648bba104251bbe38726 to your computer and use it in GitHub Desktop.
Save RushingAlien/251199d0bd7c648bba104251bbe38726 to your computer and use it in GitHub Desktop.
Electron app with custom window frame
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self';">
<link href="./styles.css" rel="stylesheet">
<title>Custom Title Bar</title>
</head>
<body>
<div id="title-bar">
<div id="title">My Electron App</div>
<div id="window-controls">
<button id="minimize-btn">_</button>
<button id="maximize-btn">[ ]</button>
<button id="close-btn">X</button>
</div>
</div>
<div id="content">
<h1>Hello Electron Developers!</h1>
<p>Please run this fiddle with --ozone-platform-hint=auto under GNOME Wayland<br/><br/> Electron <span id="node-version"></span>, Chromium <span id="chrome-version"></span>, and Electron <span id="electron-version"></span>.</p>
</div>
<script src="./renderer.js"></script>
</body>
</html>
const { app, BrowserWindow } = require('electron');
const path = require('path');
function createWindow() {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false, // Disable the default frame
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
});
mainWindow.loadFile('index.html');
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
{
"name": "damaging-scissors-balance-kf0c0",
"productName": "damaging-scissors-balance-kf0c0",
"description": "My Electron application description",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "raambm",
"scripts": {
"start": "electron ."
},
"dependencies": {},
"devDependencies": {
"electron": "27.0.4"
}
}
/**
* The preload script runs before. It has access to web APIs
* as well as Electron's renderer process modules and some
* polyfilled Node.js functions.
*
* https://www.electronjs.org/docs/latest/tutorial/sandbox
*/
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])
}
})
const { remote } = require('electron');
document.getElementById('minimize-btn').addEventListener('click', () => {
remote.getCurrentWindow().minimize();
});
document.getElementById('maximize-btn').addEventListener('click', () => {
const window = remote.getCurrentWindow();
if (window.isMaximized()) {
window.unmaximize();
} else {
window.maximize();
}
});
document.getElementById('close-btn').addEventListener('click', () => {
remote.getCurrentWindow().close();
});
body {
margin: 0;
font-family: Arial, sans-serif;
}
#title-bar {
background-color: #333;
color: white;
display: flex;
justify-content: space-between;
padding: 10px;
-webkit-user-select: none;
-webkit-app-region: drag;
}
#title {
font-size: 16px;
}
#window-controls button {
background-color: #555;
color: white;
border: none;
width: 30px;
height: 30px;
margin-left: 10px;
-webkit-app-region: no-drag;
cursor: pointer;
}
#window-controls button:hover {
background-color: #777;
}
#content {
padding: 20px;
}
@RushingAlien
Copy link
Author

Hello! There are a few steps to reproduce the issue

Reproductions steps:

  1. Run Linux
  2. Use GNOME wayland or Weston for desktop
  3. Run electron fiddle app with custom window frame with --ozone-platform-hint=auto
  4. Run fiddle apop
  5. See missing window shadow

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