- add: Foolproof

This commit is contained in:
2025-07-05 20:39:36 +03:00
parent 3bfae32c25
commit a3c96174b2
12 changed files with 179 additions and 10 deletions

View File

@@ -33,6 +33,7 @@
<entry key="Nebula.Launcher/Views/Popup/ExceptionListView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
<entry key="Nebula.Launcher/Views/Popup/ExceptionView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
<entry key="Nebula.Launcher/Views/Popup/InfoPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
<entry key="Nebula.Launcher/Views/Popup/IsLoginCredentialsNullPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
<entry key="Nebula.Launcher/Views/Popup/LoadingContextView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
<entry key="Nebula.Launcher/Views/Popup/LogPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
<entry key="Nebula.Launcher/Views/Popup/MessagePopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />

View File

@@ -25,6 +25,8 @@ account-auth-button = Authenticate
account-auth-save = Save Profile
account-auth-hello = Hello,
account-auth-logout = Log out
auth-current-login-name = Current login: {$login}
auth-current-login-no-name = Profile not selected
auth-processing = Processing authentication request...
auth-error = An authentication error has occurred.
@@ -45,6 +47,7 @@ config-remove-content-all = Remove all content
filter-roleplay = Roleplay
filter-language = Language
favorite-add = Add to favorites
popup-add-favorite-invalid-ip = Please enter a valid IP
servername-set = Set server name
servername-clear = Clear server name
twofa-enabled = You have two-factor authentication enabled. Please enter the code.
@@ -56,4 +59,10 @@ serverentry-map = Map
serverentry-preset = Preset
content-view-server = Server url
content-view-path = Path
content-view-path = Path
popup-login-credentials-warning = Warning! No credentials provided!
popup-login-credentials-warning-label = Warning! No credentials provided! The servers will not be able to let you in due to lack of authorization. Please keep this in mind.
popup-login-credentials-warning-go-auth = Go to auth page
popup-login-credentials-warning-cancel = Cancel
popup-login-credentials-warning-proceed = Proceed

View File

@@ -25,6 +25,8 @@ account-auth-button = Аутентифицировать
account-auth-save = Сохранить профиль
account-auth-hello = Привет,
account-auth-logout = Выйти
auth-current-login-name = Текущий профиль: {$login}
auth-current-login-no-name = Профиль не выбран
auth-processing = Обработка запроса аутентификации...
auth-error = Произошла ошибка аутентификации.
@@ -45,6 +47,7 @@ config-remove-content-all = Удалить весь контент
filter-roleplay = Ролевая игра
filter-language = Язык
favorite-add = Добавить в избранное
popup-add-favorite-invalid-ip = Пожалуйста, введите валидный адрес
servername-set = Установить имя сервера
servername-clear = Очистить
twofa-enabled = У вас включена двухфакторная аутентификация. Введите код.
@@ -56,4 +59,10 @@ serverentry-map = Карта
serverentry-preset = Режим
content-view-server = Сервер
content-view-path = Путь
content-view-path = Путь
popup-login-credentials-warning = Предупреждение! Учетные данные не указаны!
popup-login-credentials-warning-label = Предупреждение! Учетные данные не указаны! Серверы не смогут пропустить вас из-за отсутствия авторизации. Пожалуйста, имейте это в виду.
popup-login-credentials-warning-go-auth = Перейти на страницу авторизации
popup-login-credentials-warning-cancel = Отмена
popup-login-credentials-warning-proceed = Продолжить

View File

@@ -51,16 +51,15 @@ public partial class LocalisationService
Initialise();
}
public static string GetString(string locale)
public static string GetString(string locale, Dictionary<string, object>? options = null)
{
if (_currentMessageContext is null)
{
Console.WriteLine("ERROR SHIT BITHC!");
return locale;
}
var message = _currentMessageContext.GetMessage(locale);
if (message == null) return locale;
return _currentMessageContext.Format(message, new Dictionary<string, object>());
return _currentMessageContext.Format(message, options ?? []);
}
}

View File

@@ -41,7 +41,17 @@ public partial class MainViewModel : ViewModelBase
[ObservableProperty] private bool _popup;
[ObservableProperty] private ListItemTemplate? _selectedListItem;
public bool IsLoggedIn => AuthService.SelectedAuth is not null;
public string LoginName => AuthService.SelectedAuth?.Login ?? string.Empty;
public string LoginText => Services.LocalisationService.GetString("auth-current-login-name",
new Dictionary<string, object>
{
{ "login", LoginName }
});
[GenerateProperty] private LocalisationService LocalisationService { get; }
[GenerateProperty] private AuthService AuthService { get; }
[GenerateProperty] private DebugService DebugService { get; } = default!;
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
[GenerateProperty] private ContentService ContentService { get; } = default!;
@@ -136,6 +146,12 @@ public partial class MainViewModel : ViewModelBase
CurrentPage = obj;
}
public void InvokeChangeAuth()
{
OnPropertyChanged(nameof(IsLoggedIn));
OnPropertyChanged(nameof(LoginText));
}
public void PopupMessage(PopupViewModelBase viewModelBase)
{
if (CurrentPopup == null)
@@ -163,6 +179,11 @@ public partial class MainViewModel : ViewModelBase
Popup = true;
}
public void OpenAuthPage()
{
RequirePage<AccountInfoViewModel>();
}
public void OpenLink()
{
Helper.OpenBrowser("https://durenko.tatar/nebula");

View File

@@ -142,6 +142,7 @@ public partial class AccountInfoViewModel : ViewModelBase
try
{
await a();
ViewHelperService.GetViewModel<MainViewModel>().InvokeChangeAuth();
}
catch (AuthException e)
{
@@ -200,6 +201,7 @@ public partial class AccountInfoViewModel : ViewModelBase
{
IsLogged = false;
AuthService.ClearAuth();
ViewHelperService.GetViewModel<MainViewModel>().InvokeChangeAuth();
}
private void UpdateAuthMenu()

View File

@@ -42,6 +42,9 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
{
try
{
if(string.IsNullOrWhiteSpace(IpInput))
throw new Exception(LocalisationService.GetString("popup-add-favorite-invalid-ip"));
var uri = IpInput.ToRobustUrl();
FavoriteServerListProvider.AddFavorite(uri);
Dispose();

View File

@@ -0,0 +1,50 @@
using Nebula.Launcher.Services;
using Nebula.Launcher.ViewModels.Pages;
using Nebula.Launcher.Views.Popup;
using Nebula.Shared.Services;
using Nebula.Shared.ViewHelper;
namespace Nebula.Launcher.ViewModels.Popup;
[ConstructGenerator, ViewModelRegister(typeof(IsLoginCredentialsNullPopupView))]
public partial class IsLoginCredentialsNullPopupViewModel : PopupViewModelBase
{
private ServerEntryModelView _entry;
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; }
protected override void InitialiseInDesignMode()
{
}
protected override void Initialise()
{
}
public IsLoginCredentialsNullPopupViewModel WithServerEntry(ServerEntryModelView entryModelView)
{
_entry = entryModelView;
return this;
}
public void Proceed()
{
_entry.RunInstanceIgnoreAuth();
Dispose();
}
public void Cancel()
{
Dispose();
}
public void GotoAuthPage()
{
ViewHelperService.GetViewModel<MainViewModel>().RequirePage<AccountInfoViewModel>();
Dispose();
}
public override string Title => LocalisationService.GetString("popup-login-credentials-warning");
public override bool IsClosable => true;
}

View File

@@ -47,7 +47,7 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis
public LogPopupModelView CurrLog;
public RobustUrl Address { get; private set; }
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
[GenerateProperty] private AuthService AuthService { get; }
[GenerateProperty] private CancellationService CancellationService { get; } = default!;
[GenerateProperty] private DebugService DebugService { get; } = default!;
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
@@ -163,11 +163,26 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis
public void RunInstance()
{
CurrLog.Clear();
Task.Run(RunInstanceAsync);
Task.Run(async ()=> await RunInstanceAsync());
}
private async void RunInstanceAsync()
public void RunInstanceIgnoreAuth()
{
CurrLog.Clear();
Task.Run(async ()=> await RunInstanceAsync(true));
}
private async Task RunInstanceAsync(bool ignoreLoginCredentials = false)
{
if (!ignoreLoginCredentials && AuthService.SelectedAuth is null)
{
var warningContext = ViewHelperService.GetViewModel<IsLoginCredentialsNullPopupViewModel>()
.WithServerEntry(this);
PopupMessageService.Popup(warningContext);
return;
}
using var loadingContext = ViewHelperService.GetViewModel<LoadingContextViewModel>();
loadingContext.LoadingName = "Loading instance...";
((ILoadingHandler)loadingContext).AppendJob();

View File

@@ -10,7 +10,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:models1="clr-namespace:Nebula.Launcher.Models">
xmlns:models1="clr-namespace:Nebula.Launcher.Models"
xmlns:services="clr-namespace:Nebula.Launcher.Services">
<Design.DataContext>
<viewModels:MainViewModel />
</Design.DataContext>
@@ -120,7 +121,20 @@
https://durenko.tatar/nebula/
</TextBlock>
</Button>
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding VersionInfo}"/>
<StackPanel Spacing="5" HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal">
<Button
Margin="0"
Padding="0"
CornerRadius="0"
Command="{Binding OpenAuthPage}">
<Panel>
<TextBlock Foreground="#777777" IsVisible="{Binding IsLoggedIn}" Text="{Binding LoginText}"/>
<TextBlock Foreground="#777777" IsVisible="{Binding !IsLoggedIn}" Text="{services:LocaledText auth-current-login-no-name}"/>
</Panel>
</Button>
<TextBlock>|</TextBlock>
<TextBlock Text="{Binding VersionInfo}"/>
</StackPanel>
</Panel>
</Label>
</Border>

View File

@@ -0,0 +1,35 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
xmlns:controls="clr-namespace:Nebula.Launcher.Controls"
xmlns:services="clr-namespace:Nebula.Launcher.Services"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Nebula.Launcher.Views.Popup.IsLoginCredentialsNullPopupView"
x:DataType="popup:IsLoginCredentialsNullPopupViewModel">
<Design.DataContext>
<popup:IsLoginCredentialsNullPopupViewModel />
</Design.DataContext>
<StackPanel Margin="15" Orientation="Vertical" Spacing="15">
<TextBlock HorizontalAlignment="Center" Text="{services:LocaledText popup-login-credentials-warning-label}" TextWrapping="Wrap"/>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="5">
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
<Button Command="{Binding GotoAuthPage}">
<TextBlock Text="{services:LocaledText popup-login-credentials-warning-go-auth}"/>
</Button>
</Border>
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
<Button Command="{Binding Cancel}">
<TextBlock Text="{services:LocaledText popup-login-credentials-warning-cancel}"/>
</Button>
</Border>
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
<Button Command="{Binding Proceed}">
<TextBlock Text="{services:LocaledText popup-login-credentials-warning-proceed}"/>
</Button>
</Border>
</StackPanel>
</StackPanel>
</UserControl>

View File

@@ -0,0 +1,11 @@
using Avalonia.Controls;
namespace Nebula.Launcher.Views.Popup;
public partial class IsLoginCredentialsNullPopupView : UserControl
{
public IsLoginCredentialsNullPopupView()
{
InitializeComponent();
}
}