diff --git a/Files/App.xaml.cs b/Files/App.xaml.cs index 81bb5fd6b6d4..8473a12edbc7 100644 --- a/Files/App.xaml.cs +++ b/Files/App.xaml.cs @@ -375,10 +375,6 @@ private void OnSuspending(object sender, SuspendingEventArgs e) LibraryManager?.Dispose(); DrivesManager?.Dispose(); deferral.Complete(); - -#if DEBUG - Current.Exit(); -#endif } public static void SaveSessionTabs() // Enumerates through all tabs and gets the Path property and saves it to AppSettings.LastSessionPages diff --git a/Files/ViewModels/ItemViewModel.cs b/Files/ViewModels/ItemViewModel.cs index f7763f91b0fa..f504f7173615 100644 --- a/Files/ViewModels/ItemViewModel.cs +++ b/Files/ViewModels/ItemViewModel.cs @@ -27,7 +27,6 @@ using Windows.Storage; using Windows.Storage.FileProperties; using Windows.Storage.Search; -using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Imaging; @@ -65,7 +64,23 @@ public class ItemViewModel : INotifyPropertyChanged, IDisposable private IFileListCache fileListCache = FileListCacheController.GetInstance(); - private NamedPipeAsAppServiceConnection Connection; + private NamedPipeAsAppServiceConnection connection; + private NamedPipeAsAppServiceConnection Connection + { + get => connection; + set + { + if (connection != null) + { + connection.RequestReceived -= Connection_RequestReceived; + } + connection = value; + if (connection != null) + { + connection.RequestReceived += Connection_RequestReceived; + } + } + } public string WorkingDirectory { @@ -319,19 +334,13 @@ public ItemViewModel(FolderSettingsViewModel folderSettingsViewModel) semaphoreCTS = new CancellationTokenSource(); loadPropsCTS = new CancellationTokenSource(); shouldDisplayFileExtensions = App.AppSettings.ShowFileExtensions; + + AppServiceConnectionHelper.ConnectionChanged += AppServiceConnectionHelper_ConnectionChanged; } - public void OnAppServiceConnectionChanged(NamedPipeAsAppServiceConnection connection) + private async void AppServiceConnectionHelper_ConnectionChanged(object sender, Task e) { - if (Connection != null) - { - Connection.RequestReceived -= Connection_RequestReceived; - } - Connection = connection; - if (Connection != null) - { - Connection.RequestReceived += Connection_RequestReceived; - } + Connection = await e; } private async void Connection_RequestReceived(object sender, Dictionary message) @@ -950,6 +959,8 @@ private async void RapidAddItemsToCollectionAsync(string path, string previousDi ItemLoadStatusChanged?.Invoke(this, new ItemLoadStatusChangedEventArgs() { Status = ItemLoadStatusChangedEventArgs.ItemLoadStatus.InProgress }); + Connection ??= await AppServiceConnectionHelper.Instance; + if (path.ToLower().EndsWith(ShellLibraryItem.EXTENSION)) { if (App.LibraryManager.TryGetLibrary(path, out LibraryLocationItem library) && !library.IsEmpty) @@ -1827,6 +1838,7 @@ public void Dispose() { Connection.RequestReceived -= Connection_RequestReceived; } + AppServiceConnectionHelper.ConnectionChanged -= AppServiceConnectionHelper_ConnectionChanged; } } diff --git a/Files/Views/ColumnShellPage.xaml.cs b/Files/Views/ColumnShellPage.xaml.cs index 35d93cf9e7bc..3ed5d9b78f4f 100644 --- a/Files/Views/ColumnShellPage.xaml.cs +++ b/Files/Views/ColumnShellPage.xaml.cs @@ -546,7 +546,6 @@ private async void Page_Loaded(object sender, RoutedEventArgs e) FilesystemViewModel.PageTypeUpdated += FilesystemViewModel_PageTypeUpdated; OnNavigationParamsChanged(); ServiceConnection = await AppServiceConnectionHelper.Instance; - FilesystemViewModel.OnAppServiceConnectionChanged(ServiceConnection); this.Loaded -= Page_Loaded; } @@ -805,7 +804,6 @@ public void Dispose() private async void AppServiceConnectionHelper_ConnectionChanged(object sender, Task e) { ServiceConnection = await e; - FilesystemViewModel?.OnAppServiceConnectionChanged(ServiceConnection); } private void FilesystemViewModel_ItemLoadStatusChanged(object sender, ItemLoadStatusChangedEventArgs e) @@ -875,11 +873,10 @@ private void SetLoadingIndicatorForTabs(bool isLoading) foreach (var x in multitaskingControls) { - x.SetLoadingIndicatorStatus(x.Items.First(x => x.Control == tabItemControl), isLoading); + x.SetLoadingIndicatorStatus(x.Items.FirstOrDefault(x => x.Control == tabItemControl), isLoading); } } - public DataPackageOperation TabItemDragOver(object sender, DragEventArgs e) { if (e.DataView.AvailableFormats.Contains(StandardDataFormats.StorageItems)) diff --git a/Files/Views/ModernShellPage.xaml.cs b/Files/Views/ModernShellPage.xaml.cs index 4c948543c670..e007d7cdbfcd 100644 --- a/Files/Views/ModernShellPage.xaml.cs +++ b/Files/Views/ModernShellPage.xaml.cs @@ -574,7 +574,6 @@ private async void Page_Loaded(object sender, RoutedEventArgs e) FilesystemViewModel.PageTypeUpdated += FilesystemViewModel_PageTypeUpdated; OnNavigationParamsChanged(); ServiceConnection = await AppServiceConnectionHelper.Instance; - FilesystemViewModel.OnAppServiceConnectionChanged(ServiceConnection); this.Loaded -= Page_Loaded; } @@ -942,7 +941,6 @@ public void Dispose() private async void AppServiceConnectionHelper_ConnectionChanged(object sender, Task e) { ServiceConnection = await e; - FilesystemViewModel?.OnAppServiceConnectionChanged(ServiceConnection); } private void FilesystemViewModel_ItemLoadStatusChanged(object sender, ItemLoadStatusChangedEventArgs e) @@ -1012,7 +1010,7 @@ private void SetLoadingIndicatorForTabs(bool isLoading) foreach (var x in multitaskingControls) { - x.SetLoadingIndicatorStatus(x.Items.First(x => x.Control == tabItemControl), isLoading); + x.SetLoadingIndicatorStatus(x.Items.FirstOrDefault(x => x.Control == tabItemControl), isLoading); } }