Documente Academic
Documente Profesional
Documente Cultură
In most of the desktop applications that use custom titlebars, they aren't using normally
the default graphic kit of Windows, or Mac or Linux as it can't be normally customized by
a single application. So the most common solution for this kind of apps that need to
customize it, is to basically replicate the behaviour of the titlebar with components of
their own GUI, removing the original one and working with a window with no frame. For
an Electron application, there's no exception, so if you are willing to customize the
titlebar as well, you will need to work with a window without frame and create the
titlebar with HTML, CSS and JavaScript. Fortunately for you, there's already a module that
implements this cool feature and it can be easily installed and customize it as you want.
In this article, we will explain you how to implement a custom titlebar inspired on the
Visual Studio Code titlebar.
1/6
receives specifically the BrowserWindow instance.
We have to highlight this step as in previous versions of Electron, the node integration
was enabled by default, however now it's not, it will always come up with this attribute
set to false, so be sure to enable it in order to be able to require the module in the
renderer process. An example of how the createWindow function in the main.js file
looks like with the frame disabled and the nodeIntegration set to true :
let mainWindow
function createWindow() {
frame: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true
}
})
Copy snippet
Once you are sure that you have configured these properties, proceed with the
installation of the module.
Install the module on your Electron project using the following command:
2/6
Copy snippet
For more information about this module, please visit the official repository at Github
here.
Copy snippet
You can customize some properties of the titlebar providing them in the configuration
object as first argument of the Titlebar class:
3/6
minimizable boolean Enables or true
disables the
option to
minimize the
window by clicking
on the
corresponding
button in the title
bar.
4/6
enableMnemonics boolean Enable the true
mnemonics on
menubar and
menu items.
Remember that you need to run the code on the renderer process (in the index.html
file):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<script>
Copy snippet
Happy coding !
5/6
Interested in programming since he was 14 years old, Carlos is the founder and author
of most of the articles at Our Code World. He is currently studying systems engineering
at the UDI university in Colombia.
6/6