From f7fa6fad376863967a598db3513f3ab1bbb114d9 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Thu, 16 Nov 2023 11:21:44 +0900 Subject: [PATCH] Fix: Fixed NullReferenceException in MainPageViewModel.UpdateInstancePropertiesAsync (#13900) --- src/Files.App/ViewModels/MainPageViewModel.cs | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Files.App/ViewModels/MainPageViewModel.cs b/src/Files.App/ViewModels/MainPageViewModel.cs index bd6fc4077a97..0ed0094b602f 100644 --- a/src/Files.App/ViewModels/MainPageViewModel.cs +++ b/src/Files.App/ViewModels/MainPageViewModel.cs @@ -135,30 +135,33 @@ public async Task AddNewTabByPathAsync(Type type, string? path, int atIndex = -1 public async Task UpdateInstancePropertiesAsync(object navigationArg) { - string windowTitle = string.Empty; - if (navigationArg is PaneNavigationArguments paneArgs) + await SafetyExtensions.IgnoreExceptions(async () => { - if (!string.IsNullOrEmpty(paneArgs.LeftPaneNavPathParam) && !string.IsNullOrEmpty(paneArgs.RightPaneNavPathParam)) + string windowTitle = string.Empty; + if (navigationArg is PaneNavigationArguments paneArgs) { - var leftTabInfo = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam); - var rightTabInfo = await GetSelectedTabInfoAsync(paneArgs.RightPaneNavPathParam); - windowTitle = $"{leftTabInfo.tabLocationHeader} | {rightTabInfo.tabLocationHeader}"; + if (!string.IsNullOrEmpty(paneArgs.LeftPaneNavPathParam) && !string.IsNullOrEmpty(paneArgs.RightPaneNavPathParam)) + { + var leftTabInfo = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam); + var rightTabInfo = await GetSelectedTabInfoAsync(paneArgs.RightPaneNavPathParam); + windowTitle = $"{leftTabInfo.tabLocationHeader} | {rightTabInfo.tabLocationHeader}"; + } + else + { + (windowTitle, _, _) = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam); + } } - else + else if (navigationArg is string pathArgs) { - (windowTitle, _, _) = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam); + (windowTitle, _, _) = await GetSelectedTabInfoAsync(pathArgs); } - } - else if (navigationArg is string pathArgs) - { - (windowTitle, _, _) = await GetSelectedTabInfoAsync(pathArgs); - } - if (AppInstances.Count > 1) - windowTitle = $"{windowTitle} ({AppInstances.Count})"; + if (AppInstances.Count > 1) + windowTitle = $"{windowTitle} ({AppInstances.Count})"; - if (navigationArg == SelectedTabItem?.NavigationParameter?.NavigationParameter) - MainWindow.Instance.AppWindow.Title = $"{windowTitle} - Files"; + if (navigationArg == SelectedTabItem?.NavigationParameter?.NavigationParameter) + MainWindow.Instance.AppWindow.Title = $"{windowTitle} - Files"; + }); } public async Task UpdateTabInfoAsync(Files.App.UserControls.TabBar.TabBarItem tabItem, object navigationArg)