mirror of
https://github.com/BlossomiShymae/Needlework.Net.git
synced 2026-02-04 19:23:13 +01:00
WIP
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
using Needlework.Net.Desktop.ViewModels;
|
||||
using Needlework.Net.Desktop.Views;
|
||||
using SukiUI.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Needlework.Net.Desktop.Services
|
||||
{
|
||||
public class DialogService
|
||||
{
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
|
||||
public Dictionary<string, SukiWindow> Dialogs { get; } = [];
|
||||
|
||||
public DialogService(IServiceProvider serviceProvider)
|
||||
{
|
||||
ServiceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public void ShowEndpoint(string endpoint)
|
||||
{
|
||||
if (!Dialogs.TryGetValue(endpoint, out var _))
|
||||
{
|
||||
var dialog = new EndpointView();
|
||||
dialog.DataContext = new EndpointViewModel(endpoint);
|
||||
dialog.Show();
|
||||
dialog.Closed += OnDialogClosed;
|
||||
Dialogs[endpoint] = dialog;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDialogClosed(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender == null)
|
||||
return;
|
||||
|
||||
var dialog = (SukiWindow)sender;
|
||||
if (dialog.DataContext is EndpointViewModel vm)
|
||||
{
|
||||
Dialogs.Remove(vm.Endpoint);
|
||||
dialog.DataContext = null;
|
||||
}
|
||||
|
||||
dialog.Closed -= OnDialogClosed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using Avalonia.Media;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Needlework.Net.Core;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Needlework.Net.Desktop.Services
|
||||
{
|
||||
public partial class LcuService : ObservableObject
|
||||
{
|
||||
public HttpClient HttpClient { get; }
|
||||
|
||||
public LcuSchemaHandler LcuSchemaHandler { get; }
|
||||
|
||||
[ObservableProperty] private string _statusText = "Offline";
|
||||
[ObservableProperty] private IBrush _statusColor = new SolidColorBrush(Colors.Red.ToUInt32());
|
||||
[ObservableProperty] private string _statusAddress = "N/A";
|
||||
|
||||
public LcuService(HttpClient httpClient)
|
||||
{
|
||||
HttpClient = httpClient;
|
||||
|
||||
Task.Run(ProcessBackground);
|
||||
}
|
||||
|
||||
private void ProcessBackground()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Needlework.Net.Desktop/Services/WindowService.cs
Normal file
53
Needlework.Net.Desktop/Services/WindowService.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Needlework.Net.Desktop.Messages;
|
||||
using Needlework.Net.Desktop.ViewModels;
|
||||
using Needlework.Net.Desktop.Views;
|
||||
using SukiUI.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Needlework.Net.Desktop.Services
|
||||
{
|
||||
public class WindowService : IRecipient<OopsiesWindowCanceledMessage>
|
||||
{
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
|
||||
public Dictionary<string, SukiWindow> EndpointWindows { get; } = []; // Workaround memory leak by storing and reusing windows.
|
||||
// Figure out why creating and closing windows leaks memory.
|
||||
|
||||
public OopsiesWindow? OopsiesWindow { get; set; }
|
||||
|
||||
public WindowService(IServiceProvider serviceProvider)
|
||||
{
|
||||
ServiceProvider = serviceProvider;
|
||||
|
||||
WeakReferenceMessenger.Default.Register<OopsiesWindowCanceledMessage>(this);
|
||||
}
|
||||
|
||||
public void ShowOopsiesWindow(string text)
|
||||
{
|
||||
if (OopsiesWindow != null) OopsiesWindow!.Close();
|
||||
|
||||
var window = new OopsiesWindow();
|
||||
window.DataContext = new OopsiesWindowViewModel(text);
|
||||
window.Show(App.MainWindow!);
|
||||
window.Closed += OnOopsiesWindowClosed;
|
||||
OopsiesWindow = window;
|
||||
}
|
||||
|
||||
public void OnOopsiesWindowClosed(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender == null) return;
|
||||
|
||||
var window = (OopsiesWindow)sender;
|
||||
window.DataContext = null;
|
||||
window.Closed -= OnOopsiesWindowClosed;
|
||||
OopsiesWindow = null;
|
||||
}
|
||||
|
||||
public void Receive(OopsiesWindowCanceledMessage message)
|
||||
{
|
||||
if (OopsiesWindow is OopsiesWindow window) window.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user