mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-13 20:33:49 +00:00
Merge branch 'main' into custom-tokenizer
This commit is contained in:
commit
e3cb7e9734
165 files changed
+4739
-1738
No files matched your search
@@ -1,5 +1,7 @@
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using AIStudio.Tools.Rust;
|
||||
|
||||
namespace AIStudio.Tools.Services;
|
||||
|
||||
public sealed partial class RustService
|
||||
@@ -117,4 +119,35 @@ public sealed partial class RustService
|
||||
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requests the Rust runtime to exit the entire desktop application.
|
||||
/// </summary>
|
||||
public async Task<bool> ExitApplication()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await this.http.PostAsync("/app/exit", null);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
this.logger?.LogError("Failed to exit the app due to network error: {StatusCode}.", response.StatusCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<AppExitResponse>(this.jsonRustSerializerOptions);
|
||||
if (result is null || !result.Success)
|
||||
{
|
||||
this.logger?.LogError("Failed to exit the app: {Error}", result?.ErrorMessage ?? "Unknown error");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.logger?.LogInformation("Exit request sent to Rust runtime.");
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.logger?.LogError(ex, "Exception while requesting application exit.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,22 @@ public sealed partial class RustService
|
||||
{
|
||||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(45));
|
||||
var response = await this.http.GetFromJsonAsync<UpdateResponse>("/updates/check", this.jsonRustSerializerOptions, cts.Token);
|
||||
|
||||
if (response == default)
|
||||
{
|
||||
this.logger!.LogError("Failed to check for an update: the Rust endpoint returned an empty response.");
|
||||
return new UpdateResponse
|
||||
{
|
||||
Error = true,
|
||||
UpdateIsAvailable = false,
|
||||
NewVersion = string.Empty,
|
||||
Changelog = string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
if (response.Error)
|
||||
this.logger!.LogWarning("The Rust updater reported an error while checking for updates.");
|
||||
|
||||
this.logger!.LogInformation($"Checked for an update: update available='{response.UpdateIsAvailable}'; error='{response.Error}'; next version='{response.NewVersion}'; changelog len='{response.Changelog.Length}'");
|
||||
return response;
|
||||
}
|
||||
@@ -20,6 +36,8 @@ public sealed partial class RustService
|
||||
{
|
||||
Error = true,
|
||||
UpdateIsAvailable = false,
|
||||
NewVersion = string.Empty,
|
||||
Changelog = string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,16 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
|
||||
private readonly SettingsManager settingsManager;
|
||||
private readonly MessageBus messageBus;
|
||||
private readonly RustService rust;
|
||||
private readonly ILogger<UpdateService> logger;
|
||||
|
||||
private TimeSpan updateInterval;
|
||||
|
||||
public UpdateService(MessageBus messageBus, SettingsManager settingsManager, RustService rust)
|
||||
public UpdateService(MessageBus messageBus, SettingsManager settingsManager, RustService rust, ILogger<UpdateService> logger)
|
||||
{
|
||||
this.settingsManager = settingsManager;
|
||||
this.messageBus = messageBus;
|
||||
this.rust = rust;
|
||||
this.logger = logger;
|
||||
|
||||
this.messageBus.RegisterComponent(this);
|
||||
this.ApplyFilters([], [ Event.USER_SEARCH_FOR_UPDATE ]);
|
||||
@@ -113,6 +115,23 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
|
||||
return;
|
||||
|
||||
var response = await this.rust.CheckForUpdate();
|
||||
if (response.Error)
|
||||
{
|
||||
this.logger.LogWarning("Update check failed. The updater did not return a usable result.");
|
||||
|
||||
if (notifyUserWhenNoUpdate)
|
||||
{
|
||||
SNACKBAR!.Add(TB("Failed to check for updates. Please try again later."), Severity.Error, config =>
|
||||
{
|
||||
config.Icon = Icons.Material.Filled.Error;
|
||||
config.IconSize = Size.Large;
|
||||
config.IconColor = Color.Error;
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.UpdateIsAvailable)
|
||||
{
|
||||
// ReSharper disable RedundantAssignment
|
||||
|
||||
Reference in new issue
Block a user