fix: ensure set vibrancy with invalid value is a no-op (#31162)

* chore: remove c-style conversion for vibrantView (#29724)

* fix: ensure set vibrancy with invalid value is a no-op (#29795)

Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
Shelley Vohr
2021-09-29 11:42:32 +02:00
committed by GitHub
parent 717a3f4c40
commit 4831aa56bf
2 changed files with 33 additions and 33 deletions

View File

@@ -1337,10 +1337,9 @@ void NativeWindowMac::SetAutoHideCursor(bool auto_hide) {
}
void NativeWindowMac::UpdateVibrancyRadii(bool fullscreen) {
NSView* vibrant_view = [window_ vibrantView];
NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view;
NSVisualEffectView* vibrantView = [window_ vibrantView];
if (effect_view != nil && !vibrancy_type_.empty()) {
if (vibrantView != nil && !vibrancy_type_.empty()) {
const bool no_rounded_corner =
[window_ styleMask] & NSWindowStyleMaskFullSizeContentView;
if (!has_frame() && !is_modal() && !no_rounded_corner) {
@@ -1370,49 +1369,25 @@ void NativeWindowMac::UpdateVibrancyRadii(bool fullscreen) {
[maskImage setCapInsets:NSEdgeInsetsMake(radius, radius, radius, radius)];
[maskImage setResizingMode:NSImageResizingModeStretch];
[effect_view setMaskImage:maskImage];
[vibrantView setMaskImage:maskImage];
[window_ setCornerMask:maskImage];
}
}
}
void NativeWindowMac::SetVibrancy(const std::string& type) {
NSView* vibrant_view = [window_ vibrantView];
NSVisualEffectView* vibrantView = [window_ vibrantView];
if (type.empty()) {
if (vibrant_view == nil)
if (vibrantView == nil)
return;
[vibrant_view removeFromSuperview];
[vibrantView removeFromSuperview];
[window_ setVibrantView:nil];
return;
}
NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view;
if (effect_view == nil) {
effect_view = [[[NSVisualEffectView alloc]
initWithFrame:[[window_ contentView] bounds]] autorelease];
[window_ setVibrantView:(NSView*)effect_view];
[effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
if (visual_effect_state_ == VisualEffectState::kActive) {
[effect_view setState:NSVisualEffectStateActive];
} else if (visual_effect_state_ == VisualEffectState::kInactive) {
[effect_view setState:NSVisualEffectStateInactive];
} else {
[effect_view setState:NSVisualEffectStateFollowsWindowActiveState];
}
[[window_ contentView] addSubview:effect_view
positioned:NSWindowBelow
relativeTo:nil];
UpdateVibrancyRadii(IsFullscreen());
}
std::string dep_warn = " has been deprecated and removed as of macOS 10.15.";
node::Environment* env =
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());
@@ -1476,7 +1451,32 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
if (vibrancyType) {
vibrancy_type_ = type;
[effect_view setMaterial:vibrancyType];
if (vibrantView == nil) {
vibrantView = [[[NSVisualEffectView alloc]
initWithFrame:[[window_ contentView] bounds]] autorelease];
[window_ setVibrantView:vibrantView];
[vibrantView
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[vibrantView setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
if (visual_effect_state_ == VisualEffectState::kActive) {
[vibrantView setState:NSVisualEffectStateActive];
} else if (visual_effect_state_ == VisualEffectState::kInactive) {
[vibrantView setState:NSVisualEffectStateInactive];
} else {
[vibrantView setState:NSVisualEffectStateFollowsWindowActiveState];
}
[[window_ contentView] addSubview:vibrantView
positioned:NSWindowBelow
relativeTo:nil];
UpdateVibrancyRadii(IsFullscreen());
}
[vibrantView setMaterial:vibrancyType];
}
}

View File

@@ -35,7 +35,7 @@ class ScopedDisableResize {
@property BOOL enableLargerThanScreen;
@property BOOL disableAutoHideCursor;
@property BOOL disableKeyOrMainWindow;
@property(nonatomic, retain) NSView* vibrantView;
@property(nonatomic, retain) NSVisualEffectView* vibrantView;
@property(nonatomic, retain) NSImage* cornerMask;
- (id)initWithShell:(electron::NativeWindowMac*)shell
styleMask:(NSUInteger)styleMask;