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
View File
@@ -10,7 +10,6 @@ public class AppDbContext : DbContext
{
public DbSet<Subscription> Subscriptions => Set<Subscription>();
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
+13
View File
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WinWARP.Core.Enums;
public enum CommonDialogResult
{
None,
Primary,
Secondary,
Cancel
}
+62
View File
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WinWARP.Core.Helper;
public static class FlagEmojiParser
{
private const int RegionalIndicatorStart = 0x1F1E6; // '🇦'
private const int RegionalIndicatorEnd = 0x1F1FF; // '🇿'
/// <summary>
/// Parses a string and returns a list of ISO 3166-1 alpha-2 country codes found as emojis.
/// </summary>
public static List<string> ExtractCountryCodes(string text)
{
var countryCodes = new List<string>();
if (string.IsNullOrEmpty(text)) return countryCodes;
var i = 0;
int? firstLetterCode = null;
while (i < text.Length)
{
// Read the 32-bit Unicode code point (handles emoji surrogate pairs)
var codePoint = char.ConvertToUtf32(text, i);
// Advance the index (surrogate pairs take 2 char slots in .NET strings)
i += char.IsSurrogatePair(text, i) ? 2 : 1;
// Check if the character is a Regional Indicator Symbol (A-Z flag component)
if (codePoint >= RegionalIndicatorStart && codePoint <= RegionalIndicatorEnd)
{
var letterOffset = codePoint - RegionalIndicatorStart; // 0 for A, 1 for B...
if (firstLetterCode == null)
{
// This is the first letter of a flag pair
firstLetterCode = letterOffset;
}
else
{
// This is the second letter of a flag pair. Construct the ISO string.
var c1 = (char)('A' + firstLetterCode.Value);
var c2 = (char)('A' + letterOffset);
countryCodes.Add($"{c1}{c2}");
// Reset to look for the next flag
firstLetterCode = null;
}
}
else
{
// If we hit any other character, break any broken/incomplete flag sequences
firstLetterCode = null;
}
}
return countryCodes;
}
}
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using CommunityToolkit.Mvvm.Messaging.Messages;
using WinWARP.Core.ViewModels;
namespace WinWARP.Core.Messages;
public class DeleteServerItemMessage : ValueChangedMessage<ServerItemViewModel>
{
public DeleteServerItemMessage(ServerItemViewModel serverItem) : base(serverItem) {}
}
+12 -2
View File
@@ -14,13 +14,23 @@ public abstract class Server
}
[Required]
public string Name
public string DefaultTitle
{
get; set;
}
[StringLength(100)]
public string CustomName
public string Title
{
get; set;
} = string.Empty;
public string Region
{
get; set;
} = string.Empty;
public string ConnectionString
{
get; set;
} = string.Empty;
@@ -7,7 +7,6 @@ namespace WinWARP.Core.Models.Entities;
public class StandaloneServer : Server
{
[Required]
public string FilePath
{
get; set;
@@ -10,9 +10,4 @@ public class SubscriptionServer : Server
{
get; set;
}
public string Region
{
get; set;
} = string.Empty;
}
@@ -10,7 +10,7 @@ namespace WinWARP.Core.Services.Implementations;
public class SubscriptionDbService : ISubscriptionDbService
{
private IDbContextFactory<AppDbContext> _dbContextFactory;
private readonly IDbContextFactory<AppDbContext> _dbContextFactory;
public SubscriptionDbService(IDbContextFactory<AppDbContext> dbContextFactory)
{
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;
using WinWARP.Core.Helper;
using WinWARP.Core.Models.Entities;
using WinWARP.Core.Services.Interfaces;
namespace WinWARP.Core.Services.Implementations;
public class SubscriptionFetcher : ISubscriptionFetcher
{
public bool IsUrlValid(string subscriptionUrl)
{
Uri? validatedUri;
if (!Uri.TryCreate(subscriptionUrl, UriKind.Absolute, out validatedUri))
{
return false;
}
return validatedUri.Scheme == Uri.UriSchemeHttp ||
validatedUri.Scheme == Uri.UriSchemeHttps;
}
public async Task<Subscription> FetchAsync(string subscriptionUrl)
{
// TODO: Implement the actual fetching logic here, e.g., using HttpClient to get the subscription data from the URL.
await Task.Delay(10); // Simulate an asynchronous operation
return new Subscription
{
DefaultTitle = "Default Subscription",
Link = subscriptionUrl,
Servers = [new() { DefaultTitle = "Default Server", Region = "NO", Title = "Not default title" }]
};
}
}
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using WinWARP.Core.Enums;
namespace WinWARP.Core.Services.Interfaces;
public interface IDialogService
{
Task<(CommonDialogResult Result, string Title, string URL, int UpdateInterval)> ShowAddSubscriptionAsync();
}
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using WinWARP.Core.Models.Entities;
namespace WinWARP.Core.Services.Interfaces;
public interface ISubscriptionFetcher
{
public bool IsUrlValid(string url);
public Task<Subscription> FetchAsync(string url);
}
@@ -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);
}
+2 -7
View File
@@ -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()
{
}
}