Switch to main window after login
This commit is contained in:
parent
e86b971d62
commit
60141105ed
@ -48,6 +48,12 @@ public class AuthWindowViewModel: ViewModelBase
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
|
public event EventHandler? ReplaceWithMainWindowEvent;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public AuthWindowViewModel(IApiService apiService, IStorageService storageService)
|
public AuthWindowViewModel(IApiService apiService, IStorageService storageService)
|
||||||
{
|
{
|
||||||
_apiService = apiService;
|
_apiService = apiService;
|
||||||
@ -65,8 +71,8 @@ public class AuthWindowViewModel: ViewModelBase
|
|||||||
private async Task Login()
|
private async Task Login()
|
||||||
{
|
{
|
||||||
var user = await _apiService.Login(Email, Password);
|
var user = await _apiService.Login(Email, Password);
|
||||||
//await _storageService.SetUser(user);
|
await _storageService.SetUser(user);
|
||||||
Close();
|
ReplaceWithMainWindowEvent?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ShowError(Exception error)
|
private async void ShowError(Exception error)
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
using AutoCat.ViewModels;
|
using AutoCat.ViewModels;
|
||||||
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting.Internal;
|
||||||
|
|
||||||
namespace AutoCat.Views;
|
namespace AutoCat.Views;
|
||||||
|
|
||||||
@ -9,10 +13,16 @@ public partial class AuthWindow : Window
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
if (DataContext is ViewModelBase vm)
|
if (DataContext is AuthWindowViewModel vm)
|
||||||
{
|
{
|
||||||
vm.ClosingRequest += (sender, args) =>
|
vm.ReplaceWithMainWindowEvent += (sender, args) =>
|
||||||
{
|
{
|
||||||
|
if (Application.Current is not App app) return;
|
||||||
|
if (app.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return;
|
||||||
|
|
||||||
|
var mainWindow = app.AppHost.Services.GetRequiredService<MainWindow>();
|
||||||
|
mainWindow.Show();
|
||||||
|
desktop.MainWindow = mainWindow;
|
||||||
Close();
|
Close();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user