Ensure new wallets show up in the menu
This commit is contained in:
@@ -14,7 +14,7 @@ public class CreateWalletHandler(IWalletFactory componentFactory,
|
|||||||
{
|
{
|
||||||
if (args.Sender is Wallet <(string, string)> Wallet)
|
if (args.Sender is Wallet <(string, string)> Wallet)
|
||||||
{
|
{
|
||||||
if (Wallet.Value is (string name, string password) &&
|
if (Wallet.Sender is (string name, string password) &&
|
||||||
name is { Length: > 0 } &&
|
name is { Length: > 0 } &&
|
||||||
password is { Length: > 0 })
|
password is { Length: > 0 })
|
||||||
{
|
{
|
||||||
@@ -36,7 +36,7 @@ public class CreateWalletHandler(IWalletFactory componentFactory,
|
|||||||
configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
|
configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
|
||||||
host.Start();
|
host.Start();
|
||||||
|
|
||||||
publisher.Publish(Activated.As(host), cancellationToken);
|
publisher.Publish(Activated.As(new Wallet<IComponentHost>(host)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
[Notification(typeof(CreateEventArgs<IMainNavigationViewModel>), nameof(MainViewModel))]
|
[Notification(typeof(CreateEventArgs<IMainNavigationViewModel>), nameof(MainViewModel))]
|
||||||
|
[Notification(typeof(InsertEventArgs<IMainNavigationViewModel>), nameof(MainViewModel))]
|
||||||
public partial class MainViewModel :
|
public partial class MainViewModel :
|
||||||
ObservableCollection<IMainNavigationViewModel>
|
ObservableCollection<IMainNavigationViewModel>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class OpenWalletHandler(IConfigurationDescriptor<WalletConfiguration> des
|
|||||||
{
|
{
|
||||||
if (args.Sender is Wallet<string> Wallet &&
|
if (args.Sender is Wallet<string> Wallet &&
|
||||||
descriptor.Name is { Length: > 0 } name &&
|
descriptor.Name is { Length: > 0 } name &&
|
||||||
Wallet.Value is { Length: > 0 } password)
|
Wallet.Sender is { Length: > 0 } password)
|
||||||
{
|
{
|
||||||
WalletConfiguration configuration = descriptor.Value;
|
WalletConfiguration configuration = descriptor.Value;
|
||||||
if (configuration.Key?.Split(':') is { Length: >= 2 } keyPart)
|
if (configuration.Key?.Split(':') is { Length: >= 2 } keyPart)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class QueryWalletHandler(IDbContextFactory<WalletContext> dbContextFactor
|
|||||||
List<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)> items = [];
|
List<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)> items = [];
|
||||||
if (args.Value is Wallet<(string, string)> Wallet)
|
if (args.Value is Wallet<(string, string)> Wallet)
|
||||||
{
|
{
|
||||||
(string filter, string text) = Wallet.Value;
|
(string filter, string text) = Wallet.Sender;
|
||||||
|
|
||||||
ExpressionStarter<ItemEntry> predicate =
|
ExpressionStarter<ItemEntry> predicate =
|
||||||
PredicateBuilder.New<ItemEntry>(true);
|
PredicateBuilder.New<ItemEntry>(true);
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public record Wallet<TValue>(TValue Value);
|
public record Wallet<TSender>(TSender Sender);
|
||||||
|
|
||||||
public record Wallet;
|
public record Wallet;
|
||||||
@@ -5,25 +5,27 @@ namespace Wallet;
|
|||||||
|
|
||||||
public class WalletActivatedHandler(IWalletHostCollection Wallets,
|
public class WalletActivatedHandler(IWalletHostCollection Wallets,
|
||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
INotificationHandler<ActivatedEventArgs<IComponentHost>>
|
INotificationHandler<ActivatedEventArgs<Wallet<IComponentHost>>>
|
||||||
{
|
{
|
||||||
public Task Handle(ActivatedEventArgs<IComponentHost> args)
|
public Task Handle(ActivatedEventArgs<Wallet<IComponentHost>> args)
|
||||||
{
|
{
|
||||||
if (args.Sender is IComponentHost Wallet)
|
if (args.Sender is Wallet<IComponentHost> wallet && wallet.Sender is IComponentHost host)
|
||||||
{
|
{
|
||||||
List<IComponentHost> sortedWallets = [.. Wallets, Wallet];
|
List<IComponentHost> sortedWallets = [.. Wallets, host];
|
||||||
sortedWallets = [.. sortedWallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() is
|
sortedWallets = [.. sortedWallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() is
|
||||||
IConfigurationDescriptor<WalletConfiguration> descriptor ? descriptor.Name : null)];
|
IConfigurationDescriptor<WalletConfiguration> descriptor ? descriptor.Name : null)];
|
||||||
|
|
||||||
int index = sortedWallets.IndexOf(Wallet);
|
int index = sortedWallets.IndexOf(host);
|
||||||
|
|
||||||
if (Wallet.Services.GetRequiredService<ConfigurationDescriptor<WalletConfiguration>>() is ConfigurationDescriptor<WalletConfiguration> descriptor)
|
if (host.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() is
|
||||||
|
ConfigurationDescriptor<WalletConfiguration> descriptor)
|
||||||
{
|
{
|
||||||
if (Wallet.Services.GetRequiredService<IServiceFactory>() is IServiceFactory serviceFactory)
|
if (host.Services.GetRequiredService<IServiceFactory>() is IServiceFactory serviceFactory)
|
||||||
{
|
{
|
||||||
if (serviceFactory.Create<WalletNavigationViewModel>(descriptor.Name) is WalletNavigationViewModel viewModel)
|
if (serviceFactory.Create<WalletNavigationViewModel>(descriptor.Name, false)
|
||||||
|
is WalletNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
publisher.Publish(new InsertEventArgs<IMainNavigationViewModel>(index, viewModel),
|
publisher.Publish(Insert.As<IMainNavigationViewModel>(index, viewModel),
|
||||||
nameof(MainViewModel));
|
nameof(MainViewModel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user