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

fix: handle a nil backgroundColor in win.getBackgroundColor() #28186

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions shell/browser/native_window_mac.mm
Expand Up @@ -1202,8 +1202,10 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

SkColor NativeWindowMac::GetBackgroundColor() {
return skia::CGColorRefToSkColor(
[[[window_ contentView] layer] backgroundColor]);
CGColorRef color = [[[window_ contentView] layer] backgroundColor];
if (!color)
return SK_ColorTRANSPARENT;
return skia::CGColorRefToSkColor(color);
}

void NativeWindowMac::SetHasShadow(bool has_shadow) {
Expand Down
5 changes: 4 additions & 1 deletion shell/browser/native_window_views.cc
Expand Up @@ -915,7 +915,10 @@ bool NativeWindowViews::IsKiosk() {
}

SkColor NativeWindowViews::GetBackgroundColor() {
return root_view_->background()->get_color();
auto* background = root_view_->background();
if (!background)
return SK_ColorTRANSPARENT;
return background->get_color();
}

void NativeWindowViews::SetBackgroundColor(SkColor background_color) {
Expand Down
@@ -0,0 +1,14 @@
const { app, BrowserWindow } = require('electron');

function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
transparent: true
});
mainWindow.getBackgroundColor();
}

app.on('ready', () => {
createWindow();
setTimeout(() => app.quit());
});