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: potential crash when setting vibrancy #29677

Merged
merged 1 commit into from Jun 16, 2021
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
8 changes: 4 additions & 4 deletions shell/browser/native_window_mac.mm
Expand Up @@ -1360,8 +1360,6 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
return;
}

vibrancy_type_ = type;

NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view;
if (effect_view == nil) {
effect_view = [[[NSVisualEffectView alloc]
Expand Down Expand Up @@ -1390,7 +1388,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
node::Environment* env =
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());

NSVisualEffectMaterial vibrancyType;
NSVisualEffectMaterial vibrancyType{};
if (type == "appearance-based") {
EmitWarning(env, "NSVisualEffectMaterialAppearanceBased" + dep_warn,
"electron");
Expand Down Expand Up @@ -1447,8 +1445,10 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}
}

if (vibrancyType)
if (vibrancyType) {
vibrancy_type_ = type;
[effect_view setMaterial:vibrancyType];
}
}

void NativeWindowMac::SetWindowButtonVisibility(bool visible) {
Expand Down
7 changes: 7 additions & 0 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -1610,6 +1610,13 @@ describe('BrowserWindow module', () => {
w.setVibrancy('' as any);
}).to.not.throw();
});

it('does not crash if vibrancy is set to an invalid value', () => {
const w = new BrowserWindow({ show: false });
expect(() => {
w.setVibrancy('i-am-not-a-valid-vibrancy-type' as any);
}).to.not.throw();
});
});

ifdescribe(process.platform === 'darwin')('trafficLightPosition', () => {
Expand Down