Skip to content

Commit

Permalink
Improved state handling for bot settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaoticz committed May 9, 2024
1 parent 4c3fae3 commit 3c0f670
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions NadekoHub/Features/BotConfig/Services/NadekoResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ await GetDownloadUrlAsync(latestVersion, cToken),
public async ValueTask<string?> GetCurrentVersionAsync(CancellationToken cToken = default)
{
var botEntry = _appConfigManager.AppConfig.BotEntries[Id];

if (!string.IsNullOrWhiteSpace(botEntry.Version))
return botEntry.Version;

var assemblyUri = Path.Combine(botEntry.InstanceDirectoryUri, "NadekoBot.dll");

if (!File.Exists(assemblyUri))
{
await _appConfigManager.UpdateBotEntryAsync(Id, x => x with { Version = null }, cToken);
return null;
}

if (!string.IsNullOrWhiteSpace(botEntry.Version))
return botEntry.Version;

var nadekoAssembly = Assembly.LoadFile(assemblyUri);
var version = nadekoAssembly.GetName().Version
Expand Down
9 changes: 5 additions & 4 deletions NadekoHub/Features/BotConfig/ViewModels/BotConfigViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public BotConfigViewModel(IAppConfigManager appConfigManager, AppView mainWindow

var botEntry = _appConfigManager.AppConfig.BotEntries[botResolver.Id];

_ = LoadUpdateBarAsync(botResolver, updateBotBar);
_logWriter.TryRead(botResolver.Id, out var logContent);
FakeConsole.Content = logContent ?? string.Empty;
FakeConsole.Watermark = "Waiting for the bot to start...";
Expand All @@ -170,15 +171,12 @@ public BotConfigViewModel(IAppConfigManager appConfigManager, AppView mainWindow
_botAvatar = Utilities.LoadLocalImage(botEntry.AvatarUri);
BotName = botResolver.BotName;
Id = botResolver.Id;
UpdateBar.DependencyName = "Checking...";
IsBotRunning = botOrchestrator.IsBotRunning(botResolver.Id);

if (IsBotRunning)
EnableButtons(true, false);
else
EnableButtons(!Directory.Exists(botEntry.InstanceDirectoryUri), true);

_ = LoadUpdateBarAsync(botResolver, updateBotBar);
EnableButtons(!File.Exists(Path.Combine(botEntry.InstanceDirectoryUri, Resolver.FileName)), true);

// Dispose when the view is deactivated
this.WhenActivated(disposables => Disposable.Create(() => Dispose()).DisposeWith(disposables));
Expand Down Expand Up @@ -422,6 +420,9 @@ public void StopBot()
/// <param name="updateBotBar">The update bar.</param>
private async static Task LoadUpdateBarAsync(IBotResolver botResolver, DependencyButtonViewModel updateBotBar)
{
updateBotBar.DependencyName = "Checking...";
updateBotBar.Status = DependencyStatus.Checking;

var currentVersion = await botResolver.GetCurrentVersionAsync();
updateBotBar.DependencyName = string.IsNullOrWhiteSpace(currentVersion)
? "Not Installed"
Expand Down

0 comments on commit 3c0f670

Please sign in to comment.