Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BrowserWindow#setBackgroundColor() method #13464

Closed
sindresorhus opened this issue Jun 27, 2018 · 5 comments
Closed

Add BrowserWindow#setBackgroundColor() method #13464

sindresorhus opened this issue Jun 27, 2018 · 5 comments
Labels
beginner friendly language/cpp semver/minor backwards-compatible functionality status/reviewed A maintainer made an initial review but not reproduced the issue

Comments

@sindresorhus
Copy link
Contributor

Is your feature request related to a problem? Please describe.

It's possible to set the backgroundColor in the BrowserWindow constructor, but it's not possible to change it later. I need a way to dynamically change the background color when the user toggles system dark mode. I cannot just set it in CSS as my app uses window.history.reload(), so the original window background color becomes visible then.

Describe the solution you'd like

I like to see a BrowserWindow#setBackgroundColor() method.

The BrowserView API already have this method.

@MarshallOfSound MarshallOfSound added beginner friendly status/reviewed A maintainer made an initial review but not reproduced the issue semver/minor backwards-compatible functionality labels Jun 27, 2018
@MarshallOfSound
Copy link
Member

This should just be a case of exposing the internal SetBackgroundColor method. And exposing a new getter method.

https://github.com/electron/electron/blob/master/atom/browser/api/atom_api_browser_window.cc#L295

@darkcoderrises
Copy link

Could I work on this?

@sarkararpan710
Copy link

Hi I am new to this. Have C++ experience. Can anyone help me understand how I can contribute to this project and guide me towards solving this issue in specific.

@caesar
Copy link
Contributor

caesar commented Oct 31, 2018

Looks like this is in 4.0.0-beta, but it only works (on macOS Mojave and Windows 10, at least) if the window is opened with a transparent backgroundColor. Otherwise setBackgroundColor() has no effect.

@erickzhao
Copy link
Member

Hey there, it seems like the setBackgroundColor API for BrowserWindow was added at some point and properly documented here in PR #14972.

`win.setBackgroundColor(backgroundColor)

  • backgroundColor String - Window's background color as a hexadecimal value,
    like #66CD00 or #FFF or #80FFFFFF (alpha is supported if transparent
    is true). Default is #FFF (white).

Sets the background color of the window. See Setting
backgroundColor
.


Also,

Looks like this is in 4.0.0-beta, but it only works (on macOS Mojave and Windows 10, at least) if the window is opened with a transparent backgroundColor. Otherwise setBackgroundColor() has no effect.

It also seems to be working without opening the window with a transparent backgroundColor. Tested in both v4.2.4 and v5.0.3 (on macOS Mojave as well).

See gist for Electron Fiddle: https://gist.github.com/erickzhao/f173c821a3310911d045ffeca201c10a

Will be closing this for now, then!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner friendly language/cpp semver/minor backwards-compatible functionality status/reviewed A maintainer made an initial review but not reproduced the issue
Projects
None yet
Development

No branches or pull requests

6 participants