From 11e2d9250c3f967d44f2d99f230677a852b6a542 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Sun, 21 Feb 2021 21:12:45 +0100 Subject: [PATCH 1/4] Reduce memory pressure when using bindings. --- src/Avalonia.Base/Data/BindingOperations.cs | 28 ++++++++++++++++++- .../Reactive/AvaloniaPropertyObservable.cs | 5 ++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Base/Data/BindingOperations.cs b/src/Avalonia.Base/Data/BindingOperations.cs index dc8421fb35..42f941da0c 100644 --- a/src/Avalonia.Base/Data/BindingOperations.cs +++ b/src/Avalonia.Base/Data/BindingOperations.cs @@ -45,7 +45,7 @@ namespace Avalonia.Data case BindingMode.OneWay: return target.Bind(property, binding.Observable ?? binding.Subject, binding.Priority); case BindingMode.TwoWay: - return new CompositeDisposable( + return new TwoWayBindingDisposable( target.Bind(property, binding.Subject, binding.Priority), target.GetObservable(property).Subscribe(binding.Subject)); case BindingMode.OneTime: @@ -88,6 +88,32 @@ namespace Avalonia.Data throw new ArgumentException("Invalid binding mode."); } } + + private sealed class TwoWayBindingDisposable : IDisposable + { + private readonly IDisposable _first; + private readonly IDisposable _second; + private bool _isDisposed; + + public TwoWayBindingDisposable(IDisposable first, IDisposable second) + { + _first = first; + _second = second; + } + + public void Dispose() + { + if (_isDisposed) + { + return; + } + + _first.Dispose(); + _second.Dispose(); + + _isDisposed = true; + } + } } public sealed class DoNothingType diff --git a/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs b/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs index 238aba5c96..6a3f9b0b30 100644 --- a/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs +++ b/src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Avalonia.Reactive { @@ -55,9 +56,9 @@ namespace Avalonia.Reactive newValue = (T)e.Sender.GetValue(e.Property); } - if (!Equals(newValue, _value)) + if (!EqualityComparer.Default.Equals(newValue, _value)) { - _value = (T)newValue; + _value = newValue; PublishNext(_value); } } From 52de38d8a1c1c28b848b37f735c2347daf90986c Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 22 Feb 2021 21:58:42 +0000 Subject: [PATCH 2/4] fix handling of becomeKeyWindow on OSX. --- native/Avalonia.Native/src/OSX/window.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/Avalonia.Native/src/OSX/window.mm b/native/Avalonia.Native/src/OSX/window.mm index 9d49025398..7fa6614d4d 100644 --- a/native/Avalonia.Native/src/OSX/window.mm +++ b/native/Avalonia.Native/src/OSX/window.mm @@ -2068,17 +2068,17 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent -(void)becomeKeyWindow { + [self showWindowMenuWithAppMenu]; + if([self activateAppropriateChild: true]) { - [self showWindowMenuWithAppMenu]; - if(_parent != nullptr) { _parent->BaseEvents->Activated(); } - - [super becomeKeyWindow]; } + + [super becomeKeyWindow]; } -(void) restoreParentWindow; From 52a3b6ef19e9b74983264f019d2f7184d418659c Mon Sep 17 00:00:00 2001 From: Jeffrey Ye Date: Mon, 22 Feb 2021 23:50:14 -0800 Subject: [PATCH 3/4] Fix #5541 --- src/Avalonia.Dialogs/ManagedFileChooserSources.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Avalonia.Dialogs/ManagedFileChooserSources.cs b/src/Avalonia.Dialogs/ManagedFileChooserSources.cs index 0dc024c4dd..5f2bd7a9cd 100644 --- a/src/Avalonia.Dialogs/ManagedFileChooserSources.cs +++ b/src/Avalonia.Dialogs/ManagedFileChooserSources.cs @@ -71,6 +71,10 @@ namespace Avalonia.Dialogs { return null; } + catch (DirectoryNotFoundException _) + { + return null; + } return new ManagedFileChooserNavigationItem { From ad6b76be7f9eb11a5bfcb32087296e0b9362299d Mon Sep 17 00:00:00 2001 From: Jeffrey Ye Date: Tue, 23 Feb 2021 00:26:46 -0800 Subject: [PATCH 4/4] ignore all exceptions --- src/Avalonia.Dialogs/ManagedFileChooserSources.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Avalonia.Dialogs/ManagedFileChooserSources.cs b/src/Avalonia.Dialogs/ManagedFileChooserSources.cs index 5f2bd7a9cd..050d618ce1 100644 --- a/src/Avalonia.Dialogs/ManagedFileChooserSources.cs +++ b/src/Avalonia.Dialogs/ManagedFileChooserSources.cs @@ -67,11 +67,7 @@ namespace Avalonia.Dialogs { Directory.GetFiles(x.VolumePath); } - catch (UnauthorizedAccessException _) - { - return null; - } - catch (DirectoryNotFoundException _) + catch (Exception _) { return null; }