Idk, dev work goin on

This commit is contained in:
2026-09-09 16:19:45 +03:00 Unverified
parent b0d8bcd742
commit 17a0a9f7a6
318 changed files with 11908 additions and 81 deletions
@@ -1,19 +1,32 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Text;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using WinWARP.Core.Enums;
using WinWARP.Core.Messages;
using WinWARP.Core.Models.Entities;
using WinWARP.Core.Services.Interfaces;
using WinWARP.Core.ViewModels.Wrappers;
namespace WinWARP.Core.ViewModels;
public partial class SubsSettingsViewModel(ISubscriptionDbService dbService) : ObservableObject
public partial class SubsSettingsViewModel(ISubscriptionDbService dbService, ISubscriptionFetcher fetcher, IDialogService dialogService) : ObservableRecipient, IRecipient<DeleteServerItemMessage>
{
private readonly ISubscriptionDbService _dbService = dbService;
private readonly ISubscriptionFetcher _fetcher = fetcher;
private readonly IDialogService _dialogService = dialogService;
public ObservableCollection<Subscription> Subscriptions { get; } = [];
protected override void OnActivated()
{
Messenger.RegisterAll(this);
}
public ObservableCollection<SubscriptionViewModel> Subscriptions { get; } = [];
public ObservableCollection<ServerItemViewModel> Servers { get; } = [];
public async Task LoadSubscriptionsAsync()
{
@@ -21,33 +34,49 @@ public partial class SubsSettingsViewModel(ISubscriptionDbService dbService) : O
var data = await _dbService.GetSubscriptionsAsync();
foreach (var subscription in data)
{
Subscriptions.Add(subscription);
Subscriptions.Add(new SubscriptionViewModel(subscription));
}
Servers.Add(new StandaloneServerViewModel(new StandaloneServer() { Region = "NO", Title = "Not default title", DefaultTitle = "Default title" }) { Tags = { "VLESS", "GRPC", "REALITY" } });
ShowLoadingIndicator = false;
}
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(AddSubscriptionCommand))]
public partial string NewSubscriptionLink { get; set; } = string.Empty;
public partial bool ShowLoadingIndicator
{
get; set;
} = false;
[RelayCommand(CanExecute = nameof(CanAddSubscription))]
[RelayCommand]
public async Task AddSubscriptionAsync()
{
if (!string.IsNullOrWhiteSpace(NewSubscriptionLink))
(var result, var customName, var subscriptionLink, var updateInterval) = await _dialogService.ShowAddSubscriptionAsync();
if (result is CommonDialogResult.Cancel or CommonDialogResult.None or CommonDialogResult.Secondary) return;
ShowLoadingIndicator = true;
var subscription = await _fetcher.FetchAsync(subscriptionLink);
// TODO: error handling here and in the fetcher, dialog that will display exception
if (subscription == null)
{
var subscription = new Subscription
{
Link = NewSubscriptionLink,
Title = "New Subscription",
UpdateInterval = 60 // Default update interval
};
await _dbService.AddSubscriptionAsync(subscription);
Subscriptions.Add(subscription);
NewSubscriptionLink = string.Empty;
ShowLoadingIndicator = false;
return;
}
subscription.Title = customName;
subscription.UpdateInterval = updateInterval;
Subscriptions.Add(new SubscriptionViewModel(subscription));
foreach (var server in subscription.Servers)
{
Servers.Add(new SubscriptionServerViewModel(server) { Tags = { "VLESS", "WS", "TLS" } });
}
ShowLoadingIndicator = false;
}
private bool CanAddSubscription()
public void Receive(DeleteServerItemMessage message)
{
return !string.IsNullOrWhiteSpace(NewSubscriptionLink);
Debug.WriteLine($"Deleting server: {message.Value.Title}");
// TODO: add deletion logic
}
}