- fix: memory leak part 1
This commit is contained in:
@@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading.Tasks;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Utils;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared;
|
||||
@@ -69,7 +70,7 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
|
||||
public void OpenDataFolder()
|
||||
{
|
||||
ExplorerHelper.OpenFolder(FileService.RootPath);
|
||||
ExplorerUtils.OpenFolder(FileService.RootPath);
|
||||
}
|
||||
|
||||
public void ExportLogs()
|
||||
@@ -79,7 +80,7 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
ZipFile.CreateFromDirectory(logPath, Path.Join(path, DateTime.Now.ToString("yyyy-MM-dd") + ".zip"));
|
||||
ExplorerHelper.OpenFolder(path);
|
||||
ExplorerUtils.OpenFolder(path);
|
||||
}
|
||||
|
||||
public void RemoveAllContent()
|
||||
|
||||
@@ -11,6 +11,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Utils;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
@@ -63,7 +64,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase, IContentHol
|
||||
ContentService.Unpack(serverEntry.FileApi, myTempDir, loading.CreateLoadingContext());
|
||||
loading.Dispose();
|
||||
});
|
||||
ExplorerHelper.OpenFolder(tmpDir);
|
||||
ExplorerUtils.OpenFolder(tmpDir);
|
||||
}
|
||||
|
||||
public void OnGoEnter()
|
||||
@@ -80,10 +81,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase, IContentHol
|
||||
var cur = ServiceProvider.GetService<ServerFolderContentEntry>()!;
|
||||
cur.Init(this, ServerText.ToRobustUrl());
|
||||
var curContent = cur.Go(new ContentPath(SearchText), CancellationService.Token);
|
||||
if(curContent == null)
|
||||
throw new NullReferenceException($"{SearchText} not found in {ServerText}");
|
||||
|
||||
CurrentEntry = curContent;
|
||||
CurrentEntry = curContent ?? throw new NullReferenceException($"{SearchText} not found in {ServerText}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -23,22 +23,16 @@ namespace Nebula.Launcher.ViewModels.Pages;
|
||||
public partial class ServerOverviewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty] private string _searchText = string.Empty;
|
||||
|
||||
[ObservableProperty] private bool _isFilterVisible;
|
||||
|
||||
[ObservableProperty] private ServerListView _currentServerList = new();
|
||||
|
||||
public readonly ServerFilter CurrentFilter = new();
|
||||
|
||||
[GenerateProperty] private IServiceProvider ServiceProvider { get; }
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
|
||||
public ObservableCollection<ServerListTabTemplate> Items { get; private set; }
|
||||
[ObservableProperty] private ServerListTabTemplate _selectedItem;
|
||||
|
||||
[GenerateProperty, DesignConstruct] private ServerViewContainer ServerViewContainer { get; }
|
||||
|
||||
private Dictionary<string, ServerListView> _viewCache = [];
|
||||
[GenerateProperty, DesignConstruct] public ServerListViewModel CurrentServerList { get; }
|
||||
|
||||
|
||||
//Design think
|
||||
@@ -106,26 +100,19 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
{
|
||||
ServerViewContainer.Clear();
|
||||
CurrentServerList.RefreshFromProvider();
|
||||
CurrentServerList.RequireStatusUpdate();
|
||||
CurrentServerList.ApplyFilter(CurrentFilter);
|
||||
}
|
||||
|
||||
partial void OnSelectedItemChanged(ServerListTabTemplate value)
|
||||
{
|
||||
if (!_viewCache.TryGetValue(value.TabName, out var view))
|
||||
{
|
||||
view = ServerListView.TakeFrom(value.ServerListProvider);
|
||||
_viewCache[value.TabName] = view;
|
||||
}
|
||||
|
||||
CurrentServerList = view;
|
||||
CurrentServerList.Provider = value.ServerListProvider;
|
||||
ApplyFilter();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ServiceRegister]
|
||||
public class ServerViewContainer
|
||||
public sealed class ServerViewContainer
|
||||
{
|
||||
private readonly ViewHelperService _viewHelperService;
|
||||
private readonly List<string> _favorites = [];
|
||||
@@ -212,6 +199,10 @@ public class ServerViewContainer
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
foreach (var (_, value) in _entries)
|
||||
{
|
||||
value.Dispose();
|
||||
}
|
||||
_entries.Clear();
|
||||
}
|
||||
|
||||
@@ -244,7 +235,7 @@ public class ServerViewContainer
|
||||
}
|
||||
}
|
||||
|
||||
public interface IListEntryModelView
|
||||
public interface IListEntryModelView : IDisposable
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user