fix: potential crash when setting vibrancy (#29677)
This commit is contained in:
parent
81795744cf
commit
2ae7e04598
2 changed files with 11 additions and 4 deletions
|
@ -1360,8 +1360,6 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vibrancy_type_ = type;
|
|
||||||
|
|
||||||
NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view;
|
NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view;
|
||||||
if (effect_view == nil) {
|
if (effect_view == nil) {
|
||||||
effect_view = [[[NSVisualEffectView alloc]
|
effect_view = [[[NSVisualEffectView alloc]
|
||||||
|
@ -1390,7 +1388,7 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
node::Environment* env =
|
node::Environment* env =
|
||||||
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());
|
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());
|
||||||
|
|
||||||
NSVisualEffectMaterial vibrancyType;
|
NSVisualEffectMaterial vibrancyType{};
|
||||||
if (type == "appearance-based") {
|
if (type == "appearance-based") {
|
||||||
EmitWarning(env, "NSVisualEffectMaterialAppearanceBased" + dep_warn,
|
EmitWarning(env, "NSVisualEffectMaterialAppearanceBased" + dep_warn,
|
||||||
"electron");
|
"electron");
|
||||||
|
@ -1447,8 +1445,10 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vibrancyType)
|
if (vibrancyType) {
|
||||||
|
vibrancy_type_ = type;
|
||||||
[effect_view setMaterial:vibrancyType];
|
[effect_view setMaterial:vibrancyType];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetWindowButtonVisibility(bool visible) {
|
void NativeWindowMac::SetWindowButtonVisibility(bool visible) {
|
||||||
|
|
|
@ -1609,6 +1609,13 @@ describe('BrowserWindow module', () => {
|
||||||
w.setVibrancy('' as any);
|
w.setVibrancy('' as any);
|
||||||
}).to.not.throw();
|
}).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', () => {
|
ifdescribe(process.platform === 'darwin')('trafficLightPosition', () => {
|
||||||
|
|
Loading…
Reference in a new issue