namespace AIStudio.Tools; /// /// Shows the notifications of file exports in one window, and keeps a late notification that an export /// runs from appearing after its end. /// /// /// FileExportFeedback sends its notifications in the right order, but they may take effect in another /// one. The notification that an export runs comes late, from a timer, and waits in the queue of the /// renderer. The end of an export usually comes from a component, on the thread of the renderer, and /// takes effect right away: it overtakes the waiting notification, which would then appear after the /// end and stay until the user closes it. So we remember which exports ended and drop what comes late. ///

/// One key stays per export which ended, for as long as the window lives. That is a few bytes per /// file the user saved, which is not worth a cleanup that could drop a key too early. ///
/// The notifications of the window. public sealed class FileExportNotifications(ISnackbar snackbar) { private readonly HashSet finishedExports = []; public void ShowRunning(DataFileExportRunningMessage message) { if (this.finishedExports.Contains(message.Key)) return; message.Show(snackbar); } /// The notification of the success. /// Whether the notification closes after a few seconds, as the user chose. public void ShowSuccess(DataFileExportSuccessMessage message, bool closesAutomatically) { this.finishedExports.Add(message.Key); message.Show(snackbar, closesAutomatically); } public void HideRunning(DataFileExportRunningMessage message) { this.finishedExports.Add(message.Key); message.Hide(snackbar); } }