- add: ServerLink think

This commit is contained in:
2025-01-27 15:55:30 +03:00
parent 1374772d46
commit e1657d9234
12 changed files with 143 additions and 39 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -75,24 +77,29 @@ public partial class AccountInfoViewModel : ViewModelBase
DoAuth();
}
public async void DoAuth()
public void DoAuth()
{
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
message.InfoText = "Auth think, please wait...";
message.IsInfoClosable = false;
Console.WriteLine("AUTH SHIT");
PopupMessageService.Popup(message);
if (await AuthService.Auth(CurrentAlp))
Task.Run(async () =>
{
message.Dispose();
IsLogged = true;
ConfigurationService.SetConfigValue(CurrentConVar.AuthCurrent, CurrentAlp);
}
else
{
message.Dispose();
Logout();
PopupMessageService.Popup("Well, shit is happened: " + AuthService.Reason);
}
if (await AuthService.Auth(CurrentAlp))
{
message.Dispose();
IsLogged = true;
ConfigurationService.SetConfigValue(CurrentConVar.AuthCurrent, CurrentAlp);
}
else
{
message.Dispose();
Logout();
PopupMessageService.Popup("Well, shit is happened: " + AuthService.Reason);
}
});
}
public void Logout()

View File

@@ -40,19 +40,15 @@ public partial class ServerListViewModel : ViewModelBase
foreach (var info in HubService.ServerList) UnsortedServers.Add(info);
HubService.HubServerChangedEventArgs += HubServerChangedEventArgs;
HubService.HubServerLoaded += HubServerLoaded;
HubService.HubServerLoaded += SortServers;
OnSearchChange += OnChangeSearch;
if (!HubService.IsUpdating) SortServers();
}
private void HubServerLoaded()
{
SortServers();
}
private void OnChangeSearch()
{
if(string.IsNullOrEmpty(SearchText)) return;
SortServers();
}

View File

@@ -13,7 +13,8 @@ public partial class InfoPopupViewModel : PopupViewModelBase
[ObservableProperty] private string _infoText = "Test";
public override string Title => "Info";
public override bool IsClosable => true;
public bool IsInfoClosable { get; set; } = true;
public override bool IsClosable => IsInfoClosable;
protected override void Initialise()
{

View File

@@ -8,9 +8,11 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Nebula.Launcher.Services;
using Nebula.Launcher.ViewModels.Popup;
using Nebula.Launcher.Views;
@@ -37,7 +39,8 @@ public partial class ServerEntryModelView : ViewModelBase
[GenerateProperty] private ViewHelperService ViewHelperService { get; } = default!;
[GenerateProperty] private RestService RestService { get; } = default!;
[ObservableProperty] private string _description = "...";
[ObservableProperty] private string _description = "Fetching info...";
public ObservableCollection<ServerLink> Links { get; } = new();
[ObservableProperty] private bool _expandInfo = false;
public bool RunVisible => Process == null;
@@ -79,6 +82,8 @@ public partial class ServerEntryModelView : ViewModelBase
public ObservableCollection<string> Tags { get; } = [];
public ICommand OnLinkGo { get; }= new LinkGoCommand();
private Process? Process
{
get => _p;
@@ -92,8 +97,14 @@ public partial class ServerEntryModelView : ViewModelBase
protected override void InitialiseInDesignMode()
{
Description = "Server of meow girls! Nya~ \nNyaMeow\nOOOINK!!";
Links.Add(new ServerLink("Discord","discord","https://cinka.ru"));
ServerHubInfo = new ServerHubInfo("ss14://localhost",
new ServerStatus("Ameba", "Locala meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow ", ["rp:hrp", "18+"], "Antag", 15, 5, 1, false, DateTime.Now, 100), ["meow:rp"]);
new ServerStatus("Ameba",
"Locala meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow ",
["rp:hrp", "18+"],
"Antag", 15, 5, 1, false
, DateTime.Now, 100),
["meow:rp"]);
}
protected override void Initialise()
@@ -221,7 +232,20 @@ public partial class ServerEntryModelView : ViewModelBase
}
var info = await GetServerInfo();
Description = info != null ? info.Desc : "Server offline";
if (info == null)
{
Description = "Error think!";
return;
}
Description = info.Desc;
Links.Clear();
foreach (var link in info.Links)
{
Links.Add(link);
}
}
private static string FindDotnetPath()
@@ -273,4 +297,24 @@ public sealed class LogInfo
Category = category, Message = message, CategoryColor = color
};
}
}
public class LinkGoCommand : ICommand
{
public LinkGoCommand()
{
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
public bool CanExecute(object? parameter)
{
return true;
}
public void Execute(object? parameter)
{
if(parameter is not string str) return;
Helper.SafeOpenBrowser(str);
}
public event EventHandler? CanExecuteChanged;
}