Skip to content

Commit f09ba5d

Browse files
committed
fix crash when clicking on toasts, make toast handling more resilient
1 parent 2f97782 commit f09ba5d

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

Signal-Windows/App.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ protected override async void OnActivated(IActivatedEventArgs args)
9595
Logger.LogInformation("OnActivated() {0}", args.GetType());
9696
if (args is ToastNotificationActivatedEventArgs toastArgs)
9797
{
98-
bool createdMainWindow = await CreateMainWindow(toastArgs.Argument);
98+
string requestedConversation = toastArgs.Argument;
99+
bool createdMainWindow = await CreateMainWindow(requestedConversation);
99100
if (!createdMainWindow)
100101
{
101102
if (args is IViewSwitcherProvider viewSwitcherProvider && viewSwitcherProvider.ViewSwitcher != null)
@@ -107,13 +108,13 @@ protected override async void OnActivated(IActivatedEventArgs args)
107108
await Views[currentId].Dispatcher.RunTaskAsync(() =>
108109
{
109110
Logger.LogInformation("OnActivated() selecting conversation");
110-
Views[currentId].Locator.MainPageInstance.SelectConversation(toastArgs.Argument);
111+
Views[currentId].Locator.MainPageInstance.TrySelectConversation(requestedConversation);
111112
});
112113
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(currentId);
113114
}
114115
else
115116
{
116-
await CreateSecondaryWindowOrShowMain(switcher, toastArgs.Argument);
117+
await CreateSecondaryWindowOrShowMain(switcher, requestedConversation);
117118
}
118119
}
119120
else

Signal-Windows/ViewModels/MainPageViewModel.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,16 @@ internal async Task SendMessageButton_Click(TextBox messageTextBox)
148148
messageTextBox.Focus(FocusState.Programmatic);
149149
}
150150

151-
public void SelectConversation(string conversationId)
151+
public void TrySelectConversation(string conversationId)
152152
{
153-
SelectedConversation = ConversationsDictionary[conversationId];
153+
if (ConversationsDictionary.ContainsKey(conversationId))
154+
{
155+
SelectedConversation = ConversationsDictionary[conversationId];
156+
}
157+
else
158+
{
159+
Logger.LogError("TrySelectConversation could not select conversation: key is not present");
160+
}
154161
}
155162

156163
public void ConversationsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -276,17 +283,17 @@ public void ReplaceConversationList(List<SignalConversation> conversations)
276283
{
277284
ConversationsDictionary.Add(c.ThreadId, c);
278285
}
279-
if (SelectedThread != null)
280-
{
281-
Logger.LogDebug("SelectedThread is != null, refreshing");
282-
SelectedThread = ConversationsDictionary[SelectedThread.ThreadId];
283-
SelectConversation(SelectedThread.ThreadId);
284-
}
285-
286286
if (RequestedConversationId != null && RequestedConversationId != "")
287287
{
288288
Logger.LogDebug("RequestedConversationId is != null, refreshing");
289-
SelectConversation(RequestedConversationId);
289+
TrySelectConversation(RequestedConversationId);
290+
RequestedConversationId = null;
291+
}
292+
else if (SelectedThread != null)
293+
{
294+
Logger.LogDebug("SelectedThread is != null, refreshing");
295+
SelectedThread = ConversationsDictionary[SelectedThread.ThreadId];
296+
TrySelectConversation(SelectedThread.ThreadId);
290297
}
291298
}
292299

Signal-Windows/Views/MainPage.xaml.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
8585
UpdateLayout();
8686
SwitchToStyle(GetCurrentViewStyle());
8787
MainPanel.DisplayMode = SplitViewDisplayMode.CompactInline;
88-
if (Vm.RequestedConversationId != null && Vm.RequestedConversationId != "")
89-
{
90-
Vm.SelectConversation(Vm.RequestedConversationId);
91-
}
92-
else if (Vm.SelectedThread != null)
93-
{
94-
ConversationControl.Load(Vm.SelectedThread);
95-
}
9688
Frame.SizeChanged += Frame_SizeChanged;
9789
}
9890

0 commit comments

Comments
 (0)