Idk, dev work goin on
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
|
||||
|
||||
namespace WinWARP.Core.ViewModels.Dialogs;
|
||||
|
||||
public partial class AddSubscriptionViewModel(ISubscriptionFetcher subscriptionFetcher, ILocalizationService localizationService) : ObservableObject
|
||||
{
|
||||
private readonly ISubscriptionFetcher _subscriptionFetcher = subscriptionFetcher;
|
||||
private readonly ILocalizationService _localizationService = localizationService;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(CanSubmit))]
|
||||
public partial string SubscriptionLink
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string CustomName
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial int UpdateInterval
|
||||
{
|
||||
get; set;
|
||||
} = 0;
|
||||
|
||||
public bool CanSubmit => _subscriptionFetcher.IsUrlValid(SubscriptionLink);
|
||||
}
|
||||
@@ -7,14 +7,9 @@ using WinWARP.Core.Services.Interfaces;
|
||||
|
||||
namespace WinWARP.Core.ViewModels;
|
||||
|
||||
public partial class HomeViewModel : ObservableObject
|
||||
public partial class HomeViewModel(INavigationService navigationService) : ObservableObject
|
||||
{
|
||||
private readonly INavigationService _navigationService;
|
||||
|
||||
public HomeViewModel(INavigationService navigationService)
|
||||
{
|
||||
_navigationService = navigationService;
|
||||
}
|
||||
private readonly INavigationService _navigationService = navigationService;
|
||||
|
||||
[RelayCommand]
|
||||
private void TestTransition()
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using WinWARP.Core.Models.Entities;
|
||||
|
||||
namespace WinWARP.Core.ViewModels;
|
||||
|
||||
public abstract partial class ServerItemViewModel : ObservableObject
|
||||
{
|
||||
public ServerItemViewModel(Server server)
|
||||
{
|
||||
Id = server.Id;
|
||||
DefaultTitle = server.DefaultTitle;
|
||||
Title = server.Title;
|
||||
ConnectionString = server.ConnectionString;
|
||||
Region = server.Region;
|
||||
}
|
||||
|
||||
public int Id
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string DefaultTitle
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string Title
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string ConnectionString
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string Region
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
[RelayCommand]
|
||||
public abstract Task DeleteAsync();
|
||||
|
||||
public abstract Task EditNameAsync();
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsNameEditing
|
||||
{
|
||||
get; set;
|
||||
} = false;
|
||||
|
||||
[RelayCommand]
|
||||
public void EditName()
|
||||
{
|
||||
if (IsNameEditing)
|
||||
EditNameAsync();
|
||||
IsNameEditing = !IsNameEditing;
|
||||
}
|
||||
|
||||
public ObservableCollection<string> Tags { get; } = [];
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using WinWARP.Core.Models.Entities;
|
||||
|
||||
namespace WinWARP.Core.ViewModels.Wrappers;
|
||||
|
||||
public partial class StandaloneServerViewModel : ServerItemViewModel
|
||||
{
|
||||
public StandaloneServerViewModel(StandaloneServer server) : base(server)
|
||||
{
|
||||
FilePath = server.FilePath;
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string FilePath
|
||||
{
|
||||
get; set;
|
||||
} = string.Empty;
|
||||
|
||||
public async override Task DeleteAsync()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async override Task EditNameAsync()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using WinWARP.Core.Messages;
|
||||
using WinWARP.Core.Models.Entities;
|
||||
|
||||
namespace WinWARP.Core.ViewModels.Wrappers;
|
||||
|
||||
public partial class SubscriptionServerViewModel : ServerItemViewModel
|
||||
{
|
||||
public SubscriptionServerViewModel(SubscriptionServer server) : base(server)
|
||||
{
|
||||
}
|
||||
|
||||
public async override Task DeleteAsync()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new DeleteServerItemMessage(this));
|
||||
}
|
||||
|
||||
public async override Task EditNameAsync()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user