Git Product home page Git Product logo

electron-seamless-titlebar-tutorial's People

Contributors

binaryfunt avatar dependabot[bot] avatar toby56 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

electron-seamless-titlebar-tutorial's Issues

Full example code

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

Disable border

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:

image

I did some fiddling around, and on line 44, I changed the margin-top to 0, making it look like this:

image

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.

Whole of titlebar should be draggable when maximised

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

Window controls icons look a bit too thick on high scale/dpi

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:
image

100% scaling, electron titlebar at top:
image

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.

window controls functionality with a typescript frontend

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

Full example code

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

Clean up Electron win listeners on app reload

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.

Solution - Avoid using remote or clean up your event handlers on remote objects if you have to use it

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.

Screenshot-
Screenshot (146)

Conclusion- update tutorial to adapt to solution

To reproduce-

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

Display in Windows 11

Hello everyone, in windows 11 the icons have been slightly redesigned (a little fatter), will they add here?
Снимок экрана 2021-08-25 185341

Segoe MDL2 Icons cross platform app

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

image

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.

nodeIntegration Disabled

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
}

Scrollbar not visible

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>&#xE921;</span>
          </div>
          <div class="button" id="max-button">
            <span>&#xE922;</span>
          </div>
          <div class="button" id="restore-button">
            <span>&#xE923;</span>
          </div>
          <div class="button" id="close-button">
            <span>&#xE8BB;</span>
          </div>
        </div>
      </div>
    </header>

<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

Maximise button doesn't work properly on Electron 6.0.0+

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.