- tweak: loading popup thinks

* - tweak: change loading handle logic

* - tweak: beautify loading thinks

* - fix: speed thinks while downloading
This commit is contained in:
Cinkafox
2025-12-06 23:25:25 +03:00
committed by GitHub
parent d7f775e80c
commit 0c6bbaadac
39 changed files with 710 additions and 491 deletions

View File

@@ -70,3 +70,4 @@ popup-login-credentials-warning-cancel = Cancel
popup-login-credentials-warning-proceed = Proceed
goto-path-home = Root folder
tab-favorite = Favorite

View File

@@ -69,4 +69,5 @@ popup-login-credentials-warning-go-auth = Перейти на страницу
popup-login-credentials-warning-cancel = Отмена
popup-login-credentials-warning-proceed = Продолжить
goto-path-home = Корн. папка
goto-path-home = Корн. папка
tab-favorite = Избранное

View File

@@ -14,7 +14,7 @@ public class LocalizedLabel : Label
set
{
SetValue(LocalIdProperty, value);
Content = LocalisationService.GetString(value);
Content = LocalizationService.GetString(value);
}
}
}

View File

@@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Reactive;
using Avalonia.Threading;
namespace Nebula.Launcher.Controls;
public class SimpleGraph : Control
{
// Bindable data: list of doubles or points
public static readonly StyledProperty<ObservableCollection<double>> ValuesProperty =
AvaloniaProperty.Register<SimpleGraph,ObservableCollection<double>>(nameof(Values));
public static readonly StyledProperty<IBrush> GraphBrushProperty =
AvaloniaProperty.Register<SimpleGraph, IBrush>(nameof(GraphBrush), Brushes.CornflowerBlue);
public static readonly StyledProperty<IBrush> GridBrushProperty =
AvaloniaProperty.Register<SimpleGraph, IBrush>(nameof(GridBrush), Brushes.LightGray);
static SimpleGraph()
{
ValuesProperty.Changed.Subscribe(
new AnonymousObserver<AvaloniaPropertyChangedEventArgs<ObservableCollection<double>>>(args =>
{
if (args.Sender is not SimpleGraph g)
return;
g.InvalidateVisual();
g.Values.CollectionChanged += g.ValuesOnCollectionChanged;
}));
}
public SimpleGraph()
{
Values = new ObservableCollection<double>();
}
private void ValuesOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
Dispatcher.UIThread.Post(InvalidateVisual);
}
public ObservableCollection<double> Values
{
get => GetValue(ValuesProperty);
set => SetValue(ValuesProperty, value);
}
public IBrush GraphBrush
{
get => GetValue(GraphBrushProperty);
set => SetValue(GraphBrushProperty, value);
}
public IBrush GridBrush
{
get => GetValue(GridBrushProperty);
set => SetValue(GridBrushProperty, value);
}
public override void Render(DrawingContext context)
{
base.Render(context);
if (Bounds.Width <= 0 || Bounds.Height <= 0)
return;
// background grid
DrawGrid(context, Bounds);
if (Values.Count == 0)
return;
var min = Values.Min();
var max = Values.Max();
if (Math.Abs(min - max) < 0.001)
{
min -= 1;
max += 1;
}
var geo = new StreamGeometry();
using (var ctx = geo.Open())
{
if (Values.Count > 1)
{
Point p0 = Map(0, Values[0]);
ctx.BeginFigure(p0, false);
for (int i = 0; i < Values.Count - 1; i++)
{
var p1 = Map(i, Values[i]);
var p2 = Map(i + 1, Values[i + 1]);
// control points for smoothing
var c1 = new Point((p1.X + p2.X) / 2, p1.Y);
var c2 = new Point((p1.X + p2.X) / 2, p2.Y);
ctx.CubicBezierTo(c1, c2, p2);
}
ctx.EndFigure(false);
}
}
// stroke
context.DrawGeometry(null, new Pen(GraphBrush, 2), geo);
// draw points
for (var i = 0; i < Values.Count; i++)
{
var p = Map(i, Values[i]);
context.DrawEllipse(GraphBrush, null, p, 3, 3);
}
return;
// map data index/value -> point
Point Map(int i, double val)
{
var x = Bounds.X + Bounds.Width * (i / (double)Math.Max(1, Values.Count - 1));
var y = Bounds.Y + Bounds.Height - (val - min) / (max - min) * Bounds.Height;
return new Point(x, y);
}
}
private void DrawGrid(DrawingContext dc, Rect r)
{
var pen = new Pen(GridBrush, 0.5);
var rows = 4;
var cols = Math.Max(2, Values?.Count ?? 2);
for (var i = 0; i <= rows; i++)
{
var y = r.Y + i * (r.Height / rows);
dc.DrawLine(pen, new Point(r.X, y), new Point(r.Right, y));
}
for (var j = 0; j <= cols; j++)
{
var x = r.X + j * (r.Width / cols);
dc.DrawLine(pen, new Point(x, r.Y), new Point(x, r.Bottom));
}
}
}

View File

@@ -5,23 +5,39 @@ using Microsoft.Extensions.DependencyInjection;
using Nebula.Shared;
using Nebula.Shared.Models;
using Nebula.Shared.Services;
using Nebula.Shared.Utils;
using Robust.LoaderApi;
namespace Nebula.Launcher.ProcessHelper;
[ServiceRegister]
public sealed class GameRunnerPreparer(IServiceProvider provider, ContentService contentService, EngineService engineService)
{
public async Task<ProcessRunHandler<GameProcessStartInfoProvider>> GetGameProcessStartInfoProvider(RobustUrl address, ILoadingHandler loadingHandler, CancellationToken cancellationToken = default)
public async Task<ProcessRunHandler<GameProcessStartInfoProvider>> GetGameProcessStartInfoProvider(RobustUrl address, ILoadingHandlerFactory loadingHandlerFactory, CancellationToken cancellationToken = default)
{
var buildInfo = await contentService.GetBuildInfo(address, cancellationToken);
var engine = await engineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion);
var engine = await engineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion, loadingHandlerFactory, cancellationToken);
if (engine is null)
throw new Exception("Engine version not found: " + buildInfo.BuildInfo.Build.EngineVersion);
await contentService.EnsureItems(buildInfo.RobustManifestInfo, loadingHandler, cancellationToken);
await engineService.EnsureEngineModules("Robust.Client.WebView", buildInfo.BuildInfo.Build.EngineVersion);
var hashApi = await contentService.EnsureItems(buildInfo.RobustManifestInfo, loadingHandlerFactory, cancellationToken);
if (hashApi.TryOpen("manifest.yml", out var stream))
{
var modules = ContentManifestParser.ExtractModules(stream);
foreach (var moduleStr in modules)
{
var module = await engineService.EnsureEngineModules(moduleStr, loadingHandlerFactory, buildInfo.BuildInfo.Build.EngineVersion);
if(module is null)
throw new Exception("Module not found: " + moduleStr);
}
await stream.DisposeAsync();
}
var gameInfo =
provider.GetService<GameProcessStartInfoProvider>()!.WithBuildInfo(buildInfo.BuildInfo.Auth.PublicKey,

View File

@@ -6,6 +6,7 @@ using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Nebula.Launcher.ViewModels.Popup;
using Nebula.Shared;
@@ -25,7 +26,6 @@ public sealed partial class DecompilerService
[GenerateProperty] private ViewHelperService ViewHelperService {get;}
[GenerateProperty] private ContentService ContentService {get;}
[GenerateProperty] private FileService FileService {get;}
[GenerateProperty] private CancellationService CancellationService {get;}
[GenerateProperty] private EngineService EngineService {get;}
[GenerateProperty] private DebugService DebugService {get;}
@@ -44,16 +44,14 @@ public sealed partial class DecompilerService
Process.Start(startInfo);
}
public async void OpenServerDecompiler(RobustUrl url)
public async void OpenServerDecompiler(RobustUrl url, CancellationToken cancellationToken)
{
var myTempDir = FileService.EnsureTempDir(out var tmpDir);
ILoadingHandler loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
using var loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
var buildInfo =
await ContentService.GetBuildInfo(url, CancellationService.Token);
var engine = await EngineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion);
await ContentService.GetBuildInfo(url, cancellationToken);
var engine = await EngineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion, loadingHandler, cancellationToken);
if (engine is null)
throw new Exception("Engine version not found: " + buildInfo.BuildInfo.Build.EngineVersion);
@@ -64,8 +62,9 @@ public sealed partial class DecompilerService
await stream.DisposeAsync();
}
var hashApi = await ContentService.EnsureItems(buildInfo.RobustManifestInfo, loadingHandler, CancellationService.Token);
var hashApi = await ContentService.EnsureItems(buildInfo.RobustManifestInfo, loadingHandler, cancellationToken);
foreach (var (file, hash) in hashApi.Manifest)
{
if(!file.Contains(".dll") || !hashApi.TryOpen(hash, out var stream)) continue;
@@ -73,8 +72,6 @@ public sealed partial class DecompilerService
await stream.DisposeAsync();
}
((IDisposable)loadingHandler).Dispose();
_logger.Log("File extracted. " + tmpDir);
OpenDecompiler(string.Join(' ', myTempDir.AllFiles.Select(f=>Path.Join(tmpDir, f))) + " --newinstance");
@@ -94,7 +91,7 @@ public sealed partial class DecompilerService
private async Task Download(){
using var loading = ViewHelperService.GetViewModel<LoadingContextViewModel>();
loading.LoadingName = "Download ILSpy";
loading.SetJobsCount(1);
loading.CreateLoadingContext().SetJobsCount(1);
PopupMessageService.Popup(loading);
using var response = await _httpClient.GetAsync(ConfigurationService.GetConfigValue(LauncherConVar.ILSpyUrl));
using var zipArchive = new ZipArchive(await response.Content.ReadAsStreamAsync());

View File

@@ -11,7 +11,7 @@ using Nebula.Shared.Services;
namespace Nebula.Launcher.Services;
[ConstructGenerator, ServiceRegister]
public partial class LocalisationService
public partial class LocalizationService
{
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
[GenerateProperty] private DebugService DebugService { get; }
@@ -74,6 +74,6 @@ public class LocaledText : MarkupExtension
public override object ProvideValue(IServiceProvider serviceProvider)
{
return LocalisationService.GetString(Key, Options);
return LocalizationService.GetString(Key, Options);
}
}

View File

@@ -41,9 +41,9 @@ public partial class MainViewModel : ViewModelBase
[ObservableProperty] private bool _isPopupClosable = true;
[ObservableProperty] private bool _popup;
[ObservableProperty] private ListItemTemplate? _selectedListItem;
[ObservableProperty] private string? _loginText = LocalisationService.GetString("auth-current-login-no-name");
[ObservableProperty] private string? _loginText = LocalizationService.GetString("auth-current-login-no-name");
[GenerateProperty] private LocalisationService LocalisationService { get; } // Не убирать! Без этой хуйни вся локализация идет в пизду!
[GenerateProperty] private LocalizationService LocalizationService { get; } // Не убирать! Без этой хуйни вся локализация идет в пизду!
[GenerateProperty] private AccountInfoViewModel AccountInfoViewModel { get; }
[GenerateProperty] private DebugService DebugService { get; } = default!;
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
@@ -59,7 +59,7 @@ public partial class MainViewModel : ViewModelBase
{
Items = new ObservableCollection<ListItemTemplate>(_templates.Select(a=>
{
return a with { Label = LocalisationService.GetString(a.Label) };
return a with { Label = LocalizationService.GetString(a.Label) };
}
));
RequirePage<AccountInfoViewModel>();
@@ -92,13 +92,13 @@ public partial class MainViewModel : ViewModelBase
CheckMigration();
var loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
loadingHandler.LoadingName = LocalisationService.GetString("migration-config-task");
loadingHandler.LoadingName = LocalizationService.GetString("migration-config-task");
loadingHandler.IsCancellable = false;
ConfigurationService.MigrateConfigs(loadingHandler);
if (!VCRuntimeDllChecker.AreVCRuntimeDllsPresent())
{
OnPopupRequired(LocalisationService.GetString("vcruntime-check-error"));
OnPopupRequired(LocalizationService.GetString("vcruntime-check-error"));
Helper.OpenBrowser("https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170");
}
}
@@ -108,7 +108,7 @@ public partial class MainViewModel : ViewModelBase
if(AccountInfoViewModel.Credentials.HasValue)
{
LoginText =
LocalisationService.GetString("auth-current-login-name",
LocalizationService.GetString("auth-current-login-name",
new Dictionary<string, object>
{
{ "login", AccountInfoViewModel.Credentials.Value?.Login ?? "" },
@@ -120,7 +120,7 @@ public partial class MainViewModel : ViewModelBase
}
else
{
LoginText = LocalisationService.GetString("auth-current-login-no-name");
LoginText = LocalizationService.GetString("auth-current-login-no-name");
}
}
@@ -130,7 +130,7 @@ public partial class MainViewModel : ViewModelBase
return;
var loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
loadingHandler.LoadingName = LocalisationService.GetString("migration-label-task");
loadingHandler.LoadingName = LocalizationService.GetString("migration-label-task");
loadingHandler.IsCancellable = false;
if (!ContentService.CheckMigration(loadingHandler))

View File

@@ -32,6 +32,7 @@ public partial class AccountInfoViewModel : ViewModelBase
[ObservableProperty] private bool _isLogged;
[ObservableProperty] private bool _doRetryAuth;
[ObservableProperty] private AuthServerCredentials _authItemSelect;
[ObservableProperty] private string _authServerName;
private bool _isProfilesEmpty;
[GenerateProperty] private PopupMessageService PopupMessageService { get; }
@@ -68,7 +69,7 @@ public partial class AccountInfoViewModel : ViewModelBase
public void DoAuth(string? code = null)
{
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
message.InfoText = LocalisationService.GetString("auth-processing");
message.InfoText = LocalizationService.GetString("auth-processing");
message.IsInfoClosable = false;
PopupMessageService.Popup(message);
@@ -95,7 +96,7 @@ public partial class AccountInfoViewModel : ViewModelBase
}
catch (Exception ex)
{
exception = new Exception(LocalisationService.GetString("auth-error"), ex);
exception = new Exception(LocalizationService.GetString("auth-error"), ex);
}
}
@@ -128,19 +129,19 @@ public partial class AccountInfoViewModel : ViewModelBase
_logger.Log("TFA required");
break;
case AuthenticateDenyCode.InvalidCredentials:
PopupError(LocalisationService.GetString("auth-invalid-credentials"), e);
PopupError(LocalizationService.GetString("auth-invalid-credentials"), e);
break;
case AuthenticateDenyCode.AccountLocked:
PopupError(LocalisationService.GetString("auth-account-locked"), e);
PopupError(LocalizationService.GetString("auth-account-locked"), e);
break;
case AuthenticateDenyCode.AccountUnconfirmed:
PopupError(LocalisationService.GetString("auth-account-unconfirmed"), e);
PopupError(LocalizationService.GetString("auth-account-unconfirmed"), e);
break;
case AuthenticateDenyCode.None:
PopupError(LocalisationService.GetString("auth-none"),e);
PopupError(LocalizationService.GetString("auth-none"),e);
break;
default:
PopupError(LocalisationService.GetString("auth-error-fuck"), e);
PopupError(LocalizationService.GetString("auth-error-fuck"), e);
break;
}
}
@@ -150,46 +151,46 @@ public partial class AccountInfoViewModel : ViewModelBase
switch (e.HttpRequestError)
{
case HttpRequestError.ConnectionError:
PopupError(LocalisationService.GetString("auth-connection-error"), e);
PopupError(LocalizationService.GetString("auth-connection-error"), e);
DoRetryAuth = true;
break;
case HttpRequestError.NameResolutionError:
PopupError(LocalisationService.GetString("auth-name-resolution-error"), e);
PopupError(LocalizationService.GetString("auth-name-resolution-error"), e);
DoRetryAuth = true;
break;
case HttpRequestError.SecureConnectionError:
PopupError(LocalisationService.GetString("auth-secure-error"), e);
PopupError(LocalizationService.GetString("auth-secure-error"), e);
DoRetryAuth = true;
break;
case HttpRequestError.UserAuthenticationError:
PopupError(LocalisationService.GetString("auth-user-authentication-error"), e);
PopupError(LocalizationService.GetString("auth-user-authentication-error"), e);
break;
case HttpRequestError.Unknown:
PopupError(LocalisationService.GetString("auth-unknown"), e);
PopupError(LocalizationService.GetString("auth-unknown"), e);
break;
case HttpRequestError.HttpProtocolError:
PopupError(LocalisationService.GetString("auth-http-protocol-error"), e);
PopupError(LocalizationService.GetString("auth-http-protocol-error"), e);
break;
case HttpRequestError.ExtendedConnectNotSupported:
PopupError(LocalisationService.GetString("auth-extended-connect-not-support"), e);
PopupError(LocalizationService.GetString("auth-extended-connect-not-support"), e);
break;
case HttpRequestError.VersionNegotiationError:
PopupError(LocalisationService.GetString("auth-version-negotiation-error"), e);
PopupError(LocalizationService.GetString("auth-version-negotiation-error"), e);
break;
case HttpRequestError.ProxyTunnelError:
PopupError(LocalisationService.GetString("auth-proxy-tunnel-error"), e);
PopupError(LocalizationService.GetString("auth-proxy-tunnel-error"), e);
break;
case HttpRequestError.InvalidResponse:
PopupError(LocalisationService.GetString("auth-invalid-response"), e);
PopupError(LocalizationService.GetString("auth-invalid-response"), e);
break;
case HttpRequestError.ResponseEnded:
PopupError(LocalisationService.GetString("auth-response-ended"), e);
PopupError(LocalizationService.GetString("auth-response-ended"), e);
break;
case HttpRequestError.ConfigurationLimitExceeded:
PopupError(LocalisationService.GetString("auth-configuration-limit-exceeded"), e);
PopupError(LocalizationService.GetString("auth-configuration-limit-exceeded"), e);
break;
default:
var authError = new Exception(LocalisationService.GetString("auth-error"), e);
var authError = new Exception(LocalizationService.GetString("auth-error"), e);
_logger.Error(authError);
PopupMessageService.Popup(authError);
break;
@@ -245,7 +246,7 @@ public partial class AccountInfoViewModel : ViewModelBase
private async Task ReadAuthConfig()
{
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
message.InfoText = LocalisationService.GetString("auth-config-read");
message.InfoText = LocalizationService.GetString("auth-config-read");
message.IsInfoClosable = false;
PopupMessageService.Popup(message);
@@ -318,7 +319,7 @@ public partial class AccountInfoViewModel : ViewModelBase
}
catch (Exception e)
{
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), e);
var unexpectedError = new Exception(LocalizationService.GetString("auth-error"), e);
_logger.Error(unexpectedError);
return authTokenCredentials;
}
@@ -345,7 +346,7 @@ public partial class AccountInfoViewModel : ViewModelBase
private void PopupError(string message, Exception e)
{
message = LocalisationService.GetString("auth-error-occured") + message;
message = LocalizationService.GetString("auth-error-occured") + message;
_logger.Error(new Exception(message, e));
var messageView = ViewHelperService.GetViewModel<InfoPopupViewModel>();
@@ -385,7 +386,7 @@ public partial class AccountInfoViewModel : ViewModelBase
}
var message = accountInfoViewModel.ViewHelperService.GetViewModel<InfoPopupViewModel>();
message.InfoText = LocalisationService.GetString("auth-try-auth-config");
message.InfoText = LocalizationService.GetString("auth-try-auth-config");
message.IsInfoClosable = false;
accountInfoViewModel.PopupMessageService.Popup(message);
@@ -423,7 +424,7 @@ public partial class AccountInfoViewModel : ViewModelBase
{
accountInfoViewModel.CurrentLogin = currProfile.Login;
accountInfoViewModel.CurrentAuthServer = currProfile.AuthServer;
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
var unexpectedError = new Exception(LocalizationService.GetString("auth-error"), ex);
accountInfoViewModel._logger.Error(unexpectedError);
accountInfoViewModel.PopupMessageService.Popup(unexpectedError);
errorRun = true;
@@ -436,6 +437,8 @@ public partial class AccountInfoViewModel : ViewModelBase
}
accountInfoViewModel.IsLogged = true;
accountInfoViewModel.AuthServerName = accountInfoViewModel.GetServerAuthName(currProfile.AuthServer);
return currProfile;
}

View File

@@ -89,7 +89,7 @@ public partial class ConfigurationViewModel : ViewModelBase
using var loader = ViewHelperService.GetViewModel<LoadingContextViewModel>();
loader.LoadingName = "Removing content";
PopupService.Popup(loader);
ContentService.RemoveAllContent(loader, CancellationService.Token);
ContentService.RemoveAllContent(loader.CreateLoadingContext(), CancellationService.Token);
});
}

View File

@@ -33,6 +33,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase, IContentHol
[GenerateProperty] private FileService FileService { get; } = default!;
[GenerateProperty] private PopupMessageService PopupService { get; } = default!;
[GenerateProperty] private IServiceProvider ServiceProvider { get; }
[GenerateProperty] private CancellationService CancellationService { get; set; } = default!;
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; } = default!;
@@ -57,7 +58,11 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase, IContentHol
loading.LoadingName = "Unpacking entry";
PopupService.Popup(loading);
Task.Run(() => ContentService.Unpack(serverEntry.FileApi, myTempDir, loading));
Task.Run(() =>
{
ContentService.Unpack(serverEntry.FileApi, myTempDir, loading.CreateLoadingContext());
loading.Dispose();
});
ExplorerHelper.OpenFolder(tmpDir);
}
@@ -74,7 +79,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase, IContentHol
{
var cur = ServiceProvider.GetService<ServerFolderContentEntry>()!;
cur.Init(this, ServerText.ToRobustUrl());
var curContent = cur.Go(new ContentPath(SearchText));
var curContent = cur.Go(new ContentPath(SearchText), CancellationService.Token);
if(curContent == null)
throw new NullReferenceException($"{SearchText} not found in {ServerText}");
@@ -144,11 +149,11 @@ public interface IContentEntry
public string IconPath { get; }
public ContentPath FullPath => Parent?.FullPath.With(Name) ?? new ContentPath(Name);
public IContentEntry? Go(ContentPath path);
public IContentEntry? Go(ContentPath path, CancellationToken cancellationToken);
public void GoCurrent()
{
var entry = Go(ContentPath.Empty);
var entry = Go(ContentPath.Empty, CancellationToken.None);
if(entry is not null) Holder.CurrentEntry = entry;
}
@@ -178,7 +183,7 @@ public sealed class LazyContentEntry : IContentEntry
_lazyEntry = entry;
_lazyEntryInit = lazyEntryInit;
}
public IContentEntry? Go(ContentPath path)
public IContentEntry? Go(ContentPath path, CancellationToken cancellationToken)
{
_lazyEntryInit?.Invoke();
return _lazyEntry;
@@ -196,13 +201,13 @@ public sealed class ExtContentExecutor
_decompilerService = decompilerService;
}
public bool TryExecute(RobustManifestItem manifestItem)
public bool TryExecute(RobustManifestItem manifestItem, CancellationToken cancellationToken)
{
var ext = Path.GetExtension(manifestItem.Path);
if (ext == ".dll")
{
_decompilerService.OpenServerDecompiler(_root.ServerUrl);
_decompilerService.OpenServerDecompiler(_root.ServerUrl, cancellationToken);
return true;
}
@@ -231,9 +236,9 @@ public sealed partial class ManifestContentEntry : IContentEntry
_extContentExecutor = executor;
}
public IContentEntry? Go(ContentPath path)
public IContentEntry? Go(ContentPath path, CancellationToken cancellationToken)
{
if (_extContentExecutor.TryExecute(_manifestItem))
if (_extContentExecutor.TryExecute(_manifestItem, cancellationToken))
return null;
var ext = Path.GetExtension(_manifestItem.Path);
@@ -319,7 +324,7 @@ public sealed partial class ServerFolderContentEntry : BaseFolderContentEntry
{
CreateContent(new ContentPath(path), item);
}
IsLoading = false;
loading.Dispose();
});
@@ -433,11 +438,11 @@ public abstract class BaseFolderContentEntry : ViewModelBase, IContentEntry
public IContentEntry? Parent { get; set; }
public string? Name { get; private set; }
public IContentEntry? Go(ContentPath path)
public IContentEntry? Go(ContentPath path, CancellationToken cancellationToken)
{
if (path.IsEmpty()) return this;
if (_childs.TryGetValue(path.GetNext(), out var child))
return child.Go(path);
return child.Go(path, cancellationToken);
return null;
}

View File

@@ -66,7 +66,7 @@ public partial class ServerOverviewModel : ViewModelBase
tempItems.Add(new ServerListTabTemplate(ServiceProvider.GetService<HubServerListProvider>()!.With(record.MainUrl), record.Name));
}
tempItems.Add(new ServerListTabTemplate(FavoriteServerListProvider, "Favorite"));
tempItems.Add(new ServerListTabTemplate(FavoriteServerListProvider, LocalizationService.GetString("tab-favorite")));
Items = new ObservableCollection<ServerListTabTemplate>(tempItems);

View File

@@ -32,7 +32,7 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
[GenerateProperty] private ServerOverviewModel ServerOverviewModel { get; }
[GenerateProperty] private DebugService DebugService { get; }
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
public override string Title => LocalisationService.GetString("popup-add-favorite");
public override string Title => LocalizationService.GetString("popup-add-favorite");
public override bool IsClosable => true;
[ObservableProperty] private string _ipInput;
@@ -43,7 +43,7 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
try
{
if(string.IsNullOrWhiteSpace(IpInput))
throw new Exception(LocalisationService.GetString("popup-add-favorite-invalid-ip"));
throw new Exception(LocalizationService.GetString("popup-add-favorite-invalid-ip"));
var uri = IpInput.ToRobustUrl();
FavoriteServerListProvider.AddFavorite(uri);

View File

@@ -12,7 +12,7 @@ public sealed partial class EditServerNameViewModel : PopupViewModelBase
{
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
[GenerateProperty] public ConfigurationService ConfigurationService { get; }
public override string Title => LocalisationService.GetString("popup-edit-name");
public override string Title => LocalizationService.GetString("popup-edit-name");
public override bool IsClosable => true;
[ObservableProperty] private string _ipInput;

View File

@@ -12,7 +12,7 @@ namespace Nebula.Launcher.ViewModels.Popup;
public sealed partial class ExceptionListViewModel : PopupViewModelBase
{
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
public override string Title => LocalisationService.GetString("popup-exception");
public override string Title => LocalizationService.GetString("popup-exception");
public override bool IsClosable => true;
public ObservableCollection<Exception> Errors { get; } = new();

View File

@@ -14,7 +14,7 @@ public partial class InfoPopupViewModel : PopupViewModelBase
[ObservableProperty] private string _infoText = "Test";
public override string Title => LocalisationService.GetString("popup-information");
public override string Title => LocalizationService.GetString("popup-information");
public bool IsInfoClosable { get; set; } = true;
public override bool IsClosable => IsInfoClosable;

View File

@@ -45,6 +45,6 @@ public partial class IsLoginCredentialsNullPopupViewModel : PopupViewModelBase
Dispose();
}
public override string Title => LocalisationService.GetString("popup-login-credentials-warning");
public override string Title => LocalizationService.GetString("popup-login-credentials-warning");
public override bool IsClosable => true;
}

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using Nebula.Launcher.Services;
using Nebula.Launcher.Views.Popup;
@@ -9,82 +11,121 @@ namespace Nebula.Launcher.ViewModels.Popup;
[ViewModelRegister(typeof(LoadingContextView), false)]
[ConstructGenerator]
public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadingHandler
public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadingHandlerFactory, IConnectionSpeedHandler
{
public ObservableCollection<LoadingContext> LoadingContexts { get; } = [];
public ObservableCollection<double> Values { get; } = [];
[ObservableProperty] private string _speedText = "";
[ObservableProperty] private bool _showSpeed;
[ObservableProperty] private int _loadingColumnSize = 2;
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
[GenerateProperty] public CancellationService CancellationService { get; }
[ObservableProperty] private int _currJobs;
[ObservableProperty] private int _resolvedJobs;
[ObservableProperty] private string _message = string.Empty;
public string LoadingName { get; set; } = LocalisationService.GetString("popup-loading");
public string LoadingName { get; set; } = LocalizationService.GetString("popup-loading");
public bool IsCancellable { get; set; } = true;
public override bool IsClosable => false;
public override string Title => LoadingName;
public override string Title => LocalizationService.GetString("popup-loading");
public void SetJobsCount(int count)
public void Cancel()
{
CurrJobs = count;
}
public int GetJobsCount()
{
return CurrJobs;
}
public void SetResolvedJobsCount(int count)
{
ResolvedJobs = count;
}
public int GetResolvedJobsCount()
{
return ResolvedJobs;
}
public void SetLoadingMessage(string message)
{
Message = message + "\n" + Message;
}
public void Cancel(){
if(!IsCancellable) return;
if (!IsCancellable) return;
CancellationService.Cancel();
Dispose();
}
public void PasteSpeed(int speed)
{
if (Values.Count == 0)
{
ShowSpeed = true;
LoadingColumnSize = 1;
}
SpeedText = FileLoadingFormater.FormatBytes(speed) + " / s";
Values.Add(speed);
if(Values.Count > 10) Values.RemoveAt(0);
}
public ILoadingHandler CreateLoadingContext(ILoadingFormater? loadingFormater = null)
{
var instance = new LoadingContext(this, loadingFormater ?? DefaultLoadingFormater.Instance);
LoadingContexts.Add(instance);
return instance;
}
public void RemoveContextInstance(LoadingContext loadingContext)
{
LoadingContexts.Remove(loadingContext);
}
protected override void Initialise()
{
}
protected override void InitialiseInDesignMode()
{
SetJobsCount(5);
SetResolvedJobsCount(2);
string[] debugMessages = {
"Debug: Starting phase 1...",
"Debug: Loading assets...",
"Debug: Connecting to server...",
"Debug: Fetching user data...",
"Debug: Applying configurations...",
"Debug: Starting phase 2...",
"Debug: Rendering UI...",
"Debug: Preparing scene...",
"Debug: Initializing components...",
"Debug: Running diagnostics...",
"Debug: Checking dependencies...",
"Debug: Verifying files...",
"Debug: Cleaning up cache...",
"Debug: Finalizing setup...",
"Debug: Setup complete.",
"Debug: Ready for launch."
};
var context = CreateLoadingContext();
context.SetJobsCount(5);
context.SetResolvedJobsCount(2);
context.SetLoadingMessage("message");
foreach (string message in debugMessages)
var ctx1 = CreateLoadingContext(new FileLoadingFormater());
ctx1.SetJobsCount(1020120);
ctx1.SetResolvedJobsCount(12331);
ctx1.SetLoadingMessage("File data");
for (var i = 0; i < 14; i++)
{
SetLoadingMessage(message);
PasteSpeed(Random.Shared.Next(10000000));
}
}
}
}
public sealed partial class LoadingContext : ObservableObject, ILoadingHandler
{
private readonly LoadingContextViewModel _master;
private readonly ILoadingFormater _loadingFormater;
public string LoadingText => _loadingFormater.Format(this);
[ObservableProperty] private string _message = string.Empty;
[ObservableProperty] private long _currJobs;
[ObservableProperty] private long _resolvedJobs;
public LoadingContext(LoadingContextViewModel master, ILoadingFormater loadingFormater)
{
_master = master;
_loadingFormater = loadingFormater;
}
public void SetJobsCount(long count)
{
CurrJobs = count;
OnPropertyChanged(nameof(LoadingText));
}
public long GetJobsCount()
{
return CurrJobs;
}
public void SetResolvedJobsCount(long count)
{
ResolvedJobs = count;
OnPropertyChanged(nameof(LoadingText));
}
public long GetResolvedJobsCount()
{
return ResolvedJobs;
}
public void SetLoadingMessage(string message)
{
Message = message;
}
public void Dispose()
{
_master.RemoveContextInstance(this);
}
}

View File

@@ -12,7 +12,7 @@ public partial class TfaViewModel : PopupViewModelBase
{
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
[GenerateProperty] public AccountInfoViewModel AccountInfo { get; }
public override string Title => LocalisationService.GetString("popup-twofa");
public override string Title => LocalizationService.GetString("popup-twofa");
public override bool IsClosable => true;
protected override void InitialiseInDesignMode()

View File

@@ -186,13 +186,12 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis
try
{
using var loadingContext = ViewHelperService.GetViewModel<LoadingContextViewModel>();
loadingContext.LoadingName = "Loading instance...";
((ILoadingHandler)loadingContext).AppendJob();
using var viewModelLoading = ViewHelperService.GetViewModel<LoadingContextViewModel>();
viewModelLoading.LoadingName = "Loading instance...";
PopupMessageService.Popup(loadingContext);
PopupMessageService.Popup(viewModelLoading);
_currentInstance =
await GameRunnerPreparer.GetGameProcessStartInfoProvider(Address, loadingContext, CancellationService.Token);
await GameRunnerPreparer.GetGameProcessStartInfoProvider(Address, viewModelLoading, CancellationService.Token);
_logger.Log("Preparing instance...");
_currentInstance.RegisterLogger(_currentContentLogConsumer);
_currentInstance.RegisterLogger(new DebugLoggerBridge(DebugService.GetLogger($"PROCESS_{Random.Shared.Next(65535)}")));

View File

@@ -3,9 +3,9 @@
ExtendClientAreaChromeHints="NoChrome"
ExtendClientAreaTitleBarHeightHint="-1"
ExtendClientAreaToDecorationsHint="True"
Height="500"
Height="550"
Icon="/Assets/nebula.ico"
MinHeight="500"
MinHeight="550"
MinWidth="800"
SystemDecorations="BorderOnly"
Title="Nebula.Launcher"

View File

@@ -188,14 +188,14 @@
Margin="0,0,0,20"
Path="/Assets/svg/user.svg" />
<Label>
<StackPanel>
<StackPanel Spacing="15">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="5">
<customControls:LocalizedLabel LocalId="account-auth-hello"/>
<TextBlock Text="{Binding Credentials.Value.Login}" />
</StackPanel>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="5">
<customControls:LocalizedLabel LocalId="account-auth-current-server"/>
<TextBlock Text="{Binding Credentials.Value.AuthServer}" />
<TextBlock Text="{Binding AuthServerName}" />
</StackPanel>
</StackPanel>
</Label>

View File

@@ -10,33 +10,71 @@
<Design.DataContext>
<popup:LoadingContextViewModel />
</Design.DataContext>
<StackPanel Margin="25" Spacing="15">
<ProgressBar Height="40" Maximum="{Binding CurrJobs}" Value="{Binding ResolvedJobs}" />
<Panel>
<StackPanel Orientation="Horizontal" Spacing="5" HorizontalAlignment="Left" VerticalAlignment="Center">
<Label>
<TextBlock Text="{Binding ResolvedJobs}" />
<StackPanel Margin="25" Spacing="15" >
<Panel Margin="5">
<Border Padding="15" Background="{StaticResource DefaultGrad}" BoxShadow="0 1 1 0 #121212">
<Label VerticalAlignment="Center">
<TextBlock Text="{Binding LoadingName}"/>
</Label>
<Label>
/
</Label>
<Label>
<TextBlock Text="{Binding CurrJobs}" />
</Label>
</StackPanel>
</Border>
<Button
HorizontalAlignment="Right"
VerticalAlignment="Center"
Command="{Binding Cancel}"
IsVisible="{Binding IsCancellable}">
<customControls:LocalizedLabel LocalId="task-cancel"/>
<Border Padding="15" Background="{StaticResource DefaultGrad}" BoxShadow="0 1 1 0 #121212">
<customControls:LocalizedLabel LocalId="task-cancel"/>
</Border>
</Button>
</Panel>
<Panel>
<Border Background="{StaticResource DefaultForeground}" MinHeight="210">
<TextBlock TextWrapping="Wrap" Text="{Binding Message}" MaxLines="10" Margin="15"/>
</Border>
</Panel>
<Grid ColumnDefinitions="*,*">
<ScrollViewer Grid.Column="0" Grid.ColumnSpan="{Binding LoadingColumnSize}">
<ItemsControl
Background="#00000000"
ItemsSource="{Binding LoadingContexts}"
Padding="0" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" Spacing="5" Margin="5" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type popup:LoadingContext}">
<Border Background="{StaticResource DefaultGrad}" BoxShadow="0 1 1 0 #121212">
<StackPanel Margin="15">
<ProgressBar Height="40" Maximum="{Binding CurrJobs}" Value="{Binding ResolvedJobs}" />
<Panel Margin="5 15 5 5">
<Label HorizontalAlignment="Left" VerticalAlignment="Center">
<TextBlock Text="{Binding LoadingText}" />
</Label>
<Label HorizontalAlignment="Right" VerticalAlignment="Center">
<TextBlock Text="{Binding Message}" />
</Label>
</Panel>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<StackPanel
Grid.Column="1"
Margin="10" Spacing="15"
IsVisible="{Binding ShowSpeed}">
<customControls:SimpleGraph Values="{Binding Values}"
Height="167"
GridBrush="{StaticResource DefaultForeground}"/>
<Border Background="{StaticResource DefaultGrad}" BoxShadow="0 1 1 0 #121212">
<Panel Margin="10">
<Label>Speed</Label>
<Label HorizontalAlignment="Right">
<TextBlock Text="{Binding SpeedText}" />
</Label>
</Panel>
</Border>
</StackPanel>
</Grid>
</StackPanel>
</UserControl>