- 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

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0,0,256,256" width="50px" height="50px" fill-rule="nonzero"><g fill="#ffffff" fill-rule="nonzero" stroke="none" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="none" font-size="none" style="mix-blend-mode: normal"><g transform="scale(5.12,5.12)"><path d="M18.90625,7c0,0 -6.36719,0.4375 -10.53125,3.78125c-0.01953,0.00781 -0.04297,0.01953 -0.0625,0.03125c-0.72266,0.66797 -1.26562,1.70313 -1.9375,3.1875c-0.67187,1.48438 -1.38281,3.39453 -2.03125,5.53125c-1.29297,4.27734 -2.34375,9.52734 -2.34375,14.46875c-0.00391,0.17578 0.03906,0.34766 0.125,0.5c1.46094,2.56641 4.14844,4.11719 6.65625,5.09375c2.50781,0.97656 4.82422,1.36719 6,1.40625c0.33203,0.01172 0.64844,-0.14062 0.84375,-0.40625l2.4375,-3.375c1.96484,0.46484 4.26953,0.78125 6.9375,0.78125c2.66797,0 4.97266,-0.31641 6.9375,-0.78125l2.4375,3.375c0.19531,0.26563 0.51172,0.41797 0.84375,0.40625c1.17578,-0.03906 3.49219,-0.42969 6,-1.40625c2.50781,-0.97656 5.19531,-2.52734 6.65625,-5.09375c0.08594,-0.15234 0.12891,-0.32422 0.125,-0.5c0,-4.94141 -1.05078,-10.19141 -2.34375,-14.46875c-0.64844,-2.13672 -1.35937,-4.04687 -2.03125,-5.53125c-0.67187,-1.48437 -1.21484,-2.51953 -1.9375,-3.1875c-0.01953,-0.01172 -0.04297,-0.02344 -0.0625,-0.03125c-4.16406,-3.34375 -10.53125,-3.78125 -10.53125,-3.78125c-0.07422,-0.00781 -0.14453,-0.00781 -0.21875,0c-0.34766,0.04688 -0.64062,0.27344 -0.78125,0.59375c0,0 -0.33984,0.74609 -0.5625,1.8125c-1.94922,-0.3125 -3.58984,-0.40625 -4.53125,-0.40625c-0.94141,0 -2.58203,0.09375 -4.53125,0.40625c-0.22266,-1.06641 -0.5625,-1.8125 -0.5625,-1.8125c-0.17187,-0.39062 -0.57422,-0.62891 -1,-0.59375zM18.28125,9.15625c0.07422,0.20313 0.125,0.39453 0.1875,0.625c-2.25391,0.52344 -4.72266,1.37891 -7.03125,2.8125c-0.36328,0.15234 -0.60156,0.50391 -0.61328,0.89844c-0.00781,0.39063 0.21484,0.75391 0.56641,0.92578c0.35547,0.16797 0.77734,0.11719 1.07813,-0.13672c4.63281,-2.87109 10.52734,-3.28125 12.53125,-3.28125c2.00391,0 7.89844,0.41016 12.53125,3.28125c0.30078,0.25391 0.72266,0.30469 1.07813,0.13672c0.35156,-0.17187 0.57422,-0.53516 0.56641,-0.92578c-0.01172,-0.39453 -0.25,-0.74609 -0.61328,-0.89844c-2.30859,-1.43359 -4.77734,-2.28906 -7.03125,-2.8125c0.0625,-0.23047 0.11328,-0.42187 0.1875,-0.625c1.14063,0.14063 5.57422,0.73828 8.59375,3.125c0.19531,0.17969 0.875,1.17969 1.5,2.5625c0.625,1.38281 1.28125,3.18359 1.90625,5.25c1.21875,4.03125 2.20313,9.00391 2.25,13.5625c-1.13672,1.83984 -3.26953,3.20703 -5.46875,4.0625c-2,0.77734 -3.86719,1.125 -4.84375,1.21875l-1.6875,-2.28125c0.85938,-0.27734 1.63281,-0.57812 2.3125,-0.875c2.52344,-1.10937 3.875,-2.28125 3.875,-2.28125c0.41406,-0.37109 0.44922,-1.00781 0.07813,-1.42187c-0.37109,-0.41406 -1.00781,-0.44922 -1.42187,-0.07812c0,0 -1.04687,0.95703 -3.34375,1.96875c-0.84375,0.37109 -1.86719,0.73828 -3.03125,1.0625c-0.26953,-0.03125 -0.53906,0.04688 -0.75,0.21875c-1.86328,0.45313 -4.07812,0.75 -6.6875,0.75c-2.62891,0 -4.84766,-0.32422 -6.71875,-0.78125c-0.21094,-0.14062 -0.46875,-0.19922 -0.71875,-0.15625c-1.16797,-0.32422 -2.18359,-0.72266 -3.03125,-1.09375c-2.29687,-1.01172 -3.34375,-1.96875 -3.34375,-1.96875c-0.22656,-0.21094 -0.53906,-0.30078 -0.84375,-0.25c-0.38672,0.05859 -0.70703,0.33594 -0.8125,0.71484c-0.10937,0.375 0.01563,0.78125 0.3125,1.03516c0,0 1.35156,1.17188 3.875,2.28125c0.67969,0.29688 1.45313,0.59766 2.3125,0.875l-1.6875,2.28125c-0.97656,-0.09375 -2.84375,-0.44141 -4.84375,-1.21875c-2.19922,-0.85547 -4.33203,-2.22266 -5.46875,-4.0625c0.04688,-4.55859 1.03125,-9.53125 2.25,-13.5625c0.625,-2.06641 1.28125,-3.86719 1.90625,-5.25c0.625,-1.38281 1.30469,-2.38281 1.5,-2.5625c3.01953,-2.38672 7.45313,-2.98437 8.59375,-3.125zM18.5,21c-2.55078,0 -4.5,2.31641 -4.5,5c0,2.68359 1.94922,5 4.5,5c2.55078,0 4.5,-2.31641 4.5,-5c0,-2.68359 -1.94922,-5 -4.5,-5zM31.5,21c-2.55078,0 -4.5,2.31641 -4.5,5c0,2.68359 1.94922,5 4.5,5c2.55078,0 4.5,-2.31641 4.5,-5c0,-2.68359 -1.94922,-5 -4.5,-5zM18.5,23c1.31641,0 2.5,1.26563 2.5,3c0,1.73438 -1.18359,3 -2.5,3c-1.31641,0 -2.5,-1.26562 -2.5,-3c0,-1.73437 1.18359,-3 2.5,-3zM31.5,23c1.31641,0 2.5,1.26563 2.5,3c0,1.73438 -1.18359,3 -2.5,3c-1.31641,0 -2.5,-1.26562 -2.5,-3c0,-1.73437 1.18359,-3 2.5,-3z"></path></g></g></svg>

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-messages">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<path d="M21 14l-3 -3h-7a1 1 0 0 1 -1 -1v-6a1 1 0 0 1 1 -1h9a1 1 0 0 1 1 1v10" />
<path d="M14 15v2a1 1 0 0 1 -1 1h-7l-3 3v-10a1 1 0 0 1 1 -1h2" />
</svg>

After

Width:  |  Height:  |  Size: 461 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0,0,256,256" width="24px" height="24px" fill-rule="nonzero"><g fill="#ffffff" fill-rule="nonzero" stroke="none" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="none" font-weight="none" font-size="none" text-anchor="none" style="mix-blend-mode: normal"><g transform="scale(10.66667,10.66667)"><path d="M10.9,2.1c-4.6,0.5 -8.3,4.2 -8.8,8.7c-0.5,4.7 2.2,8.9 6.3,10.5c0.3,0.1 0.6,-0.1 0.6,-0.5v-1.6c0,0 -0.4,0.1 -0.9,0.1c-1.4,0 -2,-1.2 -2.1,-1.9c-0.1,-0.4 -0.3,-0.7 -0.6,-1c-0.3,-0.1 -0.4,-0.1 -0.4,-0.2c0,-0.2 0.3,-0.2 0.4,-0.2c0.6,0 1.1,0.7 1.3,1c0.5,0.8 1.1,1 1.4,1c0.4,0 0.7,-0.1 0.9,-0.2c0.1,-0.7 0.4,-1.4 1,-1.8c-2.3,-0.5 -4,-1.8 -4,-4c0,-1.1 0.5,-2.2 1.2,-3c-0.1,-0.2 -0.2,-0.7 -0.2,-1.4c0,-0.4 0,-1 0.3,-1.6c0,0 1.4,0 2.8,1.3c0.5,-0.2 1.2,-0.3 1.9,-0.3c0.7,0 1.4,0.1 2,0.3c1.3,-1.3 2.8,-1.3 2.8,-1.3c0.2,0.6 0.2,1.2 0.2,1.6c0,0.8 -0.1,1.2 -0.2,1.4c0.7,0.8 1.2,1.8 1.2,3c0,2.2 -1.7,3.5 -4,4c0.6,0.5 1,1.4 1,2.3v2.6c0,0.3 0.3,0.6 0.7,0.5c3.7,-1.5 6.3,-5.1 6.3,-9.3c0,-6 -5.1,-10.7 -11.1,-10z"></path></g></g></svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-world-www"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M19.5 7a9 9 0 0 0 -7.5 -4a8.991 8.991 0 0 0 -7.484 4" /><path d="M11.5 3a16.989 16.989 0 0 0 -1.826 4" /><path d="M12.5 3a16.989 16.989 0 0 1 1.828 4" /><path d="M19.5 17a9 9 0 0 1 -7.5 4a8.991 8.991 0 0 1 -7.484 -4" /><path d="M11.5 21a16.989 16.989 0 0 1 -1.826 -4" /><path d="M12.5 21a16.989 16.989 0 0 0 1.828 -4" /><path d="M2 10l1 4l1.5 -4l1.5 4l1 -4" /><path d="M17 10l1 4l1.5 -4l1.5 4l1 -4" /><path d="M9.5 10l1 4l1.5 -4l1.5 4l1 -4" /></svg>

After

Width:  |  Height:  |  Size: 762 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-book"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0" /><path d="M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0" /><path d="M3 6l0 13" /><path d="M12 6l0 13" /><path d="M21 6l0 13" /></svg>

After

Width:  |  Height:  |  Size: 463 B

View File

@@ -41,9 +41,17 @@ public static class ServiceCollectionExtensions
foreach (var (viewModel, view, isSingleton) in GetTypesWithHelpAttribute(Assembly.GetExecutingAssembly()))
{
if (isSingleton) services.AddSingleton(viewModel);
else services.AddTransient(viewModel);
if (view != null) services.AddTransient(view);
if (isSingleton)
{
services.AddSingleton(viewModel);
if (view != null) services.AddSingleton(view);
}
else
{
services.AddTransient(viewModel);
if (view != null) services.AddTransient(view);
}
}
}

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;
}

View File

@@ -1,5 +1,5 @@
<UserControl
d:DesignHeight="300"
d:DesignHeight="500"
d:DesignWidth="800"
mc:Ignorable="d"
x:Class="Nebula.Launcher.Views.ServerEntryView"
@@ -9,8 +9,10 @@
xmlns:converters="clr-namespace:Nebula.Launcher.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="clr-namespace:Nebula.Shared.Models;assembly=Nebula.Shared"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
xmlns:views="clr-namespace:Nebula.Launcher.Views"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.DataContext>
<viewModels:ServerEntryModelView />
@@ -169,6 +171,39 @@
</Label>
</Border>
</StackPanel>
<ItemsControl ItemsSource="{Binding Links}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type models:ServerLink}">
<Border
Background="Transparent"
BoxShadow="0 0 13 -1 #121212"
CornerRadius="10">
<Button
Command="{Binding $parent[views:ServerEntryView].((viewModels:ServerEntryModelView)DataContext).OnLinkGo}"
CommandParameter="{Binding Url}"
Margin="3">
<StackPanel Orientation="Horizontal" Spacing="5">
<Svg Height="20" Path="{Binding Icon, Converter={x:Static converters:TypeConverters.IconConverter}}" />
<Label FontSize="10">
<TextBlock Text="{Binding Name}" />
</Label>
</StackPanel>
</Button>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
HorizontalAlignment="Left"
Margin="5"
Orientation="Horizontal"
Spacing="8"
VerticalAlignment="Center" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</Border>
<StackPanel

View File

@@ -7,21 +7,25 @@ namespace Nebula.Shared.Utils;
public static class Helper
{
public static readonly JsonSerializerOptions JsonWebOptions = new(JsonSerializerDefaults.Web);
public static void SafeOpenBrowser(string uri)
{
if (!Uri.TryCreate(uri, UriKind.Absolute, out var parsedUri))
{
Console.WriteLine("Unable to parse URI in server-provided link: {Link}", uri);
return;
}
if (parsedUri.Scheme is not ("http" or "https"))
{
Console.WriteLine("Refusing to open server-provided link {Link}, only http/https are allowed", parsedUri);
return;
}
OpenBrowser(parsedUri.ToString());
}
public static void OpenBrowser(string url)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}"));
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
public static async Task<T> AsJson<T>(this HttpContent content) where T : notnull