fix: Shutdown application when user closes login dialog
Previously, it would hang until you manually killed the process.
This commit is contained in:
1 parent
7719aaa2b3
commit
c5ea913e27
3 files changed
+15
-1
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user