mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-11 17:32:11 +00:00
Removed the snackbar from every place except the layout that renders it
This commit is contained in:
parent
18dc8bf9b8
commit
3eda45df8f
@ -24,10 +24,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
|
||||
|
||||
[Inject]
|
||||
protected IJSRuntime JsRuntime { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
|
||||
[Inject]
|
||||
protected RustService RustService { get; init; } = null!;
|
||||
|
||||
@ -529,7 +526,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
|
||||
|
||||
protected async Task CopyToClipboard()
|
||||
{
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, this.Result2Copy());
|
||||
await this.RustService.CopyText2Clipboard(this.Result2Copy());
|
||||
}
|
||||
|
||||
private ChatThread CreateSendToChatThread()
|
||||
|
||||
@ -795,7 +795,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
|
||||
}
|
||||
|
||||
var luaCode = this.GenerateLuaPolicyExport();
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, luaCode);
|
||||
await this.RustService.CopyText2Clipboard(luaCode);
|
||||
}
|
||||
|
||||
private string GenerateLuaPolicyExport()
|
||||
|
||||
@ -67,7 +67,7 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
|
||||
#if DEBUG
|
||||
AsyncAction = async () => await this.WriteToPluginFile(),
|
||||
#else
|
||||
AsyncAction = async () => await this.RustService.CopyText2Clipboard(this.Snackbar, this.finalLuaCode.ToString()),
|
||||
AsyncAction = async () => await this.RustService.CopyText2Clipboard(this.finalLuaCode.ToString()),
|
||||
#endif
|
||||
DisabledActionParam = () => this.finalLuaCode.Length == 0,
|
||||
},
|
||||
|
||||
@ -280,9 +280,7 @@ public partial class VisualBriefingAssistant
|
||||
if (this.lastBuildDiagnostics is null)
|
||||
return;
|
||||
|
||||
await this.RustService.CopyText2Clipboard(
|
||||
this.Snackbar,
|
||||
this.lastBuildDiagnostics.ToClipboardText());
|
||||
await this.RustService.CopyText2Clipboard(this.lastBuildDiagnostics.ToClipboardText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -57,12 +57,6 @@ public partial class VisualBriefingAssistant : MSGComponentBase
|
||||
[Inject]
|
||||
private IDialogService DialogService { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Defines <c>Snackbar</c> for the visual briefing feature.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
private ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Defines <c>AssistantSessionService</c> for the visual briefing feature.
|
||||
/// </summary>
|
||||
|
||||
@ -38,10 +38,7 @@ public partial class MudCopyClipboardButton : ComponentBase
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Size Size { get; set; } = Size.Small;
|
||||
|
||||
[Inject]
|
||||
private ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
|
||||
[Inject]
|
||||
private RustService RustService { get; init; } = null!;
|
||||
|
||||
@ -58,7 +55,7 @@ public partial class MudCopyClipboardButton : ComponentBase
|
||||
/// </summary>
|
||||
private async Task CopyToClipboard(string textContent)
|
||||
{
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, textContent);
|
||||
await this.RustService.CopyText2Clipboard(textContent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -73,7 +70,7 @@ public partial class MudCopyClipboardButton : ComponentBase
|
||||
{
|
||||
case ContentType.TEXT:
|
||||
var textContent = (ContentText) contentToCopy;
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, textContent.Text);
|
||||
await this.RustService.CopyText2Clipboard(textContent.Text);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@ -74,7 +74,7 @@ public partial class SettingsPanelApp : SettingsPanelBase
|
||||
private async Task GenerateEncryptionSecret()
|
||||
{
|
||||
var secret = EnterpriseEncryption.GenerateSecret();
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, secret);
|
||||
await this.RustService.CopyText2Clipboard(secret);
|
||||
}
|
||||
|
||||
private string GetStartPageHelpText()
|
||||
|
||||
@ -16,6 +16,4 @@ public abstract class SettingsPanelBase : MSGComponentBase
|
||||
[Inject]
|
||||
protected RustService RustService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected ISnackbar Snackbar { get; init; } = null!;
|
||||
}
|
||||
@ -56,6 +56,6 @@ public abstract class SettingsPanelProviderBase : SettingsPanelBase
|
||||
if (string.IsNullOrWhiteSpace(luaCode))
|
||||
return;
|
||||
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, luaCode);
|
||||
await this.RustService.CopyText2Clipboard(luaCode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,9 +23,6 @@ public partial class TextInfoLine : MSGComponentBase
|
||||
|
||||
[Inject]
|
||||
private RustService RustService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
@ -43,5 +40,5 @@ public partial class TextInfoLine : MSGComponentBase
|
||||
|
||||
private string ClipboardTooltip => string.Format(T("Copy {0} to the clipboard"), this.ClipboardTooltipSubject);
|
||||
|
||||
private async Task CopyToClipboard(string content) => await this.RustService.CopyText2Clipboard(this.Snackbar, content);
|
||||
private async Task CopyToClipboard(string content) => await this.RustService.CopyText2Clipboard(content);
|
||||
}
|
||||
@ -26,9 +26,6 @@ public partial class TextInfoLines : MSGComponentBase
|
||||
|
||||
[Inject]
|
||||
private RustService RustService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
@ -46,7 +43,7 @@ public partial class TextInfoLines : MSGComponentBase
|
||||
|
||||
private string ClipboardTooltip => string.Format(T("Copy {0} to the clipboard"), this.ClipboardTooltipSubject);
|
||||
|
||||
private async Task CopyToClipboard(string content) => await this.RustService.CopyText2Clipboard(this.Snackbar, content);
|
||||
private async Task CopyToClipboard(string content) => await this.RustService.CopyText2Clipboard(content);
|
||||
|
||||
private string GetColor()
|
||||
{
|
||||
|
||||
@ -25,9 +25,6 @@ public partial class VoiceRecorder : MSGComponentBase
|
||||
[Inject]
|
||||
private GlobalShortcutService GlobalShortcutService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private VoiceRecordingAvailabilityService VoiceRecordingAvailabilityService { get; init; } = null!;
|
||||
|
||||
@ -448,7 +445,7 @@ public partial class VoiceRecorder : MSGComponentBase
|
||||
}
|
||||
|
||||
// Copy the transcribed text to the clipboard:
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, transcribedText);
|
||||
await this.RustService.CopyText2Clipboard(transcribedText);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@ -12,10 +12,7 @@ public partial class AssistantPluginEditorDialog : MSGComponentBase
|
||||
{
|
||||
[Inject]
|
||||
protected RustService RustService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
|
||||
private const string PLUGIN_FILE_NAME = "plugin.lua";
|
||||
private static readonly ILogger LOGGER = Program.LOGGER_FACTORY.CreateLogger(nameof(AssistantPluginEditorDialog));
|
||||
|
||||
@ -134,7 +131,7 @@ public partial class AssistantPluginEditorDialog : MSGComponentBase
|
||||
|
||||
private void Cancel() => this.MudDialog.Cancel();
|
||||
|
||||
private async Task CopyToClipboard() => await this.RustService.CopyText2Clipboard(this.Snackbar, this.Result2Copy());
|
||||
private async Task CopyToClipboard() => await this.RustService.CopyText2Clipboard(this.Result2Copy());
|
||||
|
||||
private static bool AreSamePath(string left, string right)
|
||||
{
|
||||
|
||||
@ -19,9 +19,6 @@ public abstract class SettingsDialogBase : MSGComponentBase
|
||||
[Inject]
|
||||
protected RustService RustService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
protected ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
protected readonly List<ConfigurationSelectData<string>> AvailableLLMProviders = new();
|
||||
protected readonly List<ConfigurationSelectData<string>> AvailableEmbeddingProviders = new();
|
||||
|
||||
|
||||
@ -172,7 +172,7 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(luaCode))
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, luaCode);
|
||||
await this.RustService.CopyText2Clipboard(luaCode);
|
||||
}
|
||||
|
||||
private async Task CopyPackagedChatTemplateLuaToClipboard(ChatTemplate chatTemplate, string pluginDirectory)
|
||||
@ -187,6 +187,6 @@ public partial class SettingsDialogChatTemplate : SettingsDialogBase
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(luaCode))
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, luaCode);
|
||||
await this.RustService.CopyText2Clipboard(luaCode);
|
||||
}
|
||||
}
|
||||
@ -110,7 +110,7 @@ public partial class SettingsDialogDataSources : SettingsDialogBase
|
||||
{
|
||||
var publicLuaCode = eriDataSource.ExportAsConfigurationSection();
|
||||
if (!string.IsNullOrWhiteSpace(publicLuaCode))
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, publicLuaCode);
|
||||
await this.RustService.CopyText2Clipboard(publicLuaCode);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -179,7 +179,7 @@ public partial class SettingsDialogDataSources : SettingsDialogBase
|
||||
if (string.IsNullOrWhiteSpace(luaCode))
|
||||
return;
|
||||
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, luaCode);
|
||||
await this.RustService.CopyText2Clipboard(luaCode);
|
||||
}
|
||||
|
||||
private async Task EditDataSource(IDataSource dataSource)
|
||||
|
||||
@ -75,7 +75,7 @@ public partial class SettingsDialogProfiles : SettingsDialogBase
|
||||
|
||||
var luaCode = profile.ExportAsConfigurationSection();
|
||||
if (!string.IsNullOrWhiteSpace(luaCode))
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, luaCode);
|
||||
await this.RustService.CopyText2Clipboard(luaCode);
|
||||
}
|
||||
|
||||
private async Task DeleteProfile(Profile profile)
|
||||
|
||||
@ -118,7 +118,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
|
||||
]);
|
||||
|
||||
// Set the snackbar for the update service:
|
||||
UpdateService.SetBlazorDependencies(this.Snackbar);
|
||||
UpdateService.MarkBlazorReady();
|
||||
TemporaryChatService.Initialize();
|
||||
|
||||
// Should the navigation bar be open by default?
|
||||
|
||||
@ -26,9 +26,6 @@ public partial class Information : MSGComponentBase
|
||||
[Inject]
|
||||
private IDialogService DialogService { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private ISnackbar Snackbar { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private UpdatePolicy UpdatePolicy { get; init; } = null!;
|
||||
|
||||
@ -488,12 +485,12 @@ public partial class Information : MSGComponentBase
|
||||
|
||||
private async Task CopyStartupLogPath()
|
||||
{
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, this.logPaths.LogStartupPath);
|
||||
await this.RustService.CopyText2Clipboard(this.logPaths.LogStartupPath);
|
||||
}
|
||||
|
||||
private async Task CopyAppLogPath()
|
||||
{
|
||||
await this.RustService.CopyText2Clipboard(this.Snackbar, this.logPaths.LogAppPath);
|
||||
await this.RustService.CopyText2Clipboard(this.logPaths.LogAppPath);
|
||||
}
|
||||
|
||||
private const string LICENSE = """
|
||||
|
||||
@ -6,15 +6,13 @@ namespace AIStudio.Tools.Services;
|
||||
/// Wire up the clipboard service to copy Markdown to the clipboard.
|
||||
/// We use our own Rust-based clipboard service for this.
|
||||
/// </summary>
|
||||
public sealed class MarkdownClipboardService(RustService rust, ISnackbar snackbar) : IMudMarkdownClipboardService
|
||||
public sealed class MarkdownClipboardService(RustService rust) : IMudMarkdownClipboardService
|
||||
{
|
||||
private ISnackbar Snackbar { get; } = snackbar;
|
||||
|
||||
private RustService Rust { get; } = rust;
|
||||
|
||||
/// <summary>
|
||||
/// Gets called when the user wants to copy the Markdown to the clipboard.
|
||||
/// </summary>
|
||||
/// <param name="text">The Markdown text to copy.</param>
|
||||
public async ValueTask CopyToClipboardAsync(string text) => await this.Rust.CopyText2Clipboard(this.Snackbar, text);
|
||||
public async ValueTask CopyToClipboardAsync(string text) => await this.Rust.CopyText2Clipboard(text);
|
||||
}
|
||||
@ -7,13 +7,16 @@ public sealed partial class RustService
|
||||
/// <summary>
|
||||
/// Tries to copy the given text to the clipboard.
|
||||
/// </summary>
|
||||
/// <param name="snackbar">The snackbar to show the result.</param>
|
||||
/// <remarks>
|
||||
/// The outcome is reported through the message bus. Callers used to hand in their snackbar, which
|
||||
/// was the reason most components injected one at all, and it meant this notification was styled
|
||||
/// here instead of together with every other notification of the app.
|
||||
/// </remarks>
|
||||
/// <param name="text">The text to copy to the clipboard.</param>
|
||||
public async Task CopyText2Clipboard(ISnackbar snackbar, string text)
|
||||
public async Task CopyText2Clipboard(string text)
|
||||
{
|
||||
var message = TB("Successfully copied the text to your clipboard");
|
||||
var iconColor = Color.Error;
|
||||
var severity = Severity.Error;
|
||||
var succeeded = false;
|
||||
try
|
||||
{
|
||||
var encryptedText = await text.Encrypt(this.encryptor!);
|
||||
@ -32,19 +35,16 @@ public sealed partial class RustService
|
||||
message = TB("Failed to copy the text to your clipboard.");
|
||||
return;
|
||||
}
|
||||
|
||||
iconColor = Color.Success;
|
||||
severity = Severity.Success;
|
||||
|
||||
succeeded = true;
|
||||
this.logger!.LogDebug("Successfully copied the text to the clipboard.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
snackbar.Add(message, severity, config =>
|
||||
{
|
||||
config.Icon = Icons.Material.Filled.ContentCopy;
|
||||
config.IconSize = Size.Large;
|
||||
config.IconColor = iconColor;
|
||||
});
|
||||
if (succeeded)
|
||||
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.ContentCopy, message));
|
||||
else
|
||||
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.ContentCopy, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,8 +11,7 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
|
||||
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(UpdateService).Namespace, nameof(UpdateService));
|
||||
|
||||
private static bool IS_INITIALIZED;
|
||||
private static ISnackbar? SNACKBAR;
|
||||
|
||||
|
||||
private readonly SettingsManager settingsManager;
|
||||
private readonly MessageBus messageBus;
|
||||
private readonly RustService rust;
|
||||
@ -101,12 +100,7 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
|
||||
|
||||
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;
|
||||
});
|
||||
await this.messageBus.SendError(new(Icons.Material.Filled.Error, TB("Failed to check for updates. Please try again later.")));
|
||||
}
|
||||
|
||||
return;
|
||||
@ -133,12 +127,7 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
|
||||
}
|
||||
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;
|
||||
});
|
||||
await this.messageBus.SendError(new(Icons.Material.Filled.Error, TB("Failed to install update automatically. Please try again manually.")));
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -148,12 +137,7 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
|
||||
{
|
||||
if (notifyUserWhenNoUpdate)
|
||||
{
|
||||
SNACKBAR!.Add(TB("No update found."), Severity.Normal, config =>
|
||||
{
|
||||
config.Icon = Icons.Material.Filled.Update;
|
||||
config.IconSize = Size.Large;
|
||||
config.IconColor = Color.Primary;
|
||||
});
|
||||
await this.messageBus.SendInfo(new(Icons.Material.Filled.Update, TB("No update found.")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -168,9 +152,8 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
|
||||
_ => Timeout.InfiniteTimeSpan
|
||||
};
|
||||
|
||||
public static void SetBlazorDependencies(ISnackbar snackbar)
|
||||
{
|
||||
SNACKBAR = snackbar;
|
||||
IS_INITIALIZED = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Signals that the Blazor UI is ready, so queued update notifications can be shown.
|
||||
/// </summary>
|
||||
public static void MarkBlazorReady() => IS_INITIALIZED = true;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user