Skip to content

Commit 9782b79

Browse files
author
Thomas Felices
committed
Fix activation launch and potential threading issues
1 parent 047312e commit 9782b79

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

src/Client/Common/ProtonVPN.Client.Common/Observers/ObserverBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public ObserverBase(ILogger logger, IIssueReporter issueReporter)
3838
TriggerAction = new SingleAction(OnSafeTriggerAsync);
3939
}
4040

41-
private void OnSafeTriggerAsync()
41+
private async Task OnSafeTriggerAsync()
4242
{
4343
try
4444
{
45-
OnTriggerAsync();
45+
await OnTriggerAsync();
4646
}
4747
catch (Exception ex)
4848
{

src/Client/Logic/Servers/ProtonVPN.Client.Logic.Servers/Observers/DeviceLocationObserver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private async Task FetchDeviceLocationAsync(int delayInMs)
151151

152152
await Task.Delay(delayInMs);
153153

154-
await OnTriggerAsync();
154+
TriggerAction.Run();
155155
}
156156
finally
157157
{

src/Client/ProtonVPN.Client/Services/Bootstrapping/Bootstrapper.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,15 @@ await _mainWindowOverlayActivator.ShowLoadingMessageAsync(
179179

180180
private void OnCurrentAppInstanceActivated(object? sender, AppActivationArguments e)
181181
{
182-
if (e.Kind == ExtendedActivationKind.Protocol)
182+
switch (e.Kind)
183183
{
184-
HandleProtocolActivationArguments(e.Data as ProtocolActivatedEventArgs);
184+
case ExtendedActivationKind.Protocol:
185+
HandleProtocolActivationArguments(e.Data as ProtocolActivatedEventArgs);
186+
break;
187+
default:
188+
_logger.Debug<AppLog>($"Handle {e.Kind} activation - Activate window");
189+
_mainWindowActivator.Activate();
190+
break;
185191
}
186192
}
187193

src/Client/ProtonVPN.Client/Services/Bootstrapping/Helpers/AppInstanceHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static void RedirectActivationTo(AppInstance keyInstance, AppActivationA
6363
[_redirectEventHandle], out uint handleIndex);
6464

6565
// Bring the window to the foreground
66-
//BringToForeground();
66+
BringToForeground();
6767
}
6868

6969
private static void BringToForeground()

src/Common/ProtonVPN.Common.Core/Threading/TaskCompletionSourceExtensions.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,27 @@ public static class TaskCompletionSourceExtensions
2323
{
2424
public static Task Wrap(this TaskCompletionSource<object?> source, Func<Task> action)
2525
{
26-
return source.Wrap(async () =>
26+
return source.WrapAsync(async () =>
2727
{
2828
await action();
2929
return null;
3030
});
3131
}
3232

33-
public static async Task Wrap<T>(this TaskCompletionSource<T?> source, Func<Task<T?>> function)
33+
public static async Task WrapAsync<T>(this TaskCompletionSource<T?> source, Func<Task<T?>> function)
3434
{
3535
try
3636
{
37-
source.SetResult(await function());
37+
T? result = await function();
38+
source.TrySetResult(result);
3839
}
3940
catch (OperationCanceledException)
4041
{
41-
source.SetCanceled();
42+
source.TrySetCanceled();
4243
}
4344
catch (Exception e)
4445
{
45-
source.SetException(e);
46+
source.TrySetException(e);
4647
}
4748
}
4849
}

0 commit comments

Comments
 (0)