Skip to content

Commit 0aa6822

Browse files
committed
only init MPVM if it is not already running
1 parent aca680a commit 0aa6822

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Signal-Windows/ViewModels/MainPageViewModel.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public bool ThreadListAlignRight
5151
private AsyncLock ActionInProgress = new AsyncLock();
5252
public MainPage View;
5353
public SignalConversation SelectedThread;
54-
private volatile bool Running = true;
54+
private volatile bool Running = false;
5555
private Task IncomingMessagesTask;
5656
private Task OutgoingMessagesTask;
5757
private CancellationTokenSource CancelSource;
@@ -105,13 +105,22 @@ public MainPageViewModel()
105105
App.MainPageActive = true;
106106
}
107107

108+
public async Task OnNavigatedTo()
109+
{
110+
if (!Running)
111+
{
112+
await Init();
113+
}
114+
}
115+
108116
public async Task Init()
109117
{
110-
CancelSource = new CancellationTokenSource();
111118
Debug.WriteLine("Init lock wait");
112119
using (await ActionInProgress.LockAsync(CancelSource.Token))
113120
{
114121
Debug.WriteLine("Init lock grabbed");
122+
Running = true;
123+
CancelSource = new CancellationTokenSource();
115124
try
116125
{
117126
await Task.Run(async () =>
@@ -176,6 +185,8 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch
176185
catch (AuthorizationFailedException)
177186
{
178187
Debug.WriteLine("OWS server rejected our credentials - redirecting to StartPage");
188+
Running = false;
189+
CancelSource.Cancel();
179190
View.Frame.Navigate(typeof(StartPage));
180191
}
181192
catch (Exception e)
@@ -189,11 +200,11 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch
189200

190201
public async Task Shutdown()
191202
{
192-
Running = false;
193-
App.MainPageActive = false;
194203
Debug.WriteLine("Shutdown lock await");
195204
using (await ActionInProgress.LockAsync())
196205
{
206+
Running = false;
207+
App.MainPageActive = false;
197208
Debug.WriteLine("Shutdown lock grabbed");
198209
CancelSource.Cancel();
199210
await IncomingMessagesTask;

Signal-Windows/Views/MainPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public PageStyle GetCurrentViewStyle()
7272
protected override async void OnNavigatedTo(NavigationEventArgs e)
7373
{
7474
base.OnNavigatedTo(e);
75-
await Vm.Init();
75+
await Vm.OnNavigatedTo();
7676
}
7777

7878
private void Frame_SizeChanged(object sender, SizeChangedEventArgs e)

0 commit comments

Comments
 (0)