Added update installation method configuration

This commit is contained in:
Thorsten Sommer 2025-08-26 18:47:26 +02:00
parent 487a1385f2
commit 06db007b1b
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
8 changed files with 49 additions and 4 deletions

View File

@ -13,7 +13,8 @@
<ConfigurationSelect OptionDescription="@T("Color theme")" SelectedValue="@(() => this.SettingsManager.ConfigurationData.App.PreferredTheme)" Data="@ConfigurationSelectDataFactory.GetThemesData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.App.PreferredTheme = selectedValue)" OptionHelp="@T("Choose the color theme that best suits for you.")"/> <ConfigurationSelect OptionDescription="@T("Color theme")" SelectedValue="@(() => this.SettingsManager.ConfigurationData.App.PreferredTheme)" Data="@ConfigurationSelectDataFactory.GetThemesData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.App.PreferredTheme = selectedValue)" OptionHelp="@T("Choose the color theme that best suits for you.")"/>
<ConfigurationOption OptionDescription="@T("Save energy?")" LabelOn="@T("Energy saving is enabled")" LabelOff="@T("Energy saving is disabled")" State="@(() => this.SettingsManager.ConfigurationData.App.IsSavingEnergy)" StateUpdate="@(updatedState => this.SettingsManager.ConfigurationData.App.IsSavingEnergy = updatedState)" OptionHelp="@T("When enabled, streamed content from the AI is updated once every third second. When disabled, streamed content will be updated as soon as it is available.")"/> <ConfigurationOption OptionDescription="@T("Save energy?")" LabelOn="@T("Energy saving is enabled")" LabelOff="@T("Energy saving is disabled")" State="@(() => this.SettingsManager.ConfigurationData.App.IsSavingEnergy)" StateUpdate="@(updatedState => this.SettingsManager.ConfigurationData.App.IsSavingEnergy = updatedState)" OptionHelp="@T("When enabled, streamed content from the AI is updated once every third second. When disabled, streamed content will be updated as soon as it is available.")"/>
<ConfigurationOption OptionDescription="@T("Enable spellchecking?")" LabelOn="@T("Spellchecking is enabled")" LabelOff="@T("Spellchecking is disabled")" State="@(() => this.SettingsManager.ConfigurationData.App.EnableSpellchecking)" StateUpdate="@(updatedState => this.SettingsManager.ConfigurationData.App.EnableSpellchecking = updatedState)" OptionHelp="@T("When enabled, spellchecking will be active in all input fields. Depending on your operating system, errors may not be visually highlighted, but right-clicking may still offer possible corrections.")"/> <ConfigurationOption OptionDescription="@T("Enable spellchecking?")" LabelOn="@T("Spellchecking is enabled")" LabelOff="@T("Spellchecking is disabled")" State="@(() => this.SettingsManager.ConfigurationData.App.EnableSpellchecking)" StateUpdate="@(updatedState => this.SettingsManager.ConfigurationData.App.EnableSpellchecking = updatedState)" OptionHelp="@T("When enabled, spellchecking will be active in all input fields. Depending on your operating system, errors may not be visually highlighted, but right-clicking may still offer possible corrections.")"/>
<ConfigurationSelect OptionDescription="@T("Check for updates")" SelectedValue="@(() => this.SettingsManager.ConfigurationData.App.UpdateInterval)" Data="@ConfigurationSelectDataFactory.GetUpdateBehaviorData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.App.UpdateInterval = selectedValue)" OptionHelp="@T("How often should we check for app updates?")" IsLocked="() => ManagedConfiguration.TryGet(x => x.App, x => x.UpdateInterval, out var meta) && meta.IsLocked"/> <ConfigurationSelect OptionDescription="@T("Check for updates")" SelectedValue="@(() => this.SettingsManager.ConfigurationData.App.UpdateInterval)" Data="@ConfigurationSelectDataFactory.GetUpdateIntervalData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.App.UpdateInterval = selectedValue)" OptionHelp="@T("How often should we check for app updates?")" IsLocked="() => ManagedConfiguration.TryGet(x => x.App, x => x.UpdateInterval, out var meta) && meta.IsLocked"/>
<ConfigurationSelect OptionDescription="@T("Update installation method")" SelectedValue="@(() => this.SettingsManager.ConfigurationData.App.UpdateBehaviour)" Data="@ConfigurationSelectDataFactory.GetUpdateBehaviourData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.App.UpdateBehaviour = selectedValue)" OptionHelp="@T("Should updates be installed automatically or manually?")" IsLocked="() => ManagedConfiguration.TryGet(x => x.App, x => x.UpdateBehaviour, out var meta) && meta.IsLocked"/>
<ConfigurationSelect OptionDescription="@T("Navigation bar behavior")" SelectedValue="@(() => this.SettingsManager.ConfigurationData.App.NavigationBehavior)" Data="@ConfigurationSelectDataFactory.GetNavBehaviorData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.App.NavigationBehavior = selectedValue)" OptionHelp="@T("Select the desired behavior for the navigation bar.")"/> <ConfigurationSelect OptionDescription="@T("Navigation bar behavior")" SelectedValue="@(() => this.SettingsManager.ConfigurationData.App.NavigationBehavior)" Data="@ConfigurationSelectDataFactory.GetNavBehaviorData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.App.NavigationBehavior = selectedValue)" OptionHelp="@T("Select the desired behavior for the navigation bar.")"/>
<ConfigurationSelect OptionDescription="@T("Preview feature visibility")" SelectedValue="@(() => this.SettingsManager.ConfigurationData.App.PreviewVisibility)" Data="@ConfigurationSelectDataFactory.GetPreviewVisibility()" SelectionUpdate="@this.UpdatePreviewFeatures" OptionHelp="@T("Do you want to show preview features in the app?")"/> <ConfigurationSelect OptionDescription="@T("Preview feature visibility")" SelectedValue="@(() => this.SettingsManager.ConfigurationData.App.PreviewVisibility)" Data="@ConfigurationSelectDataFactory.GetPreviewVisibility()" SelectionUpdate="@this.UpdatePreviewFeatures" OptionHelp="@T("Do you want to show preview features in the app?")"/>

View File

@ -92,7 +92,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
[ [
Event.UPDATE_AVAILABLE, Event.CONFIGURATION_CHANGED, Event.COLOR_THEME_CHANGED, Event.SHOW_ERROR, Event.UPDATE_AVAILABLE, Event.CONFIGURATION_CHANGED, Event.COLOR_THEME_CHANGED, Event.SHOW_ERROR,
Event.SHOW_ERROR, Event.SHOW_WARNING, Event.SHOW_SUCCESS, Event.STARTUP_PLUGIN_SYSTEM, Event.SHOW_ERROR, Event.SHOW_WARNING, Event.SHOW_SUCCESS, Event.STARTUP_PLUGIN_SYSTEM,
Event.PLUGINS_RELOADED Event.PLUGINS_RELOADED, Event.INSTALL_UPDATE,
]); ]);
// Set the snackbar for the update service: // Set the snackbar for the update service:
@ -143,6 +143,11 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
{ {
switch (triggeredEvent) switch (triggeredEvent)
{ {
case Event.INSTALL_UPDATE:
this.performingUpdate = true;
this.StateHasChanged();
break;
case Event.UPDATE_AVAILABLE: case Event.UPDATE_AVAILABLE:
if (data is UpdateResponse updateResponse) if (data is UpdateResponse updateResponse)
{ {

View File

@ -63,7 +63,7 @@ public static class ConfigurationSelectDataFactory
yield return new(TB("Enter is sending the input"), SendBehavior.ENTER_IS_SENDING); yield return new(TB("Enter is sending the input"), SendBehavior.ENTER_IS_SENDING);
} }
public static IEnumerable<ConfigurationSelectData<UpdateInterval>> GetUpdateBehaviorData() public static IEnumerable<ConfigurationSelectData<UpdateInterval>> GetUpdateIntervalData()
{ {
yield return new(TB("No automatic update checks"), UpdateInterval.NO_CHECK); yield return new(TB("No automatic update checks"), UpdateInterval.NO_CHECK);
yield return new(TB("Once at startup"), UpdateInterval.ONCE_STARTUP); yield return new(TB("Once at startup"), UpdateInterval.ONCE_STARTUP);
@ -71,6 +71,11 @@ public static class ConfigurationSelectDataFactory
yield return new(TB("Check every day"), UpdateInterval.DAILY); yield return new(TB("Check every day"), UpdateInterval.DAILY);
yield return new (TB("Check every week"), UpdateInterval.WEEKLY); yield return new (TB("Check every week"), UpdateInterval.WEEKLY);
} }
public static IEnumerable<ConfigurationSelectData<UpdateBehaviour>> GetUpdateBehaviourData()
{
yield return new(TB("Install updates manually"), UpdateBehaviour.MANUAL);
yield return new(TB("Install updates automatically"), UpdateBehaviour.AUTOMATIC);
} }
public static IEnumerable<ConfigurationSelectData<WorkspaceStorageBehavior>> GetWorkspaceStorageBehaviorData() public static IEnumerable<ConfigurationSelectData<WorkspaceStorageBehavior>> GetWorkspaceStorageBehaviorData()

View File

@ -41,6 +41,11 @@ public sealed class DataApp(Expression<Func<Data, DataApp>>? configSelection = n
/// If and when we should look for updates. /// If and when we should look for updates.
/// </summary> /// </summary>
public UpdateInterval UpdateInterval { get; set; } = ManagedConfiguration.Register(configSelection, n => n.UpdateInterval, UpdateInterval.HOURLY); public UpdateInterval UpdateInterval { get; set; } = ManagedConfiguration.Register(configSelection, n => n.UpdateInterval, UpdateInterval.HOURLY);
/// <summary>
/// How updates should be installed.
/// </summary>
public UpdateBehaviour UpdateBehaviour { get; set; } = ManagedConfiguration.Register(configSelection, n => n.UpdateBehaviour, UpdateBehaviour.MANUAL);
/// <summary> /// <summary>
/// The navigation behavior. /// The navigation behavior.

View File

@ -0,0 +1,7 @@
namespace AIStudio.Settings.DataModel;
public enum UpdateBehaviour
{
MANUAL,
AUTOMATIC,
}

View File

@ -18,6 +18,7 @@ public enum Event
// Update events: // Update events:
USER_SEARCH_FOR_UPDATE, USER_SEARCH_FOR_UPDATE,
UPDATE_AVAILABLE, UPDATE_AVAILABLE,
INSTALL_UPDATE,
// Chat events: // Chat events:
HAS_CHAT_UNSAVED_CHANGES, HAS_CHAT_UNSAVED_CHANGES,

View File

@ -55,6 +55,9 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
// Config: check for updates, and if so, how often? // Config: check for updates, and if so, how often?
ManagedConfiguration.TryProcessConfiguration(x => x.App, x => x.UpdateInterval, this.Id, settingsTable, dryRun); ManagedConfiguration.TryProcessConfiguration(x => x.App, x => x.UpdateInterval, this.Id, settingsTable, dryRun);
// Config: how should updates be installed?
ManagedConfiguration.TryProcessConfiguration(x => x.App, x => x.UpdateBehaviour, this.Id, settingsTable, dryRun);
// Config: allow the user to add providers? // Config: allow the user to add providers?
ManagedConfiguration.TryProcessConfiguration(x => x.App, x => x.AllowUserToAddProvider, this.Id, settingsTable, dryRun); ManagedConfiguration.TryProcessConfiguration(x => x.App, x => x.AllowUserToAddProvider, this.Id, settingsTable, dryRun);

View File

@ -115,7 +115,25 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
var response = await this.rust.CheckForUpdate(); var response = await this.rust.CheckForUpdate();
if (response.UpdateIsAvailable) if (response.UpdateIsAvailable)
{ {
await this.messageBus.SendMessage(null, Event.UPDATE_AVAILABLE, response); if (this.settingsManager.ConfigurationData.App.UpdateBehaviour is UpdateBehaviour.AUTOMATIC)
{
try
{
await this.messageBus.SendMessage<bool>(null, Event.INSTALL_UPDATE);
await this.rust.InstallUpdate();
}
catch (Exception)
{
SNACKBAR!.Add(TB("Failed to install update automatically. Please try again manually."), Severity.Error, config =>
{
config.Icon = Icons.Material.Filled.Error;
config.IconSize = Size.Large;
config.IconColor = Color.Error;
});
}
}
else
await this.messageBus.SendMessage(null, Event.UPDATE_AVAILABLE, response);
} }
else else
{ {