Jelajahi Sumber

Merge pull request #2947 from AvaloniaUI/fix/managed-file-dialogs

Fix/managed file dialogs
Jumar Macato 6 tahun lalu
induk
melakukan
89345a5c09

+ 0 - 1
scripts/ReplaceNugetCache.sh

@@ -2,7 +2,6 @@
  
  cp ../samples/ControlCatalog.NetCore/bin/Debug/netcoreapp2.0/Avalonia**.dll ~/.nuget/packages/avalonia/$1/lib/netcoreapp2.0/
  cp ../samples/ControlCatalog.NetCore/bin/Debug/netcoreapp2.0/Avalonia**.dll ~/.nuget/packages/avalonia/$1/lib/netstandard2.0/
- cp ../samples/ControlCatalog.NetCore/bin/Debug/netcoreapp2.0/Avalonia**.dll ~/.nuget/packages/avalonia.gtk3/$1/lib/netstandard2.0/
  cp ../samples/ControlCatalog.NetCore/bin/Debug/netcoreapp2.0/Avalonia**.dll ~/.nuget/packages/avalonia.skia/$1/lib/netstandard2.0/
  cp ../samples/ControlCatalog.NetCore/bin/Debug/netcoreapp2.0/Avalonia**.dll ~/.nuget/packages/avalonia.native/$1/lib/netstandard2.0/
  

+ 10 - 9
src/Avalonia.Native/MacOSMountedVolumeInfoProvider.cs

@@ -8,16 +8,16 @@ using Avalonia.Controls.Platform;
 
 namespace Avalonia.Native
 {
-    internal class WindowsMountedVolumeInfoListener : IDisposable
+    internal class MacOSMountedVolumeInfoListener : IDisposable
     {
         private readonly CompositeDisposable _disposables;
-        private readonly ObservableCollection<MountedVolumeInfo> _targetObs;
         private bool _beenDisposed = false;
         private ObservableCollection<MountedVolumeInfo> mountedDrives;
 
-        public WindowsMountedVolumeInfoListener(ObservableCollection<MountedVolumeInfo> mountedDrives)
+        public MacOSMountedVolumeInfoListener(ObservableCollection<MountedVolumeInfo> mountedDrives)
         {
             this.mountedDrives = mountedDrives;
+
             _disposables = new CompositeDisposable();
 
             var pollTimer = Observable.Interval(TimeSpan.FromSeconds(1))
@@ -30,7 +30,8 @@ namespace Avalonia.Native
 
         private void Poll(long _)
         {
-            var mountVolInfos = Directory.GetDirectories("/Volumes")
+            var mountVolInfos = Directory.GetDirectories("/Volumes/")
+                                .Where(p=> p != null)
                                 .Select(p => new MountedVolumeInfo()
                                 {
                                     VolumeLabel = Path.GetFileName(p),
@@ -38,15 +39,15 @@ namespace Avalonia.Native
                                     VolumeSizeBytes = 0
                                 })
                                 .ToArray();
-
-            if (_targetObs.SequenceEqual(mountVolInfos))
+                                
+            if (mountedDrives.SequenceEqual(mountVolInfos))
                 return;
             else
             {
-                _targetObs.Clear();
+                mountedDrives.Clear();
 
                 foreach (var i in mountVolInfos)
-                    _targetObs.Add(i);
+                    mountedDrives.Add(i);
             }
         }
 
@@ -72,7 +73,7 @@ namespace Avalonia.Native
         public IDisposable Listen(ObservableCollection<MountedVolumeInfo> mountedDrives)
         {
             Contract.Requires<ArgumentNullException>(mountedDrives != null);
-            return new WindowsMountedVolumeInfoListener(mountedDrives);
+            return new MacOSMountedVolumeInfoListener(mountedDrives);
         }
     }
 }

+ 4 - 5
src/Windows/Avalonia.Win32/WindowsMountedVolumeInfoListener.cs

@@ -10,8 +10,7 @@ namespace Avalonia.Win32
 {
     internal class WindowsMountedVolumeInfoListener : IDisposable
     {
-        private readonly CompositeDisposable _disposables;
-        private readonly ObservableCollection<MountedVolumeInfo> _targetObs = new ObservableCollection<MountedVolumeInfo>();
+        private readonly CompositeDisposable _disposables;        
         private bool _beenDisposed = false;
         private ObservableCollection<MountedVolumeInfo> mountedDrives;
 
@@ -41,14 +40,14 @@ namespace Avalonia.Win32
                                 })
                                 .ToArray();
 
-            if (_targetObs.SequenceEqual(mountVolInfos))
+            if (mountedDrives.SequenceEqual(mountVolInfos))
                 return;
             else
             {
-                _targetObs.Clear();
+                mountedDrives.Clear();
 
                 foreach (var i in mountVolInfos)
-                    _targetObs.Add(i);
+                    mountedDrives.Add(i);
             }
         }