ui(client): optimize installation key caching & show invalid key hint

This commit is contained in:
2025-11-09 08:40:18 +01:00
parent 463c2bbf2b
commit 562ce27341
4 changed files with 59 additions and 97 deletions

View File

@@ -1,11 +1,12 @@
using Unleash;
using System.Diagnostics.CodeAnalysis;
using Unleash;
using Unleash.ClientFactory;
namespace ModpackUpdater.Manager;
public class ModpackFeatures(ModpackConfig modpackConfig)
{
private IUnleash api;
private IUnleash? api;
private UnleashContext context;
private UnleashSettings settings;
@@ -26,20 +27,28 @@ public class ModpackFeatures(ModpackConfig modpackConfig)
return CheckFeature(feature, context);
}
public bool IsInvalid()
{
return string.IsNullOrWhiteSpace(modpackConfig.UnleashApiUrl) || string.IsNullOrWhiteSpace(modpackConfig.UnleashInstanceId);
}
[MemberNotNullWhen(true, nameof(api))]
private bool InitializeApi()
{
if (api == null && !string.IsNullOrWhiteSpace(modpackConfig.UnleashApiUrl) && !string.IsNullOrWhiteSpace(modpackConfig.UnleashInstanceId))
if (api != null
|| string.IsNullOrWhiteSpace(modpackConfig.UnleashApiUrl)
|| string.IsNullOrWhiteSpace(modpackConfig.UnleashInstanceId))
return api != null;
settings = new UnleashSettings
{
settings = new UnleashSettings
{
AppName = "Modpack Updater",
UnleashApi = new Uri(modpackConfig.UnleashApiUrl),
FetchTogglesInterval = TimeSpan.FromSeconds(60 * 5),
InstanceTag = modpackConfig.UnleashInstanceId,
};
AppName = "Modpack Updater",
UnleashApi = new Uri(modpackConfig.UnleashApiUrl),
FetchTogglesInterval = TimeSpan.FromSeconds(0),
InstanceTag = modpackConfig.UnleashInstanceId,
};
api = new UnleashClientFactory().CreateClient(settings, synchronousInitialization: true);
}
api = new UnleashClientFactory().CreateClient(settings, synchronousInitialization: true);
return api != null;
}