diff --git a/src/client/spark/Services/SparkLoginGuiService.cs b/src/client/spark/Services/SparkLoginGuiService.cs index 4185a8ffe..da09a781b 100644 --- a/src/client/spark/Services/SparkLoginGuiService.cs +++ b/src/client/spark/Services/SparkLoginGuiService.cs @@ -19,10 +19,12 @@ class SparkLoginGuiService : IHostedService, ISparkLoginGuiService { readonly ISparkConfigLoader configLoader; readonly TaskCompletionSource<(LoginResult Result, AuthTokenImmutable? Token, string? Workspace)> loginTcs = new(); readonly ServiceContext serviceProvider; + readonly IHostApplicationLifetime lifetime; - public SparkLoginGuiService(ISparkConfigLoader configLoader, ServiceContext serviceProvider) { + public SparkLoginGuiService(ISparkConfigLoader configLoader, ServiceContext serviceProvider, IHostApplicationLifetime lifetime) { this.configLoader = configLoader; this.serviceProvider = serviceProvider; + this.lifetime = lifetime; } public async ValueTask<(LoginResult Result, AuthTokenImmutable? Token, string? Workspace)> LoginAsync() => @@ -44,6 +46,7 @@ class SparkLoginGuiService : IHostedService, ISparkLoginGuiService { var vm = new LoginViewModel(model, Dispatcher.CurrentDispatcher); var view = new LoginView(vm); vm.LoggedIn += OnLoggedIn; + vm.Canceled += OnCanceled; model.init().ignore(); view.ShowDialog(); // ShowDialog returns when the window is closed. If the login is successful, @@ -57,6 +60,11 @@ class SparkLoginGuiService : IHostedService, ISparkLoginGuiService { loginTcs.SetResult((new LoginResult() { user = new(userId, userName), success = true, Token = token }, token, workspace)); view.Close(); } + + void OnCanceled() { + loginTcs.TrySetCanceled(); + lifetime.StopApplication(); + } } } diff --git a/src/client/spark/view/Shell/Login/LoginModel.cs b/src/client/spark/view/Shell/Login/LoginModel.cs index 3024a01cd..92c7663ec 100644 --- a/src/client/spark/view/Shell/Login/LoginModel.cs +++ b/src/client/spark/view/Shell/Login/LoginModel.cs @@ -52,6 +52,9 @@ namespace mbts.ui.shell { return _instance.Value; } + public void OnCanceled() => + _frame.Continue = false; + public bool try_get_user(string name, out User user) => Users.TryGetFirst(u => u.name == name, out user); diff --git a/src/client/spark/view/Shell/Login/LoginViewModel.cs b/src/client/spark/view/Shell/Login/LoginViewModel.cs index b3adcdfac..9da69eea2 100644 --- a/src/client/spark/view/Shell/Login/LoginViewModel.cs +++ b/src/client/spark/view/Shell/Login/LoginViewModel.cs @@ -37,6 +37,7 @@ namespace mbts.ui.shell { public event Action ready; public event Action begin_login; public event Action LoggedIn; + public event Action Canceled; private void OnSendMail(object obj) { string uri_base = obj as string; @@ -169,6 +170,8 @@ namespace mbts.ui.shell { } } private void OnCancel(object unused) { + _model.OnCanceled(); + Canceled?.Invoke(); CloseView(); Application.Current?.Dispatcher?.InvokeAsync(() => Application.Current.Shutdown(0)); }