Skip to content

Commit f7fa6fa

Browse files
authored
Fix: Fixed NullReferenceException in MainPageViewModel.UpdateInstancePropertiesAsync (#13900)
1 parent 4826f55 commit f7fa6fa

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/Files.App/ViewModels/MainPageViewModel.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,30 +135,33 @@ public async Task AddNewTabByPathAsync(Type type, string? path, int atIndex = -1
135135

136136
public async Task UpdateInstancePropertiesAsync(object navigationArg)
137137
{
138-
string windowTitle = string.Empty;
139-
if (navigationArg is PaneNavigationArguments paneArgs)
138+
await SafetyExtensions.IgnoreExceptions(async () =>
140139
{
141-
if (!string.IsNullOrEmpty(paneArgs.LeftPaneNavPathParam) && !string.IsNullOrEmpty(paneArgs.RightPaneNavPathParam))
140+
string windowTitle = string.Empty;
141+
if (navigationArg is PaneNavigationArguments paneArgs)
142142
{
143-
var leftTabInfo = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam);
144-
var rightTabInfo = await GetSelectedTabInfoAsync(paneArgs.RightPaneNavPathParam);
145-
windowTitle = $"{leftTabInfo.tabLocationHeader} | {rightTabInfo.tabLocationHeader}";
143+
if (!string.IsNullOrEmpty(paneArgs.LeftPaneNavPathParam) && !string.IsNullOrEmpty(paneArgs.RightPaneNavPathParam))
144+
{
145+
var leftTabInfo = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam);
146+
var rightTabInfo = await GetSelectedTabInfoAsync(paneArgs.RightPaneNavPathParam);
147+
windowTitle = $"{leftTabInfo.tabLocationHeader} | {rightTabInfo.tabLocationHeader}";
148+
}
149+
else
150+
{
151+
(windowTitle, _, _) = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam);
152+
}
146153
}
147-
else
154+
else if (navigationArg is string pathArgs)
148155
{
149-
(windowTitle, _, _) = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam);
156+
(windowTitle, _, _) = await GetSelectedTabInfoAsync(pathArgs);
150157
}
151-
}
152-
else if (navigationArg is string pathArgs)
153-
{
154-
(windowTitle, _, _) = await GetSelectedTabInfoAsync(pathArgs);
155-
}
156158

157-
if (AppInstances.Count > 1)
158-
windowTitle = $"{windowTitle} ({AppInstances.Count})";
159+
if (AppInstances.Count > 1)
160+
windowTitle = $"{windowTitle} ({AppInstances.Count})";
159161

160-
if (navigationArg == SelectedTabItem?.NavigationParameter?.NavigationParameter)
161-
MainWindow.Instance.AppWindow.Title = $"{windowTitle} - Files";
162+
if (navigationArg == SelectedTabItem?.NavigationParameter?.NavigationParameter)
163+
MainWindow.Instance.AppWindow.Title = $"{windowTitle} - Files";
164+
});
162165
}
163166

164167
public async Task UpdateTabInfoAsync(Files.App.UserControls.TabBar.TabBarItem tabItem, object navigationArg)

0 commit comments

Comments
 (0)