binaryfunt / electron-seamless-titlebar-tutorial Goto Github PK
View Code? Open in Web Editor NEWA guide to creating a seamless Windows 10 titlebar in your Electron app
License: MIT License
A guide to creating a seamless Windows 10 titlebar in your Electron app
License: MIT License
Hi there,
I would first like to say thank you for the tutorial. It has been very helpful. Can I possibly ask that you provide the full code in this example as well. It's quite useful when someone gets stuck at a point, to be able to reference and check for differences in their own work and what should work.
All and all, great writeup
Hi, thanks for this tutorial!
I was wondering, though, if I could disable the border for the window. Initially, I tried commenting out the line enabling the border on line 26 of style.css and changing the width of the titlebar from calc(100% - 2px)
to 100% on line 34, but I ended up with this:
I did some fiddling around, and on line 44, I changed the margin-top to 0, making it look like this:
Although this fixes the position of the titlebar, this changes the position of the #main content and the keeps the scrollbar to the right of the close button.
Could you tell me what I need to change to properly remove the border?
Thanks in advance.
The margin around the draggable area of the title bar is useful for resizing the unmaximised window, but when the window is maximised, the margin should be zero so you can click the very top and drag down to restore the window
This is something you may or may not think is an issue.
On screens above 720p, scaling up can be used by Windows to prevent everything from being super tiny. And while this works mostly well, it makes the window control icons on our titlebar thick, because they are a font. So instead of the icons being made of perfect 1px lines, they look a bit out of place.
175% scaling, electron titlebar at bottom:
100% scaling, electron titlebar at top:
The Microsoft office apps also have thicker icons like this
I don't know why I did this, it's a pretty tiny issue, and I don't think there's and fix for it. Just something I noticed when I switched to a new laptop.
Hey, i am trying to implement the Functionality of the Windows Controls but i am having a few issues as my backend is electron JS but my frontend is typescript so my renderer.js is actually index.tsx. Is there anyway i could insert the functionality of the windows buttons directly into the index.html file. Thanks and sorry i am a bit new to html and java
The minimize, maximize, and close functions don't working on version 14.0.0.
The 1px border around the window should not be shown when the window is maximized
Hi there,
I would first like to say thank you for the tutorial. It has been very helpful. Can I possibly ask that you provide the full code in this example as well. It's quite useful when someone gets stuck at a point, to be able to reference and check for differences in their own work and what should work.
All and all, great writeup
Using events in renderer process throw error on development console
saying Attempting to call a function in a renderer window that has been closed or released.
win.on('maximize', toggleMaxRestoreButtons);
win.on('unmaximize', toggleMaxRestoreButtons);
This will cause error because you haven't cleaned up correctly and a listener exists on a remote object from a renderer that does not exist any more.
Add event remover in your code where you had added events code
window.onbeforeunload = (e) => {
win.removeAllListeners();
};
This will remove ALL listeners attached to your window before unloading it.
Note - onbeforeunload will be called before page is refreshed or closed.
This is not same as your tutorial but here too I am using win.on events for blur and focus and it throws errors.
https://gist.github.com/AtiqGauri/1cea1c548025faa77f9f29008ca5a5fe#file-main-js-L4
The control buttons don't seem to work or don't work only for me. Please can someone help?
Great job on the tutorial, the steps are clear and the final look is great!
In regards to the maximize, minimize, restore, and close buttons in the title bar, they use the Segoe MDL2 Icons. This works perfectly for apps on Windows 10, but on older versions of Windows or Mac, the user has to install the font on their system.
From Microsoft
How do I get this font?
On Windows 10: There's nothing you need to do, the font comes with Windows.
On a Mac, you need to download and install the font: Get the Segoe UI and MDL2 icon fonts
For example, a screenshot from running on Windows 7
As electron is useful for developing cross platform apps, it would be most ideal if the user didnt have to install a font package to see these icons. Is there any way to include these icons in a cross platform electron project? For example, I found this repo that provides the icons as a .css file, but unfortunately it doesnt contain the icons referenced in the tutorial.
As of a recent version of Electron, 5 I think, nodeIntegration is disabled by default meaning that the require statement in the index.html file will not function.
People will need to add nodeIntegration: true
into the webPreferences object.
webPreferences: {
nodeIntegration: true
}
home.css file
body {
margin: 0;
/* border: 1px solid #48545c; */
font-family: "Segoe UI", sans-serif;
overflow-y: hidden;
}
#titlebar {
display: block;
position: fixed;
top: 0;
height: 32px;
width: 100%; /Compensate for body 1px border/
background: #077ccf;
z-index: 99;
}
#titlebar {
padding-left: 4;
padding-right: 4;
}
#titlebar #drag-region {
width: 100%;
height: 100%;
-webkit-app-region: drag;
}
#root {
margin-top: 32px;
padding: 0;
}
#titlebar {
color: #FFF;
}
#window-controls {
display: grid;
grid-template-columns: repeat(3, 46px);
position: absolute;
top: 0;
right: 0;
height: 100%;
font-family: "Segoe MDL2 Assets";
font-size: 10px;
}
#window-controls .button {
grid-row: 1 / span 1;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
#window-controls #min-button {
grid-column: 1;
}
#window-controls #max-button, #window-controls #restore-button {
grid-column: 2;
}
#window-controls #close-button {
grid-column: 3;
}
#window-controls {
-webkit-app-region: no-drag;
}
#window-controls .button {
user-select: none;
cursor: default;
}
#window-controls .button:hover {
background: rgba(255,255,255,0.1);
}
#window-controls .button:active {
background: rgba(255,255,255,0.2);
}
#close-button:hover {
background: #E81123 !important;
}
#close-button:active {
background: #f1707a !important;
color: #000;
}
#restore-button {
display: none !important;
}
#titlebar #drag-region {
display: grid;
grid-template-columns: auto 138px;
}
#window-title {
grid-column: 1;
display: flex;
align-items: center;
margin-left: 8px;
overflow-x: hidden;
font-family: "Segoe UI", sans-serif;
font-size: 12px;
}
#window-title span {
overflow: hidden;
text-overflow: ellipsis;
line-height: 1.5;
}
.maximized #titlebar {
width: 100%;
padding: 0;
}
.maximized #window-title {
margin-left: 12px;
}
.maximized #restore-button {
display: flex !important;
}
.maximized #max-button {
display: none;
}
index.html file
<header id="titlebar">
<div id="drag-region">
<div id="window-title">
<span>My App</span>
</div>
<div id="window-controls">
<div class="button" id="min-button">
<span></span>
</div>
<div class="button" id="max-button">
<span></span>
</div>
<div class="button" id="restore-button">
<span></span>
</div>
<div class="button" id="close-button">
<span></span>
</div>
</div>
</div>
</header>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
Amazing tutorial! Thanks so much! Got everything working just as described.
Now, my question is, do you have any ideas as to how to get back / integrate the menu into the seamless frame?
VSCode, for instance, has their menu integrated into the frame as such:
On clicking the maximize button, the window maximizes but the maximize button remains there, so you can't restore/unmaximize. This doesn't happen if you drag the title bar to the top of the screen to maximize the window - it works normally.
Windows 10
Electron 7.0.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.