nicer syntax for registering navigation instances or lazy.
MODIFY
WalletWasabi.Fluent.Generators/NavigationMetaDataGenerator.cs
WalletWasabi.Fluent.Generators/NavigationMetaDataGenerator.cs
@@ -167,8 +167,9 @@ namespace {namespaceName}
source.Append($@" }};
");
- source.AppendLine(
- $@" public static void Register(Func<Task<RoutableViewModel>> createInstance) => NavigationManager.RegisterRoutable(MetaData, createInstance);");
+ source.AppendLine($@" public static void RegisterAsyncLazy(Func<Task<RoutableViewModel>> createInstance) => NavigationManager.RegisterAsyncLazy(MetaData, createInstance);");
+ source.AppendLine($@" public static void RegisterLazy(Func<RoutableViewModel> createInstance) => NavigationManager.RegisterLazy(MetaData, createInstance);");
+ source.AppendLine($@" public static void Register(RoutableViewModel createInstance) => NavigationManager.Register(MetaData, createInstance);");
source.Append($@" }}
}}");

MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
using System;
-using System.IO;
+using System.Reactive.Concurrency;
using NBitcoin;
using ReactiveUI;
using System.Reactive.Linq;
-using System.Threading.Tasks;
using WalletWasabi.Fluent.ViewModels.AddWallet;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Fluent.ViewModels.Dialogs;
@@ -12,7 +11,6 @@ using WalletWasabi.Fluent.ViewModels.NavBar;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Fluent.ViewModels.Search;
using WalletWasabi.Fluent.ViewModels.Settings;
-using WalletWasabi.Legal;
namespace WalletWasabi.Fluent.ViewModels
{
@@ -44,63 +42,70 @@ namespace WalletWasabi.Fluent.ViewModels
_isMainContentEnabled = true;
_isDialogScreenEnabled = true;
- _statusBar = new StatusBarViewModel(global.DataDir, global.Network, global.Config, global.HostedServices, global.BitcoinStore.SmartHeaderChain, global.Synchronizer, global.LegalDocuments);
+ _statusBar = new StatusBarViewModel(
+ global.DataDir,
+ global.Network,
+ global.Config,
+ global.HostedServices,
+ global.BitcoinStore.SmartHeaderChain,
+ global.Synchronizer,
+ global.LegalDocuments);
var walletManager = new WalletManagerViewModel(global.WalletManager, global.UiConfig);
- var addWalletPage = new AddWalletPageViewModel(global.LegalDocuments, global.WalletManager, global.BitcoinStore, global.Network);
+ var addWalletPage = new AddWalletPageViewModel(
+ global.LegalDocuments,
+ global.WalletManager,
+ global.BitcoinStore,
+ global.Network);
var settingsPage = new SettingsPageViewModel(global.Config, global.UiConfig);
-
var privacyMode = new PrivacyModeViewModel(global.UiConfig);
-
var homePage = new HomePageViewModel(walletManager, addWalletPage);
-
var searchPage = new SearchPageViewModel(walletManager);
_navBar = new NavBarViewModel(MainScreen, walletManager);
RegisterCategories(searchPage);
- HomePageViewModel.Register(async () => await Task.FromResult(homePage));
-
- SearchPageViewModel.Register(async () => await Task.FromResult(searchPage));
- PrivacyModeViewModel.Register(async ()=> await Task.FromResult(privacyMode));
- AddWalletPageViewModel.Register(async () => await Task.FromResult(addWalletPage));
+ HomePageViewModel.Register(homePage);
- SettingsPageViewModel.Register(async () =>
- {
- settingsPage.SelectedTab = 0;
- return await Task.FromResult(settingsPage);
- });
+ SearchPageViewModel.Register(searchPage);
+ PrivacyModeViewModel.Register(privacyMode);
+ AddWalletPageViewModel.Register(addWalletPage);
+ SettingsPageViewModel.Register(settingsPage);
- GeneralSettingsTabViewModel.Register(async () =>
+ GeneralSettingsTabViewModel.RegisterLazy(
+ () =>
{
settingsPage.SelectedTab = 0;
- return await Task.FromResult(settingsPage);
+ return settingsPage;
});
- PrivacySettingsTabViewModel.Register(async () =>
+ PrivacySettingsTabViewModel.RegisterLazy(
+ () =>
{
settingsPage.SelectedTab = 1;
- return await Task.FromResult(settingsPage);
+ return settingsPage;
});
- NetworkSettingsTabViewModel.Register(async () =>
+ NetworkSettingsTabViewModel.RegisterLazy(
+ () =>
{
settingsPage.SelectedTab = 2;
- return await Task.FromResult(settingsPage);
+ return settingsPage;
});
- BitcoinTabViewModel.Register(async () =>
+ BitcoinTabViewModel.RegisterLazy(
+ () =>
{
settingsPage.SelectedTab = 3;
- return await Task.FromResult(settingsPage);
+ return settingsPage;
});
- AboutViewModel.Register(async () => await Task.FromResult(new AboutViewModel()));
+ AboutViewModel.RegisterLazy(() => new AboutViewModel());
- _navBar.InitialiseAsync();
+ RxApp.MainThreadScheduler.Schedule(async () => await _navBar.InitialiseAsync());
searchPage.Initialise();
@@ -127,7 +132,13 @@ namespace WalletWasabi.Fluent.ViewModels
public void Initialize()
{
// Temporary to keep things running without VM modifications.
- MainWindowViewModel.Instance = new MainWindowViewModel(_global.Network, _global.UiConfig, _global.WalletManager, null!, null!, false);
+ MainWindowViewModel.Instance = new MainWindowViewModel(
+ _global.Network,
+ _global.UiConfig,
+ _global.WalletManager,
+ null!,
+ null!,
+ false);
StatusBar.Initialize(_global.Nodes.ConnectedNodes);

MODIFY
WalletWasabi.Fluent/ViewModels/Navigation/NavigationManager.cs
WalletWasabi.Fluent/ViewModels/Navigation/NavigationManager.cs
@@ -7,13 +7,58 @@ namespace WalletWasabi.Fluent.ViewModels.Navigation
{
public static class NavigationManager
{
- private static Dictionary<NavigationMetaData, Func<Task<RoutableViewModel>>> _navigationEntries = new();
+ private class InstanceGeneratorBase
+ {
+ }
+
+ private class AsyncInstanceGenerator : InstanceGeneratorBase
+ {
+ public AsyncInstanceGenerator(Func<Task<RoutableViewModel>> generate)
+ {
+ Generate = generate;
+ }
+
+ public Func<Task<RoutableViewModel>> Generate { get; }
+ }
+
+ private class SynchronousInstanceGenerator : InstanceGeneratorBase
+ {
+ public SynchronousInstanceGenerator(Func<RoutableViewModel> generate)
+ {
+ Generate = generate;
+ }
+
+ public Func<RoutableViewModel> Generate { get; }
+ }
+
+ private class InstanceGenerator : InstanceGeneratorBase
+ {
+ public InstanceGenerator(RoutableViewModel generate)
+ {
+ Generate = generate;
+ }
+
+ public RoutableViewModel Generate { get; }
+ }
+
+ private static readonly Dictionary<NavigationMetaData, InstanceGeneratorBase> _navigationEntries = new();
public static async Task<RoutableViewModel> MaterialiseViewModel(NavigationMetaData metaData)
{
if (_navigationEntries.ContainsKey(metaData))
{
- return await _navigationEntries[metaData]();
+ if (_navigationEntries[metaData] is InstanceGenerator instanceGenerator)
+ {
+ return instanceGenerator.Generate;
+ }
+ else if (_navigationEntries[metaData] is SynchronousInstanceGenerator synchronousInstanceGenerator)
+ {
+ return synchronousInstanceGenerator.Generate();
+ }
+ else if (_navigationEntries[metaData] is AsyncInstanceGenerator asyncInstanceGenerator)
+ {
+ return await asyncInstanceGenerator.Generate();
+ }
}
throw new Exception("ViewModel metadata not registered.");
@@ -21,7 +66,33 @@ namespace WalletWasabi.Fluent.ViewModels.Navigation
public static IEnumerable<NavigationMetaData> MetaData => _navigationEntries.Keys.Select(x => x);
- public static void RegisterRoutable(NavigationMetaData metaData, Func<Task<RoutableViewModel>> generator)
+ public static void RegisterAsyncLazy(NavigationMetaData metaData, Func<Task<RoutableViewModel>> generator)
+ {
+ if (metaData.Searchable && (metaData.Category is null || metaData.Title is null))
+ {
+ throw new Exception("Searchable entries must have both a Category and a Title");
+ }
+
+ if (!_navigationEntries.ContainsKey(metaData))
+ {
+ _navigationEntries.Add(metaData, new AsyncInstanceGenerator(generator));
+ }
+ }
+
+ public static void RegisterLazy(NavigationMetaData metaData, Func<RoutableViewModel> generator)
+ {
+ if (metaData.Searchable && (metaData.Category is null || metaData.Title is null))
+ {
+ throw new Exception("Searchable entries must have both a Category and a Title");
+ }
+
+ if (!_navigationEntries.ContainsKey(metaData))
+ {
+ _navigationEntries.Add(metaData, new SynchronousInstanceGenerator(generator));
+ }
+ }
+
+ public static void Register(NavigationMetaData metaData, RoutableViewModel instance)
{
if (metaData.Searchable && (metaData.Category is null || metaData.Title is null))
{
@@ -30,7 +101,7 @@ namespace WalletWasabi.Fluent.ViewModels.Navigation
if (!_navigationEntries.ContainsKey(metaData))
{
- _navigationEntries.Add(metaData, generator);
+ _navigationEntries.Add(metaData, new InstanceGenerator(instance));
}
}
}

nicer syntax for registering navigation instances or lazy.