-Komplette view überarbeitet für Thunderstore mit mods suche, vorschau, markdown (readme) etc
todo: wenn neuer mod aufgerufen wird, soll die zurückfunktion deaktviert sein oder so das sie den mod mit aktualisiert zu dem der davor ausgewählt war (:
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.14.36414.22 d17.14
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Valheim Dashboard", "Valheim Dashboard\Valheim Dashboard.csproj", "{BDB3822A-2776-4E4A-8A1A-14BD902A66EE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Valheim Dashboard", "Valheim Dashboard\Valheim Dashboard.csproj", "{BDB3822A-2776-4E4A-8A1A-14BD902A66EE}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
@@ -13,4 +16,10 @@ Global
|
|||||||
{BDB3822A-2776-4E4A-8A1A-14BD902A66EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{BDB3822A-2776-4E4A-8A1A-14BD902A66EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{BDB3822A-2776-4E4A-8A1A-14BD902A66EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{BDB3822A-2776-4E4A-8A1A-14BD902A66EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {8E968CE6-3BDD-437F-A468-16BC057001E5}
|
||||||
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
<Application.Styles>
|
<Application.Styles>
|
||||||
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
|
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
|
||||||
<FluentTheme/>
|
<FluentTheme/>
|
||||||
|
|
||||||
<StyleInclude Source="Styles.axaml"/>
|
<StyleInclude Source="Styles.axaml"/>
|
||||||
<Style>
|
<Style>
|
||||||
<Style.Resources>
|
<Style.Resources>
|
||||||
|
|||||||
BIN
Valheim Dashboard/Assets/vd.png
Normal file
BIN
Valheim Dashboard/Assets/vd.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
26
Valheim Dashboard/Converters/BoolToColSpanConverter.cs
Normal file
26
Valheim Dashboard/Converters/BoolToColSpanConverter.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using Avalonia.Data.Converters;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Avalonia.Media.Imaging;
|
||||||
|
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Valheim_Dashboard.Converters
|
||||||
|
{
|
||||||
|
public sealed class BoolToColSpanConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
|
||||||
|
=> value is true ? 1 : 2;
|
||||||
|
|
||||||
|
public object ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
|
||||||
|
=> throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
56
Valheim Dashboard/Converters/ImageUrlToBitmapConverter.cs
Normal file
56
Valheim Dashboard/Converters/ImageUrlToBitmapConverter.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using Avalonia.Data.Converters;
|
||||||
|
using Avalonia.Media.Imaging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Valheim_Dashboard.Converters
|
||||||
|
{
|
||||||
|
public class ImageUrlToBitmapConverter : IValueConverter
|
||||||
|
{
|
||||||
|
private static readonly HttpClient _http = new HttpClient();
|
||||||
|
private static readonly ConcurrentDictionary<string, Bitmap?> _cache = new();
|
||||||
|
|
||||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is not string url || string.IsNullOrWhiteSpace(url))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Schon im Cache?
|
||||||
|
if (_cache.TryGetValue(url, out var cached))
|
||||||
|
return cached;
|
||||||
|
|
||||||
|
// async im Hintergrund laden
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var data = await _http.GetByteArrayAsync(url);
|
||||||
|
using var ms = new MemoryStream(data);
|
||||||
|
var bmp = new Bitmap(ms);
|
||||||
|
|
||||||
|
_cache[url] = bmp;
|
||||||
|
|
||||||
|
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
|
// Binding refreshen (z.B. PropertyChanged für Mods triggern)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
_cache[url] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// solange Platzhalter
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
10
Valheim Dashboard/Models/ListFooterItem.cs
Normal file
10
Valheim Dashboard/Models/ListFooterItem.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Valheim_Dashboard.Models
|
||||||
|
{
|
||||||
|
public sealed class ListFooterItem { }
|
||||||
|
}
|
||||||
37
Valheim Dashboard/Models/StoreModInfo.cs
Normal file
37
Valheim Dashboard/Models/StoreModInfo.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using Avalonia.Media.Imaging;
|
||||||
|
using ReactiveUI;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace Valheim_Dashboard.Models
|
||||||
|
{
|
||||||
|
public class StoreModInfo : ReactiveObject
|
||||||
|
{
|
||||||
|
public string Namespace { get; set; } = "";
|
||||||
|
public string PackageName { get; set; } = "";
|
||||||
|
|
||||||
|
public string Name { get; set; } = "";
|
||||||
|
public string? Description { get; set; }
|
||||||
|
public string Url { get; set; } = "";
|
||||||
|
public bool IsTemporary { get; set; }
|
||||||
|
|
||||||
|
private Avalonia.Media.Imaging.Bitmap? _icon;
|
||||||
|
public Avalonia.Media.Imaging.Bitmap? Icon
|
||||||
|
{
|
||||||
|
get => _icon;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _icon, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LoadIconAsync(string imageUrl)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var http = new HttpClient();
|
||||||
|
var data = await http.GetByteArrayAsync(imageUrl);
|
||||||
|
using var ms = new MemoryStream(data);
|
||||||
|
Icon = new Avalonia.Media.Imaging.Bitmap(ms);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
using Avalonia.ReactiveUI;
|
using Avalonia.ReactiveUI;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Avalonia.WebView;
|
||||||
|
using Avalonia.WebView.Desktop;
|
||||||
|
|
||||||
namespace Valheim_Dashboard;
|
namespace Valheim_Dashboard;
|
||||||
|
|
||||||
@@ -32,5 +34,6 @@ sealed class Program
|
|||||||
.UsePlatformDetect()
|
.UsePlatformDetect()
|
||||||
.WithInterFont()
|
.WithInterFont()
|
||||||
.LogToTrace()
|
.LogToTrace()
|
||||||
.UseReactiveUI();
|
.UseReactiveUI()
|
||||||
|
.UseWindowWebView();
|
||||||
}
|
}
|
||||||
@@ -13,19 +13,25 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.3.4" />
|
<PackageReference Include="Avalonia" Version="11.3.5" />
|
||||||
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.3.0" />
|
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.3.0" />
|
||||||
<PackageReference Include="Avalonia.Desktop" Version="11.3.4" />
|
<PackageReference Include="Avalonia.Desktop" Version="11.3.5" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.4" />
|
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.5" />
|
||||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.4" />
|
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.5" />
|
||||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||||
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.4">
|
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.5">
|
||||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.4" />
|
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.5" />
|
||||||
|
<PackageReference Include="ColorTextBlock.Avalonia" Version="11.0.2" />
|
||||||
<PackageReference Include="LoadingIndicators.Avalonia" Version="11.0.11.1" />
|
<PackageReference Include="LoadingIndicators.Avalonia" Version="11.0.11.1" />
|
||||||
<PackageReference Include="Lucide.Avalonia" Version="0.1.41" />
|
<PackageReference Include="Lucide.Avalonia" Version="0.1.42" />
|
||||||
|
<PackageReference Include="Markdig" Version="0.41.3" />
|
||||||
|
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
|
||||||
|
<PackageReference Include="WebView.Avalonia" Version="11.0.0.1" />
|
||||||
|
<PackageReference Include="WebView.Avalonia.Linux" Version="11.0.0.1" />
|
||||||
|
<PackageReference Include="WebView.Avalonia.Windows" Version="11.0.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -44,6 +50,12 @@
|
|||||||
<Compile Update="Views\ConfirmDialog.axaml.cs">
|
<Compile Update="Views\ConfirmDialog.axaml.cs">
|
||||||
<DependentUpon>ConfirmDialog.axaml</DependentUpon>
|
<DependentUpon>ConfirmDialog.axaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Update="Views\ThunderstoreView.axaml.cs">
|
||||||
|
<DependentUpon>ThunderstoreView.axaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Update="Views\StoreView.axaml.cs">
|
||||||
|
<DependentUpon>StoreView.axaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Update="Views\ServerDashboard.axaml.cs">
|
<Compile Update="Views\ServerDashboard.axaml.cs">
|
||||||
<DependentUpon>ServerDashboard.axaml</DependentUpon>
|
<DependentUpon>ServerDashboard.axaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -71,13 +71,31 @@ namespace Valheim_Dashboard.ViewModels
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Beim Erstellen direkt FTP-Verzeichnis laden
|
// Beim Erstellen direkt FTP-Verzeichnis laden
|
||||||
LoadFtpCommand.Execute().Subscribe();
|
|
||||||
|
//LoadFtpCommand.Execute().Subscribe();
|
||||||
Files.Add(new FtpItem { Name = "TestFile.txt", IsDirectory = false });
|
Files.Add(new FtpItem { Name = "TestFile.txt", IsDirectory = false });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Init(FtpClient ftpClient, string? startPath = null)
|
||||||
|
{
|
||||||
|
_ftpClient = ftpClient ?? throw new ArgumentNullException(nameof(ftpClient));
|
||||||
|
if (!string.IsNullOrEmpty(startPath))
|
||||||
|
CurrentPath = startPath;
|
||||||
|
|
||||||
|
// Erst hier laden
|
||||||
|
_ = LoadFtpDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task LoadFtpDirectory()
|
private async Task LoadFtpDirectory()
|
||||||
{
|
{
|
||||||
|
if (_ftpClient == null)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("⚠️ FTP-Client ist noch nicht verbunden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Verwende die neue Methode, um detaillierte Informationen zu erhalten
|
// Verwende die neue Methode, um detaillierte Informationen zu erhalten
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
using System;
|
||||||
using Valheim_Dashboard.ViewModels;
|
using Valheim_Dashboard.ViewModels;
|
||||||
using Valheim_Dashboard.Views;
|
using Valheim_Dashboard.Views;
|
||||||
|
|
||||||
@@ -13,24 +14,19 @@ namespace Valheim_Dashboard.ViewModels
|
|||||||
|
|
||||||
public MainWindowViewModel(ViewModelLocator locator)
|
public MainWindowViewModel(ViewModelLocator locator)
|
||||||
{
|
{
|
||||||
_locator = locator;
|
_locator = locator ?? throw new ArgumentNullException(nameof(locator));
|
||||||
|
|
||||||
// Initialer ViewModel über Locator setzen
|
// Initialer ViewModel über Locator setzen
|
||||||
if (Settings.SettingsLoad("LizenzKey") != null) {
|
string? lizenzKey = Settings.SettingsLoad("LizenzKey");
|
||||||
|
if (!string.IsNullOrEmpty(lizenzKey))
|
||||||
|
{
|
||||||
|
_locator.LizenzViewModel.LizenzKey = lizenzKey;
|
||||||
// Lizenzkey aus den Einstellungen laden
|
CurrentViewModel = _locator.FtpViewModel;
|
||||||
string lizenzKey = Settings.SettingsLoad("LizenzKey");
|
//CurrentViewModel = _locator.LizenzViewModel;
|
||||||
var lizenzViewModel = _locator.LizenzViewModel;
|
|
||||||
lizenzViewModel.LizenzKey = lizenzKey; // Lizenzkey übergeben
|
|
||||||
_currentViewModel = lizenzViewModel;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_currentViewModel = _locator.ErsterStartViewModel;
|
CurrentViewModel = _locator.ErsterStartViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,9 +61,17 @@ namespace Valheim_Dashboard.ViewModels
|
|||||||
|
|
||||||
public void SwitchToServerDashboard()
|
public void SwitchToServerDashboard()
|
||||||
{
|
{
|
||||||
|
_locator.ServerDashboardViewModel.Init();
|
||||||
CurrentViewModel = _locator.ServerDashboardViewModel;
|
CurrentViewModel = _locator.ServerDashboardViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void SwitchToStore()
|
||||||
|
{
|
||||||
|
CurrentViewModel = _locator.StoreViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
public void SwitchToDashboard()
|
public void SwitchToDashboard()
|
||||||
{
|
{
|
||||||
CurrentViewModel = _locator.DashboardViewModel;
|
CurrentViewModel = _locator.DashboardViewModel;
|
||||||
@@ -80,6 +84,8 @@ namespace Valheim_Dashboard.ViewModels
|
|||||||
{
|
{
|
||||||
// var ftpViewModel = new FtpViewModel(ftpClient);
|
// var ftpViewModel = new FtpViewModel(ftpClient);
|
||||||
// var ftpView = new FTPView(ftpViewModel);
|
// var ftpView = new FTPView(ftpViewModel);
|
||||||
|
//CurrentViewModel = _locator.FtpViewModel;
|
||||||
|
_locator.FtpViewModel.Init(ftpClient); // hier init
|
||||||
CurrentViewModel = _locator.FtpViewModel;
|
CurrentViewModel = _locator.FtpViewModel;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -87,5 +93,6 @@ namespace Valheim_Dashboard.ViewModels
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14
Valheim Dashboard/ViewModels/NexusViewModel.cs
Normal file
14
Valheim Dashboard/ViewModels/NexusViewModel.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using ReactiveUI;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Reactive;
|
||||||
|
|
||||||
|
namespace Valheim_Dashboard.ViewModels;
|
||||||
|
|
||||||
|
public class NexusViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
|
||||||
|
public NexusViewModel() { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -132,20 +132,28 @@ public class ServerDashboardViewModel : ViewModelBase
|
|||||||
get => _isLoading;
|
get => _isLoading;
|
||||||
set => this.RaiseAndSetIfChanged(ref _isLoading, value);
|
set => this.RaiseAndSetIfChanged(ref _isLoading, value);
|
||||||
}
|
}
|
||||||
|
private readonly MainWindowViewModel _main;
|
||||||
|
|
||||||
public ServerDashboardViewModel()
|
public ServerDashboardViewModel(MainWindowViewModel main)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_main = main;
|
||||||
|
|
||||||
InstallBepInExCommand = ReactiveCommand.Create(InstallBepInEx);
|
InstallBepInExCommand = ReactiveCommand.Create(InstallBepInEx);
|
||||||
UpdateBepInExCommand = ReactiveCommand.Create(UpdateBepInEx);
|
UpdateBepInExCommand = ReactiveCommand.Create(UpdateBepInEx);
|
||||||
UploadModCommand = ReactiveCommand.CreateFromTask(UploadMod);
|
UploadModCommand = ReactiveCommand.CreateFromTask(UploadMod);
|
||||||
InstallFromStoreCommand = ReactiveCommand.Create(InstallFromStore);
|
//InstallFromStoreCommand = ReactiveCommand.Create(InstallFromStore);
|
||||||
|
InstallFromStoreCommand = ReactiveCommand.Create(() =>
|
||||||
|
{
|
||||||
|
Debug.WriteLine("InstallFromStoreCommand");
|
||||||
|
_main.SwitchToStore();
|
||||||
|
});
|
||||||
SaveConfigCommand = ReactiveCommand.Create(SaveConfig);
|
SaveConfigCommand = ReactiveCommand.Create(SaveConfig);
|
||||||
RemoveModCommand = ReactiveCommand.Create<ModInfo,Task>(RemoveMod);
|
RemoveModCommand = ReactiveCommand.Create<ModInfo,Task>(RemoveMod);
|
||||||
UpdateModCommand = ReactiveCommand.Create<ModInfo>(UpdateMod);
|
UpdateModCommand = ReactiveCommand.Create<ModInfo>(UpdateMod);
|
||||||
|
|
||||||
|
|
||||||
// DEBUG: harter Testtext – MUSS im Editor erscheinen
|
|
||||||
ConfigDocument.Text = "Bitte Mod Auswählen";
|
|
||||||
|
|
||||||
// SelectedModConfig Sync mit ConfigDocument text (:
|
// SelectedModConfig Sync mit ConfigDocument text (:
|
||||||
|
|
||||||
@@ -167,11 +175,19 @@ public class ServerDashboardViewModel : ViewModelBase
|
|||||||
//Mods.Add(new ModInfo { Name = "BetterUI", Version = "2.3.4", ConfigPath = "config/better_ui.cfg" });
|
//Mods.Add(new ModInfo { Name = "BetterUI", Version = "2.3.4", ConfigPath = "config/better_ui.cfg" });
|
||||||
|
|
||||||
// Start async Initialisierung
|
// Start async Initialisierung
|
||||||
_ = InitializeAsync();
|
// _ = InitializeAsync();
|
||||||
|
|
||||||
//CheckBepInExStatus();
|
//CheckBepInExStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
// Start async Initialisierung
|
||||||
|
_ = InitializeAsync();
|
||||||
|
ConfigDocument.Text = "Bitte Mod Auswählen";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task InitializeAsync()
|
private async Task InitializeAsync()
|
||||||
{
|
{
|
||||||
IsLoading = true;
|
IsLoading = true;
|
||||||
@@ -714,7 +730,11 @@ public class ServerDashboardViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void InstallFromStore() { /* TODO */ }
|
private void InstallFromStore() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
private void SaveConfig() {
|
private void SaveConfig() {
|
||||||
Debug.WriteLine(SelectedMod.ConfigPath);
|
Debug.WriteLine(SelectedMod.ConfigPath);
|
||||||
FtpViewModel._ftpClient.UploadTextAsync(SelectedModConfig, SelectedMod.ConfigPath);
|
FtpViewModel._ftpClient.UploadTextAsync(SelectedModConfig, SelectedMod.ConfigPath);
|
||||||
|
|||||||
35
Valheim Dashboard/ViewModels/StoreViewModel.cs
Normal file
35
Valheim Dashboard/ViewModels/StoreViewModel.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using ReactiveUI;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Reactive;
|
||||||
|
|
||||||
|
namespace Valheim_Dashboard.ViewModels;
|
||||||
|
|
||||||
|
public class StoreViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
|
||||||
|
public ViewModelBase CurrentStoreView { get; set; }
|
||||||
|
public ReactiveCommand<Unit, Unit> BackCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, ViewModelBase> ShowThunderstoreCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, ViewModelBase> ShowNexusCommand { get; }
|
||||||
|
|
||||||
|
private readonly MainWindowViewModel _main;
|
||||||
|
|
||||||
|
public StoreViewModel(MainWindowViewModel main)
|
||||||
|
{
|
||||||
|
|
||||||
|
_main = main;
|
||||||
|
|
||||||
|
BackCommand = ReactiveCommand.Create(() =>
|
||||||
|
{
|
||||||
|
_main.SwitchToServerDashboard();
|
||||||
|
});
|
||||||
|
|
||||||
|
ShowThunderstoreCommand = ReactiveCommand.Create(() => CurrentStoreView = new ThunderstoreViewModel());
|
||||||
|
ShowNexusCommand = ReactiveCommand.Create(() => CurrentStoreView = new NexusViewModel());
|
||||||
|
|
||||||
|
// Default → Thunderstore
|
||||||
|
CurrentStoreView = new ThunderstoreViewModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
666
Valheim Dashboard/ViewModels/ThunderstoreViewModel.cs
Normal file
666
Valheim Dashboard/ViewModels/ThunderstoreViewModel.cs
Normal file
@@ -0,0 +1,666 @@
|
|||||||
|
using Avalonia.Media.Imaging; // <— für Bitmap
|
||||||
|
using Avalonia.Threading; // UI Thread
|
||||||
|
using Markdig;
|
||||||
|
using Markdig.Extensions.AutoIdentifiers;
|
||||||
|
using ReactiveUI;
|
||||||
|
using Splat.ModeDetection;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Reactive;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Valheim_Dashboard.Models;
|
||||||
|
|
||||||
|
namespace Valheim_Dashboard.ViewModels
|
||||||
|
{
|
||||||
|
public class ThunderstoreViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
private int _currentPage = 1;
|
||||||
|
private bool _hasMore = true;
|
||||||
|
private bool _isLoading;
|
||||||
|
private bool _inFlight;
|
||||||
|
private readonly ListFooterItem _footer = new();
|
||||||
|
// Index aller Mods, um Duplicates zu vermeiden
|
||||||
|
private static string MakeKey(string ns, string name) => $"{ns}/{name}";
|
||||||
|
private readonly Dictionary<string, StoreModInfo> _modIndex = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
|
||||||
|
// -------- HTTP Performance & Robustheit --------
|
||||||
|
private static readonly SocketsHttpHandler _httpHandler = new()
|
||||||
|
{
|
||||||
|
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli,
|
||||||
|
ConnectTimeout = TimeSpan.FromSeconds(5),
|
||||||
|
PooledConnectionLifetime = TimeSpan.FromMinutes(2),
|
||||||
|
MaxConnectionsPerServer = 8,
|
||||||
|
UseProxy = false,
|
||||||
|
ConnectCallback = async (ctx, ct) =>
|
||||||
|
{
|
||||||
|
var host = ctx.DnsEndPoint!.Host;
|
||||||
|
var port = ctx.DnsEndPoint!.Port;
|
||||||
|
IPAddress[] addrs = await Dns.GetHostAddressesAsync(host, ct).ConfigureAwait(false);
|
||||||
|
var addr = addrs.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork);
|
||||||
|
if (addr.Equals(default(IPAddress))) addr = addrs.First();
|
||||||
|
var socket = new Socket(addr.AddressFamily, SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
|
||||||
|
await socket.ConnectAsync(new IPEndPoint(addr, port), ct).ConfigureAwait(false);
|
||||||
|
return new NetworkStream(socket, ownsSocket: true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// HTTP/1.1 erzwingen
|
||||||
|
private readonly HttpClient _http = new(_httpHandler)
|
||||||
|
{
|
||||||
|
Timeout = TimeSpan.FromSeconds(15),
|
||||||
|
DefaultRequestVersion = HttpVersion.Version11,
|
||||||
|
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact
|
||||||
|
};
|
||||||
|
|
||||||
|
private readonly ThunderstoreApiClient _api;
|
||||||
|
public ModDetailsViewModel ModDetails { get; }
|
||||||
|
|
||||||
|
// Icon-Download Throttling
|
||||||
|
private static readonly SemaphoreSlim _iconGate = new(6);
|
||||||
|
|
||||||
|
private string? _searchText;
|
||||||
|
public string? SearchText
|
||||||
|
{
|
||||||
|
get => _searchText;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _searchText, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReactiveCommand<Unit, Unit> RunSearchCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> ClearSearchCommand { get; }
|
||||||
|
|
||||||
|
public ThunderstoreViewModel()
|
||||||
|
{
|
||||||
|
_http.DefaultRequestHeaders.Accept.ParseAdd("application/json");
|
||||||
|
_http.DefaultRequestHeaders.UserAgent.ParseAdd("ValheimDashboard/1.0");
|
||||||
|
|
||||||
|
_api = new ThunderstoreApiClient(_http);
|
||||||
|
ModDetails = new ModDetailsViewModel(_api);
|
||||||
|
|
||||||
|
Mods.CollectionChanged += (_, __) => this.RaisePropertyChanged(nameof(ModsWithFooter));
|
||||||
|
|
||||||
|
LoadNextPageCommand = ReactiveCommand.CreateFromTask(() => LoadNextPageAsync(prefetchNext: false));
|
||||||
|
InstallModCommand = ReactiveCommand.CreateFromTask<StoreModInfo>(InstallModAsync);
|
||||||
|
OpenPageCommand = ReactiveUI.ReactiveCommand.Create<string>(OpenPage);
|
||||||
|
OpenModCommand = ReactiveUI.ReactiveCommand.Create<StoreModInfo>(m => SelectedMod = m);
|
||||||
|
|
||||||
|
RunSearchCommand = ReactiveCommand.CreateFromTask(RunSearchAsync);
|
||||||
|
ClearSearchCommand = ReactiveCommand.CreateFromTask(async () =>
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(SearchText))
|
||||||
|
{
|
||||||
|
SearchText = "";
|
||||||
|
await RunSearchAsync();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
_ = LoadNextPageAsync(prefetchNext: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RunSearchAsync()
|
||||||
|
{
|
||||||
|
_currentPage = 1;
|
||||||
|
HasMore = true;
|
||||||
|
|
||||||
|
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
Mods.Clear();
|
||||||
|
_modIndex.Clear(); // <— NEU
|
||||||
|
});
|
||||||
|
|
||||||
|
this.RaisePropertyChanged(nameof(ModsWithFooter));
|
||||||
|
await LoadNextPageAsync(prefetchNext: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string BuildListingUrl()
|
||||||
|
{
|
||||||
|
var baseUrl = $"https://thunderstore.io/api/cyberstorm/listing/valheim/?deprecated=False&nsfw=False&ordering=top-rated&included_categories=17&page={_currentPage}";
|
||||||
|
if (!string.IsNullOrWhiteSpace(SearchText))
|
||||||
|
baseUrl += $"&q={Uri.EscapeDataString(SearchText)}";
|
||||||
|
return baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableCollection<StoreModInfo> Mods { get; } = new();
|
||||||
|
public System.Collections.Generic.IEnumerable<object> ModsWithFooter
|
||||||
|
=> Mods.Cast<object>().Concat(new object[] { _footer });
|
||||||
|
|
||||||
|
private StoreModInfo? _selectedMod;
|
||||||
|
public StoreModInfo? SelectedMod
|
||||||
|
{
|
||||||
|
get => _selectedMod;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.RaiseAndSetIfChanged(ref _selectedMod, value);
|
||||||
|
this.RaisePropertyChanged(nameof(HasSelection));
|
||||||
|
_ = LoadDetailsForSelectionAsync(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool HasSelection => _selectedMod != null;
|
||||||
|
|
||||||
|
private async Task LoadDetailsForSelectionAsync(StoreModInfo? mod)
|
||||||
|
{
|
||||||
|
if (mod == null) return;
|
||||||
|
await ModDetails.LoadAsync(mod.Namespace, mod.PackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsLoading
|
||||||
|
{
|
||||||
|
get => _isLoading;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.RaiseAndSetIfChanged(ref _isLoading, value);
|
||||||
|
this.RaisePropertyChanged(nameof(IsFooterVisible));
|
||||||
|
this.RaisePropertyChanged(nameof(IsListEndVisible));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasMore
|
||||||
|
{
|
||||||
|
get => _hasMore;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.RaiseAndSetIfChanged(ref _hasMore, value);
|
||||||
|
this.RaisePropertyChanged(nameof(IsFooterVisible));
|
||||||
|
this.RaisePropertyChanged(nameof(IsListEndVisible));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsFooterVisible => IsLoading || !HasMore;
|
||||||
|
public bool IsListEndVisible => !IsLoading && !HasMore;
|
||||||
|
|
||||||
|
public ReactiveCommand<Unit, Unit> LoadNextPageCommand { get; }
|
||||||
|
public ReactiveCommand<StoreModInfo, Unit> InstallModCommand { get; }
|
||||||
|
public ReactiveCommand<string, Unit> OpenPageCommand { get; }
|
||||||
|
public ReactiveCommand<StoreModInfo, Unit> OpenModCommand { get; }
|
||||||
|
|
||||||
|
public async Task LoadNextPageAsync(bool prefetchNext = false)
|
||||||
|
{
|
||||||
|
if (_inFlight || !HasMore) return;
|
||||||
|
|
||||||
|
_inFlight = true;
|
||||||
|
IsLoading = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var req = new HttpRequestMessage(HttpMethod.Get, BuildListingUrl())
|
||||||
|
{
|
||||||
|
Version = HttpVersion.Version11,
|
||||||
|
VersionPolicy = HttpVersionPolicy.RequestVersionExact
|
||||||
|
};
|
||||||
|
|
||||||
|
using var res = await _http.SendAsync(req, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
|
||||||
|
res.EnsureSuccessStatusCode();
|
||||||
|
var json = await res.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
using var doc = JsonDocument.Parse(json);
|
||||||
|
var root = doc.RootElement;
|
||||||
|
|
||||||
|
if (root.TryGetProperty("results", out var results))
|
||||||
|
{
|
||||||
|
var buffer = new System.Collections.Generic.List<(string ns, string name, string? desc, string? iconUrl)>();
|
||||||
|
|
||||||
|
foreach (var el in results.EnumerateArray())
|
||||||
|
{
|
||||||
|
var name = el.GetProperty("name").GetString() ?? "";
|
||||||
|
var ns = el.GetProperty("namespace").GetString() ?? "";
|
||||||
|
var desc = el.TryGetProperty("description", out var d) ? d.GetString() : null;
|
||||||
|
var iconUrl = el.TryGetProperty("icon_url", out var i) ? i.GetString() : null;
|
||||||
|
buffer.Add((ns, name, desc, iconUrl));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auf dem UI-Thread Mods einfügen/aktualisieren und Index pflegen
|
||||||
|
var newForIcons = new System.Collections.Generic.List<(StoreModInfo mod, string iconUrl)>();
|
||||||
|
|
||||||
|
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
foreach (var (ns, name, desc, iconUrl) in buffer)
|
||||||
|
{
|
||||||
|
var key = MakeKey(ns, name);
|
||||||
|
if (_modIndex.TryGetValue(key, out var existing))
|
||||||
|
{
|
||||||
|
// Bereits vorhanden (ggf. temporär) -> nur anreichern
|
||||||
|
if (!string.IsNullOrWhiteSpace(desc) && string.IsNullOrWhiteSpace(existing.Description))
|
||||||
|
existing.Description = desc!;
|
||||||
|
existing.IsTemporary = false;
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(iconUrl) && existing.Icon is null)
|
||||||
|
newForIcons.Add((existing, iconUrl!));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Neu hinzufügen
|
||||||
|
var mod = new StoreModInfo
|
||||||
|
{
|
||||||
|
Namespace = ns,
|
||||||
|
PackageName = name,
|
||||||
|
Name = $"{ns}-{name}",
|
||||||
|
Description = desc ?? "",
|
||||||
|
Url = $"https://thunderstore.io/c/valheim/p/{ns}/{name}/"
|
||||||
|
};
|
||||||
|
Mods.Add(mod);
|
||||||
|
_modIndex[key] = mod;
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(iconUrl))
|
||||||
|
newForIcons.Add((mod, iconUrl!));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Icons asynchron (throttled) laden
|
||||||
|
foreach (var (mod, iconUrl) in newForIcons)
|
||||||
|
_ = LoadIconThrottledAsync(mod, iconUrl);
|
||||||
|
|
||||||
|
_currentPage++;
|
||||||
|
HasMore = root.TryGetProperty("next", out var next) && !string.IsNullOrWhiteSpace(next.GetString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("[Thunderstore] Ladefehler: The operation was canceled.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"[Thunderstore] Ladefehler: {ex.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoading = false;
|
||||||
|
_inFlight = false;
|
||||||
|
this.RaisePropertyChanged(nameof(ModsWithFooter));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefetchNext && HasMore)
|
||||||
|
_ = LoadNextPageAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Throttled Icon-Loader: lädt Bytes via API (IPv4/HTTP1.1) und setzt das Bitmap direkt.
|
||||||
|
public async Task LoadIconThrottledAsync(StoreModInfo mod, string iconUrl)
|
||||||
|
{
|
||||||
|
await _iconGate.WaitAsync().ConfigureAwait(false);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var bytes = await _api.GetBytesAsync(iconUrl).ConfigureAwait(false);
|
||||||
|
using var ms = new MemoryStream(bytes);
|
||||||
|
var bmp = new Bitmap(ms);
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(() => { mod.Icon = bmp; }); // <— setzt direkt die gebundene Property
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("[Icon] load failed: " + ex.Message);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_iconGate.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public StoreModInfo GetOrCreateTempMod(string ns, string name, string? url = null)
|
||||||
|
{
|
||||||
|
var key = MakeKey(ns, name);
|
||||||
|
if (_modIndex.TryGetValue(key, out var existing))
|
||||||
|
return existing;
|
||||||
|
|
||||||
|
var temp = new StoreModInfo
|
||||||
|
{
|
||||||
|
Namespace = ns,
|
||||||
|
PackageName = name,
|
||||||
|
Name = $"{ns}-{name}",
|
||||||
|
Url = url ?? $"https://thunderstore.io/c/valheim/p/{ns}/{name}/",
|
||||||
|
IsTemporary = true
|
||||||
|
};
|
||||||
|
|
||||||
|
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
|
Mods.Add(temp);
|
||||||
|
_modIndex[key] = temp; // <— Index pflegen
|
||||||
|
this.RaisePropertyChanged(nameof(ModsWithFooter));
|
||||||
|
});
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task OpenPackageAsync(string ns, string name, string? url = null)
|
||||||
|
{
|
||||||
|
var hit = GetOrCreateTempMod(ns, name, url); // <— statt eigener Logik
|
||||||
|
SelectedMod = hit;
|
||||||
|
|
||||||
|
await ModDetails.LoadAsync(ns, name);
|
||||||
|
|
||||||
|
var iconUrl = ModDetails?.Package?.Latest?.Icon;
|
||||||
|
if (!string.IsNullOrWhiteSpace(iconUrl))
|
||||||
|
_ = LoadIconThrottledAsync(hit, iconUrl!);
|
||||||
|
|
||||||
|
var desc = ModDetails?.Package?.Latest?.Description;
|
||||||
|
if (!string.IsNullOrWhiteSpace(desc))
|
||||||
|
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
hit.Description = desc!;
|
||||||
|
hit.IsTemporary = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task InstallModAsync(StoreModInfo mod)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"Installiere: {mod.Name}");
|
||||||
|
await Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenPage(string? url)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(url)) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
|
||||||
|
Process.Start(psi);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------- Details-VM (unverändert zur letzten Version) --------------------
|
||||||
|
public sealed class ModDetailsViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
private readonly ThunderstoreApiClient _api;
|
||||||
|
private CancellationTokenSource? _cts;
|
||||||
|
public event Action<string>? AnchorRequested;
|
||||||
|
public event Action<string, string, string?>? OpenPackageRequested; // ns,name,url
|
||||||
|
|
||||||
|
private string _readmeHtml = "<p>Loading…</p>";
|
||||||
|
public string ReadmeHtml
|
||||||
|
{
|
||||||
|
get => _readmeHtml;
|
||||||
|
private set => this.RaiseAndSetIfChanged(ref _readmeHtml, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModDetailsViewModel(ThunderstoreApiClient api)
|
||||||
|
{
|
||||||
|
_api = api;
|
||||||
|
OpenUrlCommand = ReactiveCommand.Create<string?>(OpenUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _isLoading;
|
||||||
|
public bool IsLoading { get => _isLoading; set => this.RaiseAndSetIfChanged(ref _isLoading, value); }
|
||||||
|
|
||||||
|
private string _error = "";
|
||||||
|
public string Error { get => _error; set { this.RaiseAndSetIfChanged(ref _error, value); this.RaisePropertyChanged(nameof(HasError)); } }
|
||||||
|
public bool HasError => !string.IsNullOrWhiteSpace(Error);
|
||||||
|
|
||||||
|
private ThunderstorePackageExperimental? _pkg;
|
||||||
|
public ThunderstorePackageExperimental? Package { get => _pkg; set => this.RaiseAndSetIfChanged(ref _pkg, value); }
|
||||||
|
|
||||||
|
private Avalonia.Media.Imaging.Bitmap? _iconBitmap;
|
||||||
|
public Avalonia.Media.Imaging.Bitmap? IconBitmap
|
||||||
|
{
|
||||||
|
get => _iconBitmap;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _iconBitmap, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CategoriesJoined =>
|
||||||
|
Package?.CommunityListings is { Count: > 0 }
|
||||||
|
? string.Join(", ", Package.CommunityListings
|
||||||
|
.Where(c => c.Categories != null)
|
||||||
|
.SelectMany(c => c.Categories!)
|
||||||
|
.Distinct()
|
||||||
|
.OrderBy(s => s))
|
||||||
|
: "";
|
||||||
|
|
||||||
|
public string DependenciesJoined =>
|
||||||
|
Package?.Latest?.Dependencies is { Count: > 0 }
|
||||||
|
? string.Join(", ", Package.Latest.Dependencies!)
|
||||||
|
: "—";
|
||||||
|
|
||||||
|
public string DisplayTotalDownloads =>
|
||||||
|
Package is { TotalDownloads: > 0 } ? $"{Package!.TotalDownloads:N0} dl" : "—";
|
||||||
|
|
||||||
|
public string DisplayRating =>
|
||||||
|
Package is not null ? $"★ {Math.Max(0, Package!.RatingScore):0.0}" : "★ —";
|
||||||
|
|
||||||
|
public ReactiveCommand<string?, Unit> OpenUrlCommand { get; }
|
||||||
|
public ReactiveCommand<string?, Unit> LinkCommand { get; }
|
||||||
|
|
||||||
|
public string Readme { get; private set; }
|
||||||
|
|
||||||
|
public async Task LoadAsync(string ns, string name)
|
||||||
|
{
|
||||||
|
_cts?.Cancel();
|
||||||
|
_cts?.Dispose();
|
||||||
|
_cts = new CancellationTokenSource();
|
||||||
|
var ct = _cts.Token;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsLoading = true;
|
||||||
|
Error = "";
|
||||||
|
Readme = "";
|
||||||
|
IconBitmap = null;
|
||||||
|
|
||||||
|
Package = await _api.GetPackageAsync(ns, name, ct);
|
||||||
|
|
||||||
|
var iconUrl = Package?.Latest?.Icon;
|
||||||
|
if (!string.IsNullOrWhiteSpace(iconUrl))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var bytes = await _api.GetBytesAsync(iconUrl!, ct);
|
||||||
|
using var ms = new MemoryStream(bytes);
|
||||||
|
IconBitmap = new Avalonia.Media.Imaging.Bitmap(ms);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
var ver = Package?.Latest?.VersionNumber;
|
||||||
|
if (!string.IsNullOrWhiteSpace(ver))
|
||||||
|
{
|
||||||
|
var md = await _api.GetReadmeMarkdownAsync(ns, name, ver!, ct);
|
||||||
|
ReadmeHtml = BuildHtml(md ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.RaisePropertyChanged(nameof(ReadmeHtml));
|
||||||
|
this.RaisePropertyChanged(nameof(CategoriesJoined));
|
||||||
|
this.RaisePropertyChanged(nameof(DependenciesJoined));
|
||||||
|
this.RaisePropertyChanged(nameof(DisplayTotalDownloads));
|
||||||
|
this.RaisePropertyChanged(nameof(DisplayRating));
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException) { }
|
||||||
|
catch (Exception ex) { Error = ex.Message; }
|
||||||
|
finally { IsLoading = false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string BuildHtml(string md)
|
||||||
|
{
|
||||||
|
var pipeline = new MarkdownPipelineBuilder()
|
||||||
|
.UseAdvancedExtensions()
|
||||||
|
.UseAutoIdentifiers()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var body = Markdig.Markdown.ToHtml(md, pipeline);
|
||||||
|
|
||||||
|
var css = @"html,body{margin:0;padding:0;background:#111;color:#eaeaea;font-family:system-ui,Segoe UI,Roboto;line-height:1.6;overflow-wrap:anywhere}
|
||||||
|
a{color:#6aafe6}
|
||||||
|
img,video{max-width:100%;height:auto;display:block}
|
||||||
|
table{border-collapse:collapse;width:100%;table-layout:fixed}
|
||||||
|
th,td{border:1px solid #333;padding:.5rem;vertical-align:top;word-break:break-word}
|
||||||
|
pre,code{background:#1b1b1b}
|
||||||
|
pre{white-space:pre-wrap;word-break:break-word}
|
||||||
|
blockquote{border-left:3px solid #444;padding-left:1rem;color:#cfcfcf}";
|
||||||
|
|
||||||
|
var js = @"(function(){
|
||||||
|
window.__VD_QUEUE = window.__VD_QUEUE || [];
|
||||||
|
function post(o){ try{ __VD_QUEUE.push(JSON.stringify(o)); }catch(e){} }
|
||||||
|
function log(m){ post({type:'log', msg: (typeof m==='string'? m : JSON.stringify(m))}); }
|
||||||
|
|
||||||
|
function scrollToId(id){
|
||||||
|
try{
|
||||||
|
var el = document.getElementById(id);
|
||||||
|
if(!el){ log('anchor not found: '+id); return; }
|
||||||
|
el.scrollIntoView({block:'start'});
|
||||||
|
window.scrollBy(0,-12);
|
||||||
|
}catch(e){ log('scroll err '+e); }
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function(){
|
||||||
|
log('dom-ready');
|
||||||
|
}, {once:true});
|
||||||
|
|
||||||
|
document.addEventListener('click', function(e){
|
||||||
|
var a = e.target && e.target.closest ? e.target.closest('a[href]') : null;
|
||||||
|
if(!a) return;
|
||||||
|
if(e.defaultPrevented || e.button!==0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
||||||
|
|
||||||
|
var href = a.getAttribute('href'); if(!href) return;
|
||||||
|
|
||||||
|
// interne Anker
|
||||||
|
if(href[0]==='#'){ e.preventDefault(); scrollToId(decodeURIComponent(href.slice(1))); return; }
|
||||||
|
|
||||||
|
var u; try{ u = new URL(href, location.href); }catch(err){ return; }
|
||||||
|
|
||||||
|
var host=(u.hostname||'').toLowerCase(), path=u.pathname||'';
|
||||||
|
var isTs = /(^|\.)thunderstore\.io$/.test(host);
|
||||||
|
// Thunderstore-Package-Links
|
||||||
|
var m = path.match(/^\/c\/valheim\/p\/([^\/]+)\/([^\/]+)(?:\/.*)?$/i) || path.match(/^\/package\/([^\/]+)\/([^\/]+)(?:\/.*)?$/i);
|
||||||
|
|
||||||
|
if(isTs && m){
|
||||||
|
e.preventDefault();
|
||||||
|
post({type:'open-package', ns:m[1], name:m[2]});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Externe Navigation: WebView soll navigieren, aber Host informieren
|
||||||
|
try { post({type:'external-nav', url: u.href}); } catch(_){}
|
||||||
|
// kein preventDefault -> WebView navigiert selbst
|
||||||
|
}, true);
|
||||||
|
})();";
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append("<!doctype html><html><head><meta charset='utf-8'>");
|
||||||
|
sb.Append("<meta name='viewport' content='width=device-width,initial-scale=1'/>");
|
||||||
|
sb.Append("<style>").Append(css).Append("</style></head><body>");
|
||||||
|
sb.Append(body);
|
||||||
|
sb.Append("<script>").Append(js).Append("</script></body></html>");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void OpenUrl(string? url)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(url)) return;
|
||||||
|
try { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo { FileName = url, UseShellExecute = true }); } catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------- API-Client --------------------
|
||||||
|
public sealed class ThunderstoreApiClient
|
||||||
|
{
|
||||||
|
private readonly HttpClient _http;
|
||||||
|
private readonly JsonSerializerOptions _json = new()
|
||||||
|
{
|
||||||
|
PropertyNameCaseInsensitive = true,
|
||||||
|
NumberHandling = JsonNumberHandling.AllowReadingFromString
|
||||||
|
};
|
||||||
|
|
||||||
|
public ThunderstoreApiClient(HttpClient http) => _http = http;
|
||||||
|
|
||||||
|
public async Task<byte[]> GetBytesAsync(string url, CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
using var req = new HttpRequestMessage(HttpMethod.Get, url)
|
||||||
|
{
|
||||||
|
Version = HttpVersion.Version11,
|
||||||
|
VersionPolicy = HttpVersionPolicy.RequestVersionExact
|
||||||
|
};
|
||||||
|
using var res = await _http.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, ct).ConfigureAwait(false);
|
||||||
|
res.EnsureSuccessStatusCode();
|
||||||
|
return await res.Content.ReadAsByteArrayAsync(ct).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ThunderstorePackageExperimental?> GetPackageAsync(string ns, string name, CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
var url = $"https://thunderstore.io/api/experimental/package/{Uri.EscapeDataString(ns)}/{Uri.EscapeDataString(name)}/";
|
||||||
|
using var req = new HttpRequestMessage(HttpMethod.Get, url)
|
||||||
|
{
|
||||||
|
Version = HttpVersion.Version11,
|
||||||
|
VersionPolicy = HttpVersionPolicy.RequestVersionExact
|
||||||
|
};
|
||||||
|
using var res = await _http.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, ct).ConfigureAwait(false);
|
||||||
|
res.EnsureSuccessStatusCode();
|
||||||
|
await using var s = await res.Content.ReadAsStreamAsync(ct).ConfigureAwait(false);
|
||||||
|
return await JsonSerializer.DeserializeAsync<ThunderstorePackageExperimental>(s, _json, ct).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> GetReadmeMarkdownAsync(string ns, string name, string version, CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
var url = $"https://thunderstore.io/api/experimental/package/{Uri.EscapeDataString(ns)}/{Uri.EscapeDataString(name)}/{Uri.EscapeDataString(version)}/readme/";
|
||||||
|
using var req = new HttpRequestMessage(HttpMethod.Get, url)
|
||||||
|
{
|
||||||
|
Version = HttpVersion.Version11,
|
||||||
|
VersionPolicy = HttpVersionPolicy.RequestVersionExact
|
||||||
|
};
|
||||||
|
using var res = await _http.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, ct).ConfigureAwait(false);
|
||||||
|
res.EnsureSuccessStatusCode();
|
||||||
|
await using var s = await res.Content.ReadAsStreamAsync(ct).ConfigureAwait(false);
|
||||||
|
var data = await JsonSerializer.DeserializeAsync<ThunderstoreReadmeResponse>(s, _json, ct).ConfigureAwait(false);
|
||||||
|
return data?.Markdown ?? "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------- Experimental-Models --------------------
|
||||||
|
public sealed class ThunderstorePackageExperimental
|
||||||
|
{
|
||||||
|
[JsonPropertyName("namespace")] public string Namespace { get; set; } = "";
|
||||||
|
[JsonPropertyName("name")] public string Name { get; set; } = "";
|
||||||
|
[JsonPropertyName("full_name")] public string FullName { get; set; } = "";
|
||||||
|
[JsonPropertyName("owner")] public string Owner { get; set; } = "";
|
||||||
|
[JsonPropertyName("package_url")] public string PackageUrl { get; set; } = "";
|
||||||
|
[JsonPropertyName("date_created")] public DateTime? DateCreated { get; set; }
|
||||||
|
[JsonPropertyName("date_updated")] public DateTime? DateUpdated { get; set; }
|
||||||
|
[JsonPropertyName("rating_score")] public double RatingScore { get; set; }
|
||||||
|
[JsonPropertyName("is_pinned")] public bool IsPinned { get; set; }
|
||||||
|
[JsonPropertyName("is_deprecated")] public bool IsDeprecated { get; set; }
|
||||||
|
[JsonPropertyName("total_downloads")] public int TotalDownloads { get; set; }
|
||||||
|
[JsonPropertyName("latest")] public PackageVersionExperimental Latest { get; set; } = new();
|
||||||
|
[JsonPropertyName("community_listings")]
|
||||||
|
public System.Collections.Generic.List<PackageListingExperimental> CommunityListings { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class PackageVersionExperimental
|
||||||
|
{
|
||||||
|
[JsonPropertyName("namespace")] public string Namespace { get; set; } = "";
|
||||||
|
[JsonPropertyName("name")] public string Name { get; set; } = "";
|
||||||
|
[JsonPropertyName("version_number")] public string VersionNumber { get; set; } = "";
|
||||||
|
[JsonPropertyName("full_name")] public string FullName { get; set; } = "";
|
||||||
|
[JsonPropertyName("description")] public string Description { get; set; } = "";
|
||||||
|
[JsonPropertyName("icon")] public string Icon { get; set; } = "";
|
||||||
|
[JsonPropertyName("dependencies")] public System.Collections.Generic.List<string>? Dependencies { get; set; }
|
||||||
|
[JsonPropertyName("download_url")] public string DownloadUrl { get; set; } = "";
|
||||||
|
[JsonPropertyName("downloads")] public int Downloads { get; set; }
|
||||||
|
[JsonPropertyName("date_created")] public DateTime? DateCreated { get; set; }
|
||||||
|
[JsonPropertyName("website_url")] public string WebsiteUrl { get; set; } = "";
|
||||||
|
[JsonPropertyName("is_active")] public bool IsActive { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class PackageListingExperimental
|
||||||
|
{
|
||||||
|
[JsonPropertyName("has_nsfw_content")] public bool HasNsfwContent { get; set; }
|
||||||
|
[JsonPropertyName("categories")] public System.Collections.Generic.List<string>? Categories { get; set; }
|
||||||
|
[JsonPropertyName("community")] public string Community { get; set; } = "";
|
||||||
|
[JsonPropertyName("review_status")] public string ReviewStatus { get; set; } = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class ThunderstoreReadmeResponse
|
||||||
|
{
|
||||||
|
[JsonPropertyName("markdown")] public string Markdown { get; set; } = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,33 @@
|
|||||||
using Valheim_Dashboard.ViewModels;
|
using Valheim_Dashboard.ViewModels;
|
||||||
|
|
||||||
namespace Valheim_Dashboard
|
public class ViewModelLocator
|
||||||
{
|
{
|
||||||
public class ViewModelLocator
|
public MainWindowViewModel MainWindowViewModel { get; }
|
||||||
|
public ErsterStartViewModel ErsterStartViewModel { get; }
|
||||||
|
public LizenzViewModel LizenzViewModel { get; }
|
||||||
|
public ServerSettingsViewModel ServerSettingsViewModel { get; }
|
||||||
|
public ServerDashboardViewModel ServerDashboardViewModel { get; }
|
||||||
|
public DashboardViewModel DashboardViewModel { get; }
|
||||||
|
public StoreViewModel StoreViewModel { get; }
|
||||||
|
public ThunderstoreViewModel ThunderstoreViewModel { get; }
|
||||||
|
public FtpViewModel FtpViewModel { get; }
|
||||||
|
//public FtpViewModel FtpViewModel => new FtpViewModel(); // Hinzugef<65>gt
|
||||||
|
public ViewModelLocator()
|
||||||
{
|
{
|
||||||
public MainWindowViewModel MainWindowViewModel => new MainWindowViewModel(this);
|
// Erst diese ohne Dependencies
|
||||||
public ErsterStartViewModel ErsterStartViewModel => new ErsterStartViewModel();
|
ErsterStartViewModel = new ErsterStartViewModel();
|
||||||
public LizenzViewModel LizenzViewModel => new LizenzViewModel(); // Hinzugefügt
|
LizenzViewModel = new LizenzViewModel();
|
||||||
public ServerSettingsViewModel ServerSettingsViewModel => new ServerSettingsViewModel(); // Hinzugefügt
|
ServerSettingsViewModel = new ServerSettingsViewModel();
|
||||||
|
DashboardViewModel = new DashboardViewModel();
|
||||||
|
FtpViewModel = new FtpViewModel();
|
||||||
|
|
||||||
public ServerDashboardViewModel ServerDashboardViewModel => new ServerDashboardViewModel(); // Hinzugefügt
|
// MainWindowVM bekommt den Locator
|
||||||
public DashboardViewModel DashboardViewModel => new DashboardViewModel(); // Hinzugefügt
|
MainWindowViewModel = new MainWindowViewModel(this);
|
||||||
public FtpViewModel FtpViewModel => new FtpViewModel(); // Hinzugefügt
|
|
||||||
|
// ViewModels, die Navigation brauchen, bekommen MainWindowViewModel
|
||||||
|
ServerDashboardViewModel = new ServerDashboardViewModel(MainWindowViewModel);
|
||||||
|
StoreViewModel = new StoreViewModel(MainWindowViewModel);
|
||||||
|
ThunderstoreViewModel = new ThunderstoreViewModel();
|
||||||
|
|
||||||
public ViewModelLocator() { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="1424" d:DesignHeight="714"
|
mc:Ignorable="d" d:DesignWidth="1424" d:DesignHeight="714"
|
||||||
x:Class="Valheim_Dashboard.Views.MainWindow"
|
x:Class="Valheim_Dashboard.Views.MainWindow"
|
||||||
x:DataType="vm:MainWindowViewModel" CanResize="false"
|
x:DataType="vm:MainWindowViewModel" CanResize="false"
|
||||||
Icon="/Assets/avalonia-logo.ico"
|
Icon="/Assets/vd.png"
|
||||||
Title="Valheim_Dashboard"
|
Title="Valheim Dashboard by tbS"
|
||||||
>
|
>
|
||||||
|
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
<TextBlock Text="Mods" FontSize="28" FontWeight="Bold" Grid.Row="0"/>
|
<TextBlock Text="Mods" FontSize="28" FontWeight="Bold" Grid.Row="0"/>
|
||||||
|
|
||||||
<!-- ListBox füllt jetzt automatisch den Rest -->
|
<!-- ListBox füllt jetzt automatisch den Rest -->
|
||||||
<StackPanel IsVisible="{Binding !IsModsLoading}">
|
<StackPanel IsVisible="{Binding !IsModsLoading}" Grid.Row="1">
|
||||||
<ListBox ItemsSource="{Binding Mods}" SelectedItem="{Binding SelectedMod}">
|
<ListBox ItemsSource="{Binding Mods}" SelectedItem="{Binding SelectedMod}">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
|
|||||||
@@ -152,7 +152,9 @@ public partial class ServerSettingsView : UserControl
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mainWindowViewModel.SwitchToFTP(ftpClient);
|
// Übergabe des Clients an ViewModel
|
||||||
|
mainWindowViewModel.SwitchToFTP(FtpViewModel._ftpClient);
|
||||||
|
//mainWindowViewModel.SwitchToFTP(ftpClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
23
Valheim Dashboard/Views/StoreView.axaml
Normal file
23
Valheim Dashboard/Views/StoreView.axaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<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"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="1280" d:DesignHeight="800"
|
||||||
|
x:Class="Valheim_Dashboard.Views.StoreView"
|
||||||
|
xmlns:vm="clr-namespace:Valheim_Dashboard.ViewModels"
|
||||||
|
x:DataType="vm:StoreViewModel"
|
||||||
|
>
|
||||||
|
|
||||||
|
<DockPanel Margin="20">
|
||||||
|
|
||||||
|
<!-- Navigation -->
|
||||||
|
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Spacing="10">
|
||||||
|
<Button Content="← Zurück" Command="{Binding BackCommand}" />
|
||||||
|
<Button Content="Thunderstore" Command="{Binding ShowThunderstoreCommand}" />
|
||||||
|
<Button Content="NexusMods" Command="{Binding ShowNexusCommand}" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- Innerer Bereich -->
|
||||||
|
<ContentControl Content="{Binding CurrentStoreView}" />
|
||||||
|
</DockPanel>
|
||||||
|
</UserControl>
|
||||||
33
Valheim Dashboard/Views/StoreView.axaml.cs
Normal file
33
Valheim Dashboard/Views/StoreView.axaml.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reactive.Linq;
|
||||||
|
using Avalonia.Animation;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Media;
|
||||||
|
using Avalonia.ReactiveUI;
|
||||||
|
using Avalonia.Styling;
|
||||||
|
using ReactiveUI;
|
||||||
|
using Valheim_Dashboard.ViewModels;
|
||||||
|
using static Valheim_Dashboard.Animationen;
|
||||||
|
using Valheim_Dashboard.Views;
|
||||||
|
|
||||||
|
namespace Valheim_Dashboard.Views
|
||||||
|
{
|
||||||
|
public partial class StoreView : ReactiveUserControl<StoreViewModel>
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public StoreView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
195
Valheim Dashboard/Views/ThunderstoreView.axaml
Normal file
195
Valheim Dashboard/Views/ThunderstoreView.axaml
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
<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:vm="clr-namespace:Valheim_Dashboard.ViewModels"
|
||||||
|
xmlns:models="clr-namespace:Valheim_Dashboard.Models"
|
||||||
|
xmlns:li="using:LoadingIndicators.Avalonia"
|
||||||
|
xmlns:conv="clr-namespace:Valheim_Dashboard.Converters"
|
||||||
|
xmlns:md="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
|
||||||
|
xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia"
|
||||||
|
xmlns:wv="using:AvaloniaWebView"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
x:Class="Valheim_Dashboard.Views.ThunderstoreView"
|
||||||
|
x:DataType="vm:ThunderstoreViewModel">
|
||||||
|
|
||||||
|
<UserControl.Resources>
|
||||||
|
<conv:BoolToColSpanConverter x:Key="ColSpanConverter"/>
|
||||||
|
</UserControl.Resources>
|
||||||
|
|
||||||
|
<Grid ColumnDefinitions="*,750" RowDefinitions="Auto,*" Margin="16">
|
||||||
|
<!-- Header -->
|
||||||
|
<StackPanel Grid.ColumnSpan="2" Orientation="Horizontal" Spacing="12" Margin="0,0,0,12">
|
||||||
|
<TextBlock Text="Thunderstore" FontSize="28" FontWeight="Bold"/>
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="6" Margin="12,0,0,0" VerticalAlignment="Center">
|
||||||
|
<TextBox Width="260"
|
||||||
|
Watermark="Suchen…"
|
||||||
|
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
<Button Content="Suchen" Command="{Binding RunSearchCommand}"/>
|
||||||
|
<Button Content="✕" Command="{Binding ClearSearchCommand}" ToolTip.Tip="Suche leeren"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- Linke Seite -->
|
||||||
|
<Border Grid.Row="1"
|
||||||
|
Grid.ColumnSpan="{Binding HasSelection, Converter={StaticResource ColSpanConverter}}"
|
||||||
|
Margin="0,0,8,0"
|
||||||
|
BorderBrush="#333" BorderThickness="1"
|
||||||
|
CornerRadius="8" Padding="8">
|
||||||
|
<ListBox x:Name="ModsList"
|
||||||
|
ItemsSource="{Binding ModsWithFooter}"
|
||||||
|
SelectedItem="{Binding SelectedMod, Mode=TwoWay}"
|
||||||
|
SelectionMode="Single">
|
||||||
|
<ListBox.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<VirtualizingStackPanel/>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ListBox.ItemsPanel>
|
||||||
|
|
||||||
|
<ListBox.DataTemplates>
|
||||||
|
<!-- Mod-Kachel -->
|
||||||
|
<DataTemplate x:DataType="models:StoreModInfo">
|
||||||
|
<Border Margin="0,6" Padding="10" Background="#1D1D1D" CornerRadius="10">
|
||||||
|
<Grid ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center">
|
||||||
|
<Image Width="56" Height="56" Source="{Binding Icon}"
|
||||||
|
Stretch="UniformToFill" ClipToBounds="True"/>
|
||||||
|
<StackPanel Grid.Column="1" Margin="12,0,12,0">
|
||||||
|
<TextBlock Text="{Binding Name}" FontWeight="SemiBold" FontSize="16"/>
|
||||||
|
<TextBlock Text="{Binding Description}" FontSize="12" Foreground="#AAAAAA"
|
||||||
|
TextWrapping="Wrap" MaxLines="2" TextTrimming="CharacterEllipsis"/>
|
||||||
|
</StackPanel>
|
||||||
|
<Button Grid.Column="2" MinWidth="120" Height="36" VerticalAlignment="Center"
|
||||||
|
Content="Installieren"
|
||||||
|
Command="{Binding $parent[UserControl].DataContext.InstallModCommand}"
|
||||||
|
CommandParameter="{Binding}"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
<DataTemplate x:DataType="models:ListFooterItem">
|
||||||
|
<StackPanel Margin="0,10,0,6"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
IsHitTestVisible="False"
|
||||||
|
DataContext="{Binding $parent[UserControl].DataContext}">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="10" HorizontalAlignment="Center">
|
||||||
|
<li:LoadingIndicator Width="22" Height="22"
|
||||||
|
IsActive="{Binding IsLoading}"
|
||||||
|
IsVisible="{Binding IsFooterVisible}"
|
||||||
|
Mode="Arcs" SpeedRatio="1.2"/>
|
||||||
|
<TextBlock Text="– Ende erreicht –"
|
||||||
|
Foreground="#BBBBBB"
|
||||||
|
IsVisible="{Binding IsListEndVisible}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListBox.DataTemplates>
|
||||||
|
</ListBox>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- Rechte Seite: nur wenn ausgewählt -->
|
||||||
|
<Border Grid.Column="1" Grid.Row="1"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
BorderBrush="#333" BorderThickness="1"
|
||||||
|
CornerRadius="8" Padding="16"
|
||||||
|
IsVisible="{Binding HasSelection}">
|
||||||
|
<!-- WICHTIG: an ModDetails binden, nicht an SelectedMod -->
|
||||||
|
<ContentControl Content="{Binding ModDetails}">
|
||||||
|
<ContentControl.ContentTemplate>
|
||||||
|
<DataTemplate x:DataType="vm:ModDetailsViewModel">
|
||||||
|
<Grid RowDefinitions="Auto,*">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="12">
|
||||||
|
<Image Source="{Binding IconBitmap}" Width="64" Height="64"/>
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="{Binding Package.FullName}" FontSize="20" FontWeight="Bold"/>
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||||
|
<Border CornerRadius="6" Padding="6,2" Background="#223344">
|
||||||
|
<TextBlock Text="{Binding DisplayTotalDownloads}"/>
|
||||||
|
</Border>
|
||||||
|
<Border CornerRadius="6" Padding="6,2" Background="#224422">
|
||||||
|
<TextBlock Text="{Binding DisplayRating}"/>
|
||||||
|
</Border>
|
||||||
|
<Border CornerRadius="6" Padding="6,2" Background="#664400"
|
||||||
|
IsVisible="{Binding Package.IsDeprecated}">
|
||||||
|
<TextBlock Text="Deprecated"/>
|
||||||
|
</Border>
|
||||||
|
</StackPanel>
|
||||||
|
<TextBlock Text="{Binding Package.Latest.VersionNumber}" Opacity="0.7"/>
|
||||||
|
</StackPanel>
|
||||||
|
<Button Content="Webseite"
|
||||||
|
HorizontalAlignment="Right"
|
||||||
|
Command="{Binding OpenUrlCommand}"
|
||||||
|
CommandParameter="{Binding Package.Latest.WebsiteUrl}"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<TabControl Grid.Row="1" Margin="0,12,0,0">
|
||||||
|
<TabItem Header="Übersicht">
|
||||||
|
<ScrollViewer>
|
||||||
|
<StackPanel Spacing="8">
|
||||||
|
<TextBlock Text="{Binding Package.Latest.Description}" TextWrapping="Wrap"/>
|
||||||
|
|
||||||
|
<UniformGrid Columns="2" Margin="0,8,0,0">
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="Owner" FontWeight="Bold"/>
|
||||||
|
<TextBlock Text="{Binding Package.Owner}"/>
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="Created" FontWeight="Bold"/>
|
||||||
|
<TextBlock Text="{Binding Package.DateCreated, StringFormat={}{0:yyyy-MM-dd}}"/>
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="Updated" FontWeight="Bold"/>
|
||||||
|
<TextBlock Text="{Binding Package.DateUpdated, StringFormat={}{0:yyyy-MM-dd}}"/>
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="Version Downloads" FontWeight="Bold"/>
|
||||||
|
<TextBlock Text="{Binding Package.Latest.Downloads, StringFormat={}{0:N0}}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</UniformGrid>
|
||||||
|
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="Dependencies" FontWeight="Bold" Margin="0,8,0,0"/>
|
||||||
|
<TextBlock Text="{Binding DependenciesJoined}" TextWrapping="Wrap"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="Kategorien" FontWeight="Bold" Margin="0,8,0,0"/>
|
||||||
|
<TextBlock Text="{Binding CategoriesJoined}" TextWrapping="Wrap"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</ScrollViewer>
|
||||||
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem Header="Readme">
|
||||||
|
<Grid RowDefinitions="Auto,*">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="6" Margin="0,0,0,8" Grid.Row="0">
|
||||||
|
<Button Content="◀" Click="OnBackClick"/>
|
||||||
|
<Button Content="▶" Click="OnForwardClick"/>
|
||||||
|
<Button Content="↺" Click="OnHomeClick"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<wv:WebView x:Name="ReadmeWeb"
|
||||||
|
AttachedToVisualTree="ReadmeWeb_OnAttached"
|
||||||
|
DetachedFromVisualTree="ReadmeWeb_OnDetached"
|
||||||
|
Grid.Row="1"/>
|
||||||
|
|
||||||
|
<li:LoadingIndicator IsActive="{Binding IsLoading}"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Width="28" Height="28"
|
||||||
|
Mode="Arcs" />
|
||||||
|
<TextBlock Text="{Binding Error}" Foreground="Tomato"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
IsVisible="{Binding HasError}"/>
|
||||||
|
</Grid>
|
||||||
|
</TabItem>
|
||||||
|
</TabControl>
|
||||||
|
</Grid>
|
||||||
|
</DataTemplate>
|
||||||
|
</ContentControl.ContentTemplate>
|
||||||
|
</ContentControl>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
522
Valheim Dashboard/Views/ThunderstoreView.axaml.cs
Normal file
522
Valheim Dashboard/Views/ThunderstoreView.axaml.cs
Normal file
@@ -0,0 +1,522 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Presenters;
|
||||||
|
using Avalonia.Controls.Primitives;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using Avalonia.VisualTree;
|
||||||
|
using Avalonia.WebView;
|
||||||
|
using AvaloniaWebView;
|
||||||
|
using ExCSS;
|
||||||
|
using Markdown.Avalonia;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Valheim_Dashboard.ViewModels;
|
||||||
|
using WebViewCore.Events;
|
||||||
|
|
||||||
|
namespace Valheim_Dashboard.Views
|
||||||
|
{
|
||||||
|
public partial class ThunderstoreView : UserControl
|
||||||
|
{
|
||||||
|
private ScrollViewer? _scroll;
|
||||||
|
private bool _resetting;
|
||||||
|
private WebView? _readmeWeb;
|
||||||
|
private DispatcherTimer? _bridgeTimer;
|
||||||
|
private int _externalDepth;
|
||||||
|
|
||||||
|
// Bridge / Navigation
|
||||||
|
private string? _lastDrained; // entprellt JS-Queue
|
||||||
|
private string? _lastHtmlKey; // zuletzt geladener HTML-Hash (aus Dateiname)
|
||||||
|
private string? _currentFileUri; // aktuell geladene file://-URI (für Dedupl.)
|
||||||
|
|
||||||
|
// file://pfad -> (ns,name), damit Back/Forward des WebViews linke Auswahl synchronisiert
|
||||||
|
private readonly Dictionary<string, (string ns, string name)> _fileToMod = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
// eigene Mod-History (für Back, wenn WebView selbst kein Back hat)
|
||||||
|
private readonly Stack<(string ns, string name)> _navStack = new();
|
||||||
|
private bool _suppressPush; // verhindert „Push“ beim Back-Open
|
||||||
|
|
||||||
|
// Sauberes (De-)Abonnieren des Details-VM Handlers
|
||||||
|
private ModDetailsViewModel? _lastDetailsVm;
|
||||||
|
|
||||||
|
public ThunderstoreView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
this.AttachedToVisualTree += OnAttachedToVisualTree;
|
||||||
|
this.DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||||
|
ModsList.TemplateApplied += ModsList_TemplateApplied;
|
||||||
|
|
||||||
|
// Bei DataContext-Änderung erneut Hooken (idempotent)
|
||||||
|
this.DataContextChanged += (_, __) => HookAnchor();
|
||||||
|
|
||||||
|
// ModDetails.PropertyChanged idempotent abonnieren
|
||||||
|
this.DataContextChanged += (_, __) =>
|
||||||
|
{
|
||||||
|
if (_lastDetailsVm != null)
|
||||||
|
_lastDetailsVm.PropertyChanged -= ModDetailsOnPropertyChanged;
|
||||||
|
|
||||||
|
if (DataContext is ThunderstoreViewModel vm)
|
||||||
|
{
|
||||||
|
_lastDetailsVm = vm.ModDetails;
|
||||||
|
_lastDetailsVm.PropertyChanged += ModDetailsOnPropertyChanged;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_lastDetailsVm = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ModDetailsOnPropertyChanged(object? _, System.ComponentModel.PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.PropertyName == nameof(ModDetailsViewModel.ReadmeHtml) &&
|
||||||
|
DataContext is ThunderstoreViewModel vm)
|
||||||
|
{
|
||||||
|
await SetHtmlForCurrentAsync(vm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAttachedToVisualTree(object? s, VisualTreeAttachmentEventArgs e)
|
||||||
|
{
|
||||||
|
HookScroll();
|
||||||
|
HookAnchor();
|
||||||
|
base.OnAttachedToVisualTree(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDetachedFromVisualTree(object? s, VisualTreeAttachmentEventArgs e)
|
||||||
|
{
|
||||||
|
if (_scroll != null) _scroll.ScrollChanged -= OnScrollChanged;
|
||||||
|
_scroll = null;
|
||||||
|
|
||||||
|
if (_lastDetailsVm != null)
|
||||||
|
{
|
||||||
|
_lastDetailsVm.PropertyChanged -= ModDetailsOnPropertyChanged;
|
||||||
|
_lastDetailsVm = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnDetachedFromVisualTree(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------- XAML Events -----------
|
||||||
|
|
||||||
|
private async void ReadmeWeb_OnAttached(object? sender, VisualTreeAttachmentEventArgs e)
|
||||||
|
{
|
||||||
|
_readmeWeb = sender as WebView;
|
||||||
|
if (_readmeWeb is null)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("[WV] not found at attach.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_readmeWeb.PropertyChanged += OnWebPropertyChanged;
|
||||||
|
|
||||||
|
// JS-Bridge regelmäßig leeren
|
||||||
|
_bridgeTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(150) };
|
||||||
|
_bridgeTimer.Tick += BridgeTimer_Tick;
|
||||||
|
_bridgeTimer.Start();
|
||||||
|
|
||||||
|
// initial füllen
|
||||||
|
if (DataContext is ThunderstoreViewModel vm)
|
||||||
|
await SetHtmlForCurrentAsync(vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReadmeWeb_OnDetached(object? sender, VisualTreeAttachmentEventArgs e)
|
||||||
|
{
|
||||||
|
if (_readmeWeb != null)
|
||||||
|
_readmeWeb.PropertyChanged -= OnWebPropertyChanged;
|
||||||
|
|
||||||
|
if (_bridgeTimer != null)
|
||||||
|
{
|
||||||
|
_bridgeTimer.Tick -= BridgeTimer_Tick;
|
||||||
|
_bridgeTimer.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
_readmeWeb = null;
|
||||||
|
_bridgeTimer = null;
|
||||||
|
_lastDrained = null;
|
||||||
|
_lastHtmlKey = null;
|
||||||
|
_currentFileUri = null;
|
||||||
|
_externalDepth = 0;
|
||||||
|
_fileToMod.Clear();
|
||||||
|
_navStack.Clear();
|
||||||
|
_suppressPush = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------- Öffentlicher Back-Handler -----------
|
||||||
|
|
||||||
|
|
||||||
|
private async void OnBackClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// Wenn wir seit der aktuellen Readme nach extern navigiert sind → erst WebView zurück
|
||||||
|
if (_externalDepth > 0 && _readmeWeb?.IsCanGoBack == true)
|
||||||
|
{
|
||||||
|
_externalDepth--; // wir kommen einen Schritt aus dem externen Verlauf zurück
|
||||||
|
_readmeWeb.GoBack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sonst: Mod-History benutzen
|
||||||
|
if (_navStack.TryPop(out var prev))
|
||||||
|
{
|
||||||
|
_suppressPush = true;
|
||||||
|
try { await OpenModAsync(prev.ns, prev.name); } // lädt Readme + setzt Selektion
|
||||||
|
finally { _suppressPush = false; }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback
|
||||||
|
if (_readmeWeb?.IsCanGoBack == true)
|
||||||
|
_readmeWeb.GoBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private async Task SyncSelectionWithCurrentFileAsync()
|
||||||
|
{
|
||||||
|
if (_readmeWeb is null || DataContext is not ThunderstoreViewModel vm)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var url = _readmeWeb.Url?.ToString() ?? "";
|
||||||
|
if (string.IsNullOrWhiteSpace(url)) return;
|
||||||
|
|
||||||
|
// Fragment abwerfen
|
||||||
|
var noFrag = url.Split('#')[0];
|
||||||
|
|
||||||
|
// Robust normalisieren
|
||||||
|
if (!Uri.TryCreate(noFrag, UriKind.Absolute, out var u)) return;
|
||||||
|
if (!u.IsFile) return;
|
||||||
|
|
||||||
|
// internen Dedupe-Status aus der URL aktualisieren (wichtig nach Back/Forward!)
|
||||||
|
_currentFileUri = u.AbsoluteUri;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var file = Path.GetFileName(u.LocalPath);
|
||||||
|
var m = Regex.Match(file, @"vd_readme_([0-9A-F]+)\.html", RegexOptions.IgnoreCase);
|
||||||
|
if (m.Success) _lastHtmlKey = m.Groups[1].Value.ToUpperInvariant();
|
||||||
|
}
|
||||||
|
catch { /* egal */ }
|
||||||
|
|
||||||
|
// Schlüssel wie in SetHtmlForModAsync (slashes normalisieren)
|
||||||
|
var key = u.LocalPath.Replace('\\', '/');
|
||||||
|
|
||||||
|
Debug.WriteLine($"[WV SYNC] url={url} | key={key}");
|
||||||
|
|
||||||
|
if (!_fileToMod.TryGetValue(key, out var mod))
|
||||||
|
{
|
||||||
|
Debug.WriteLine("[WV SYNC] no mapping for key");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Linke Auswahl stellen, wenn abweichend
|
||||||
|
var hit = vm.Mods.FirstOrDefault(m =>
|
||||||
|
string.Equals(m.Namespace, mod.ns, StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
string.Equals(m.PackageName, mod.name, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
if (hit != null && !ReferenceEquals(hit, vm.SelectedMod))
|
||||||
|
{
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"[WV SYNC] select {mod.ns}/{mod.name}");
|
||||||
|
vm.SelectedMod = hit;
|
||||||
|
ModsList?.ScrollIntoView(hit);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------- VM → HTML ins WebView -----------
|
||||||
|
|
||||||
|
private async Task SetHtmlForCurrentAsync(ThunderstoreViewModel vm)
|
||||||
|
{
|
||||||
|
var html = vm.ModDetails.ReadmeHtml ?? "<p>(empty)</p>";
|
||||||
|
|
||||||
|
// Ziel-Mod (für History/Sync)
|
||||||
|
var ns =
|
||||||
|
vm.SelectedMod?.Namespace
|
||||||
|
?? vm.ModDetails.Package?.Latest?.Namespace
|
||||||
|
?? vm.ModDetails.Package?.Namespace
|
||||||
|
?? "";
|
||||||
|
|
||||||
|
var name =
|
||||||
|
vm.SelectedMod?.PackageName
|
||||||
|
?? vm.ModDetails.Package?.Latest?.Name
|
||||||
|
?? vm.ModDetails.Package?.Name
|
||||||
|
?? "";
|
||||||
|
|
||||||
|
await SetHtmlForModAsync(ns, name, html);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SetHtmlForModAsync(string ns, string name, string html)
|
||||||
|
{
|
||||||
|
if (_readmeWeb is null) return;
|
||||||
|
|
||||||
|
// stabile Temp-Datei pro Content-Hash → verhindert Spam
|
||||||
|
using var sha = SHA256.Create();
|
||||||
|
var key = Convert.ToHexString(sha.ComputeHash(Encoding.UTF8.GetBytes(html))).Substring(0, 16);
|
||||||
|
|
||||||
|
if (key == _lastHtmlKey && _currentFileUri is not null)
|
||||||
|
{
|
||||||
|
// gleicher Inhalt schon angezeigt → nichts tun
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = Path.Combine(Path.GetTempPath(), $"vd_readme_{key}.html");
|
||||||
|
if (!File.Exists(path))
|
||||||
|
await File.WriteAllTextAsync(path, html, Encoding.UTF8);
|
||||||
|
|
||||||
|
var fileUri = new Uri(path).AbsoluteUri;
|
||||||
|
|
||||||
|
// bereits diese Datei geladen? (Doppelnavigation vermeiden)
|
||||||
|
if (string.Equals(_currentFileUri, fileUri, StringComparison.OrdinalIgnoreCase))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Map für Back/Forward-Sync (LocalPath-Key)
|
||||||
|
var localKey = path.Replace('\\', '/');
|
||||||
|
_fileToMod[localKey] = (ns, name);
|
||||||
|
|
||||||
|
_lastHtmlKey = key;
|
||||||
|
_currentFileUri = fileUri;
|
||||||
|
|
||||||
|
_readmeWeb.Url = new Uri(fileUri);
|
||||||
|
_externalDepth = 0;
|
||||||
|
Debug.WriteLine("[WV] navigate to " + fileUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------- JS-Bridge (Queue) -----------
|
||||||
|
|
||||||
|
private async void BridgeTimer_Tick(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_readmeWeb is null) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var js = @"(function(){
|
||||||
|
try{
|
||||||
|
if(!window.__VD_QUEUE) return '[]';
|
||||||
|
var out = window.__VD_QUEUE.splice(0, window.__VD_QUEUE.length);
|
||||||
|
return JSON.stringify(out);
|
||||||
|
}catch(e){ return '[]'; }
|
||||||
|
})()";
|
||||||
|
|
||||||
|
var result = await _readmeWeb.ExecuteScriptAsync(js);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(result) || result == "null" || result == "undefined")
|
||||||
|
return;
|
||||||
|
|
||||||
|
// mache Engines liefern "\"[...]\"" → einmal decodieren
|
||||||
|
if (result.Length > 1 && result[0] == '"' && result[^1] == '"')
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var inner = JsonSerializer.Deserialize<string>(result);
|
||||||
|
if (!string.IsNullOrEmpty(inner)) result = inner;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == _lastDrained) return;
|
||||||
|
_lastDrained = result;
|
||||||
|
|
||||||
|
using var doc = JsonDocument.Parse(result);
|
||||||
|
if (doc.RootElement.ValueKind != JsonValueKind.Array) return;
|
||||||
|
|
||||||
|
foreach (var item in doc.RootElement.EnumerateArray())
|
||||||
|
{
|
||||||
|
var payload = item.ValueKind == JsonValueKind.String ? (item.GetString() ?? "") : item.GetRawText();
|
||||||
|
if (!string.IsNullOrWhiteSpace(payload))
|
||||||
|
HandleBridgeMessage(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("[WV] Bridge exec err: " + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleBridgeMessage(string json)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var doc = JsonDocument.Parse(json);
|
||||||
|
var root = doc.RootElement;
|
||||||
|
var type = root.TryGetProperty("type", out var t) ? t.GetString() : null;
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case "log":
|
||||||
|
{
|
||||||
|
var msg = root.TryGetProperty("msg", out var mEl) ? mEl.GetString() : null;
|
||||||
|
Debug.WriteLine("[WV LOG] " + (msg ?? ""));
|
||||||
|
if (!string.IsNullOrWhiteSpace(msg) && msg.Equals("dom-ready", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
// Falls Url-PropertyChanged nicht feuert: hier nachziehen
|
||||||
|
_ = SyncSelectionWithCurrentFileAsync();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "external-nav":
|
||||||
|
{
|
||||||
|
_externalDepth++;
|
||||||
|
var u = root.TryGetProperty("url", out var uEl) ? uEl.GetString() : "";
|
||||||
|
Debug.WriteLine("[WV NAV] external-nav " + u);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "open-package":
|
||||||
|
{
|
||||||
|
var ns = root.TryGetProperty("ns", out var nsEl) ? (nsEl.GetString() ?? "") : "";
|
||||||
|
var name = root.TryGetProperty("name", out var nEl) ? (nEl.GetString() ?? "") : "";
|
||||||
|
Debug.WriteLine($"[WV] open-package {ns}/{name}");
|
||||||
|
|
||||||
|
// aktuellen Mod in unsere History pushen (nur, wenn nicht gerade Back)
|
||||||
|
if (!_suppressPush && DataContext is ThunderstoreViewModel vm && vm.SelectedMod is not null)
|
||||||
|
{
|
||||||
|
_navStack.Push((vm.SelectedMod.Namespace, vm.SelectedMod.PackageName));
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = OpenModAsync(ns, name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("[WV HOST ERR] " + ex.Message + " | raw=" + json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------- WebView-URL-Änderung → linke Auswahl synchronisieren -----------
|
||||||
|
|
||||||
|
private void OnWebPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (_readmeWeb is null) return;
|
||||||
|
if (e.Property?.Name != nameof(WebView.Url)) return;
|
||||||
|
|
||||||
|
_ = SyncSelectionWithCurrentFileAsync(); // fire-and-forget
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------- Mod intern öffnen -----------
|
||||||
|
|
||||||
|
private async Task OpenModAsync(string ns, string name)
|
||||||
|
{
|
||||||
|
if (DataContext is not ThunderstoreViewModel vm) return;
|
||||||
|
|
||||||
|
// Zentrale Dedup-Logik im VM verwenden
|
||||||
|
var hit = vm.GetOrCreateTempMod(ns, name, $"https://thunderstore.io/c/valheim/p/{ns}/{name}/");
|
||||||
|
vm.SelectedMod = hit;
|
||||||
|
|
||||||
|
await vm.ModDetails.LoadAsync(ns, name);
|
||||||
|
|
||||||
|
// Icon + Beschreibung nachziehen
|
||||||
|
var pkg = vm.ModDetails.Package;
|
||||||
|
var iconUrl = pkg?.Latest?.Icon;
|
||||||
|
if (!string.IsNullOrWhiteSpace(iconUrl))
|
||||||
|
_ = vm.LoadIconThrottledAsync(hit, iconUrl!);
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(pkg?.Latest?.Description))
|
||||||
|
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
hit.Description = pkg!.Latest!.Description;
|
||||||
|
hit.IsTemporary = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
await SetHtmlForModAsync(ns, name, vm.ModDetails.ReadmeHtml ?? "<p>(empty)</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void OnForwardClick(object? s, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
=> _readmeWeb?.GoForward();
|
||||||
|
|
||||||
|
private async void OnHomeClick(object? s, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (_readmeWeb is null) return;
|
||||||
|
if (DataContext is ThunderstoreViewModel vm)
|
||||||
|
{
|
||||||
|
_resetting = true;
|
||||||
|
try { await SetHtmlForCurrentAsync(vm); }
|
||||||
|
finally { _resetting = false; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HookAnchor()
|
||||||
|
{
|
||||||
|
if (DataContext is not Valheim_Dashboard.ViewModels.ThunderstoreViewModel vm) return;
|
||||||
|
|
||||||
|
vm.ModDetails.OpenPackageRequested -= OnOpenPackageRequested;
|
||||||
|
vm.ModDetails.OpenPackageRequested += OnOpenPackageRequested;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnOpenPackageRequested(string ns, string name, string? url)
|
||||||
|
{
|
||||||
|
if (DataContext is not ThunderstoreViewModel vm) return;
|
||||||
|
|
||||||
|
if (!_suppressPush && vm.SelectedMod is not null)
|
||||||
|
_navStack.Push((vm.SelectedMod.Namespace, vm.SelectedMod.PackageName));
|
||||||
|
|
||||||
|
var hit = vm.GetOrCreateTempMod(ns, name, url);
|
||||||
|
|
||||||
|
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
vm.SelectedMod = hit;
|
||||||
|
ModsList?.ScrollIntoView(hit);
|
||||||
|
});
|
||||||
|
|
||||||
|
await vm.ModDetails.LoadAsync(ns, name);
|
||||||
|
|
||||||
|
var pkg = vm.ModDetails.Package;
|
||||||
|
var iconUrl = pkg?.Latest?.Icon;
|
||||||
|
if (!string.IsNullOrWhiteSpace(iconUrl))
|
||||||
|
_ = vm.LoadIconThrottledAsync(hit, iconUrl!);
|
||||||
|
|
||||||
|
var desc = pkg?.Latest?.Description;
|
||||||
|
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(desc))
|
||||||
|
hit.Description = desc!;
|
||||||
|
hit.IsTemporary = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void ModsList_TemplateApplied(object? s, TemplateAppliedEventArgs e) => HookScroll();
|
||||||
|
|
||||||
|
private void HookScroll()
|
||||||
|
{
|
||||||
|
if (_scroll != null) _scroll.ScrollChanged -= OnScrollChanged;
|
||||||
|
|
||||||
|
_scroll = ModsList?
|
||||||
|
.GetVisualDescendants()
|
||||||
|
.OfType<ScrollViewer>()
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
if (_scroll != null)
|
||||||
|
_scroll.ScrollChanged += OnScrollChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnScrollChanged(object? sender, ScrollChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (DataContext is not ThunderstoreViewModel vm || _scroll is null) return;
|
||||||
|
|
||||||
|
var extentH = _scroll.Extent.Height;
|
||||||
|
var viewH = _scroll.Viewport.Height;
|
||||||
|
var offsetY = _scroll.Offset.Y;
|
||||||
|
|
||||||
|
if (extentH <= 0 || viewH <= 0) return;
|
||||||
|
|
||||||
|
var nearEnd = offsetY + viewH >= extentH - 400;
|
||||||
|
if (nearEnd)
|
||||||
|
await vm.LoadNextPageAsync(prefetchNext: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user