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

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

* spec: add crash case

* fix: update to fix native_views transparent color

* chore: fix lint
This commit is contained in:
Samuel Attard 2021-03-14 17:26:47 -07:00 committed by GitHub
parent f73256651b
commit 8dfe4abd14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View file

@ -996,8 +996,10 @@ void NativeWindowMac::SetBackgroundColor(SkColor color) {
}
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) {

View file

@ -956,7 +956,10 @@ bool NativeWindowViews::IsTabletMode() const {
}
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) {

View file

@ -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());
});