- tweak: open content
This commit is contained in:
@@ -2,7 +2,9 @@ using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Media;
|
||||
@@ -25,6 +27,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
private readonly IServiceProvider _provider;
|
||||
private readonly ContentService _contentService;
|
||||
private readonly CancellationService _cancellationService;
|
||||
private readonly FileService _fileService;
|
||||
private readonly DebugService _debugService;
|
||||
private readonly PopupMessageService _popupService;
|
||||
public ObservableCollection<ContentEntry> Entries { get; } = new();
|
||||
@@ -42,14 +45,36 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
get => _selectedEntry;
|
||||
set
|
||||
{
|
||||
_selectedEntry = value;
|
||||
if (value is { Item: not null })
|
||||
{
|
||||
if (_fileService.ContentFileApi.TryOpen(value.Item.Value.Hash, out var stream))
|
||||
{
|
||||
var ext = Path.GetExtension(value.Item.Value.Path);
|
||||
|
||||
var myTempFile = Path.Combine(Path.GetTempPath(), "tempie"+ ext);
|
||||
|
||||
using(var sw = new FileStream(myTempFile, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
{
|
||||
stream.CopyTo(sw);
|
||||
}
|
||||
stream.Dispose();
|
||||
|
||||
var startInfo = new ProcessStartInfo(myTempFile)
|
||||
{
|
||||
UseShellExecute = true
|
||||
};
|
||||
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Entries.Clear();
|
||||
_selectedEntry = value;
|
||||
|
||||
if (value == null) return;
|
||||
|
||||
Console.WriteLine("Entries clear!");
|
||||
|
||||
if(value == null) return;
|
||||
|
||||
foreach (var (_,entryCh) in value.Childs)
|
||||
foreach (var (_, entryCh) in value.Childs)
|
||||
{
|
||||
Entries.Add(entryCh);
|
||||
}
|
||||
@@ -71,11 +96,22 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
_provider = provider;
|
||||
_contentService = contentService;
|
||||
_cancellationService = cancellationService;
|
||||
_fileService = fileService;
|
||||
_debugService = debugService;
|
||||
_popupService = popupService;
|
||||
|
||||
foreach (var info in hubService.ServerList)
|
||||
{
|
||||
_root.Add(new ContentEntry(this, ToContentUrl(info.Address.ToRobustUrl()),info.Address));
|
||||
}
|
||||
|
||||
hubService.HubServerChangedEventArgs += HubServerChangedEventArgs;
|
||||
hubService.HubServerLoaded += GoHome;
|
||||
|
||||
if (!hubService.IsUpdating)
|
||||
{
|
||||
GoHome();
|
||||
}
|
||||
}
|
||||
|
||||
private void GoHome()
|
||||
@@ -99,9 +135,9 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
};
|
||||
}
|
||||
|
||||
public async void Go(ContentPath path)
|
||||
public async void Go(ContentPath path, bool appendHistory = true)
|
||||
{
|
||||
if (path.Pathes.Count == 0)
|
||||
if (path.Pathes.Count <= 1)
|
||||
{
|
||||
SearchText = "";
|
||||
GoHome();
|
||||
@@ -112,8 +148,8 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SearchText = path.Path;
|
||||
|
||||
var oriPath = path.Clone();
|
||||
|
||||
path.Pathes.RemoveAt(0);
|
||||
path.Pathes.RemoveAt(0);
|
||||
@@ -136,21 +172,26 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
throw new Exception("Not found!");
|
||||
}
|
||||
|
||||
SelectedEntry = centry;
|
||||
if (appendHistory)
|
||||
{
|
||||
AppendHistory(SearchText);
|
||||
}
|
||||
SearchText = oriPath.Path;
|
||||
|
||||
SelectedEntry = centry;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
SearchText = oriPath.Path;
|
||||
_popupService.Popup(e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnBackEnter()
|
||||
{
|
||||
Go(new ContentPath(GetHistory()));
|
||||
Go(new ContentPath(GetHistory()), false);
|
||||
}
|
||||
|
||||
public void OnGoEnter()
|
||||
@@ -347,5 +388,10 @@ public struct ContentPath
|
||||
return Pathes.Last();
|
||||
}
|
||||
|
||||
public ContentPath Clone()
|
||||
{
|
||||
return new ContentPath(Pathes.ToList());
|
||||
}
|
||||
|
||||
public string Path => string.Join("/", Pathes);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class ExceptionViewModel : PopupViewModelBase
|
||||
public ExceptionViewModel(IServiceProvider serviceProvider) : base(serviceProvider){}
|
||||
|
||||
public override string Title => "Oopsie! Some shit is happened now!";
|
||||
public override bool IsClosable => true;
|
||||
|
||||
public ObservableCollection<Exception> Errors { get; } = new();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public partial class InfoPopupViewModel : PopupViewModelBase
|
||||
}
|
||||
|
||||
public override string Title => "Info";
|
||||
public override bool IsClosable => true;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _infoText = "Test";
|
||||
|
||||
@@ -13,6 +13,7 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
|
||||
public LoadingContextViewModel(IServiceProvider provider) : base(provider){}
|
||||
|
||||
public string LoadingName { get; set; } = "Loading...";
|
||||
public override bool IsClosable => false;
|
||||
|
||||
public override string Title => LoadingName;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
[
|
||||
new ListItemTemplate(typeof(AccountInfoViewModel), "Account", "Account"),
|
||||
new ListItemTemplate(typeof(ServerListViewModel), "HomeRegular", "Servers"),
|
||||
new ListItemTemplate(typeof(ContentBrowserViewModel), "HomeRegular", "Content")
|
||||
new ListItemTemplate(typeof(ContentBrowserViewModel), "GridRegular", "Content")
|
||||
];
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -65,6 +65,8 @@ public partial class MainViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _currentTitle = "Default";
|
||||
|
||||
[ObservableProperty] private bool _isPopupClosable = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private ListItemTemplate? _selectedListItem;
|
||||
|
||||
@@ -88,6 +90,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
{
|
||||
CurrentPopup = viewModelBase;
|
||||
CurrentTitle = viewModelBase.Title;
|
||||
IsPopupClosable = viewModelBase.IsClosable;
|
||||
OnOpenRequired();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace Nebula.Launcher.ViewModels;
|
||||
public abstract class PopupViewModelBase : ViewModelBase, IDisposable
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
public abstract string Title { get; }
|
||||
public abstract bool IsClosable { get; }
|
||||
|
||||
public PopupViewModelBase()
|
||||
{
|
||||
@@ -17,7 +19,6 @@ public abstract class PopupViewModelBase : ViewModelBase, IDisposable
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public abstract string Title { get; }
|
||||
public void Dispose()
|
||||
{
|
||||
_serviceProvider.GetService<PopupMessageService>()?.ClosePopup(this);
|
||||
|
||||
@@ -265,6 +265,7 @@ public sealed class LogPopupModelView : PopupViewModelBase
|
||||
}
|
||||
|
||||
public override string Title => "LOG";
|
||||
public override bool IsClosable => true;
|
||||
|
||||
public ObservableCollection<LogInfo> Logs { get; } = new();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.ViewHelper;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
@@ -33,9 +34,20 @@ public partial class ServerListViewModel : ViewModelBase
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_hubService = hubService;
|
||||
|
||||
foreach (var info in _hubService.ServerList)
|
||||
{
|
||||
UnsortedServers.Add(info);
|
||||
}
|
||||
|
||||
hubService.HubServerChangedEventArgs += HubServerChangedEventArgs;
|
||||
hubService.HubServerLoaded += HubServerLoaded;
|
||||
OnSearchChange += OnChangeSearch;
|
||||
|
||||
if (!hubService.IsUpdating)
|
||||
{
|
||||
SortServers();
|
||||
}
|
||||
}
|
||||
|
||||
private void HubServerLoaded()
|
||||
@@ -72,12 +84,15 @@ public partial class ServerListViewModel : ViewModelBase
|
||||
|
||||
private void SortServers()
|
||||
{
|
||||
ServerInfos.Clear();
|
||||
UnsortedServers.Sort(new ServerComparer());
|
||||
foreach (var server in UnsortedServers.Where(CheckServerThink))
|
||||
Task.Run(() =>
|
||||
{
|
||||
ServerInfos.Add(CreateServerView(server));
|
||||
}
|
||||
ServerInfos.Clear();
|
||||
UnsortedServers.Sort(new ServerComparer());
|
||||
foreach (var server in UnsortedServers.Where(CheckServerThink))
|
||||
{
|
||||
ServerInfos.Add(CreateServerView(server));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private bool CheckServerThink(ServerHubInfo hubInfo)
|
||||
@@ -100,7 +115,7 @@ public partial class ServerListViewModel : ViewModelBase
|
||||
|
||||
public void UpdateRequired()
|
||||
{
|
||||
_hubService.UpdateHub();
|
||||
Task.Run(_hubService.UpdateHub);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user