From 8ac8c16db3bb273a239a1f8f866cb5dc9d1dd9b4 Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Mon, 2 Oct 2017 19:16:06 +0300 Subject: [PATCH] Disable whole UI when busy --- DiscordChatExporter/Services/ExportService.cs | 10 +++------- DiscordChatExporter/Services/MessageGroupService.cs | 3 +-- DiscordChatExporter/Views/MainWindow.ammy | 5 +++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/DiscordChatExporter/Services/ExportService.cs b/DiscordChatExporter/Services/ExportService.cs index eb75abc..1810a13 100644 --- a/DiscordChatExporter/Services/ExportService.cs +++ b/DiscordChatExporter/Services/ExportService.cs @@ -20,8 +20,6 @@ namespace DiscordChatExporter.Services private async Task ExportAsTextAsync(string filePath, ChannelChatLog log) { - var dateFormat = _settingsService.DateFormat; - using (var writer = new StreamWriter(filePath, false, Encoding.UTF8, 128 * 1024)) { // Generation info @@ -39,7 +37,7 @@ namespace DiscordChatExporter.Services // Chat log foreach (var group in log.MessageGroups) { - var timeStampFormatted = group.TimeStamp.ToString(dateFormat); + var timeStampFormatted = group.TimeStamp.ToString(_settingsService.DateFormat); await writer.WriteLineAsync($"{group.Author} [{timeStampFormatted}]"); // Messages @@ -66,8 +64,6 @@ namespace DiscordChatExporter.Services private async Task ExportAsHtmlAsync(string filePath, ChannelChatLog log, string css) { - var dateFormat = _settingsService.DateFormat; - using (var writer = new StreamWriter(filePath, false, Encoding.UTF8, 128 * 1024)) { // Generation info @@ -113,7 +109,7 @@ namespace DiscordChatExporter.Services await writer.WriteAsync($""); await writer.WriteAsync(HtmlEncode(group.Author.Name)); await writer.WriteLineAsync(""); - var timeStampFormatted = HtmlEncode(group.TimeStamp.ToString(dateFormat)); + var timeStampFormatted = HtmlEncode(group.TimeStamp.ToString(_settingsService.DateFormat)); await writer.WriteLineAsync($"{timeStampFormatted}"); // Messages @@ -130,7 +126,7 @@ namespace DiscordChatExporter.Services if (message.EditedTimeStamp != null) { var editedTimeStampFormatted = - HtmlEncode(message.EditedTimeStamp.Value.ToString(dateFormat)); + HtmlEncode(message.EditedTimeStamp.Value.ToString(_settingsService.DateFormat)); await writer.WriteAsync( $"(edited)"); } diff --git a/DiscordChatExporter/Services/MessageGroupService.cs b/DiscordChatExporter/Services/MessageGroupService.cs index bb5218c..7559f01 100644 --- a/DiscordChatExporter/Services/MessageGroupService.cs +++ b/DiscordChatExporter/Services/MessageGroupService.cs @@ -15,7 +15,6 @@ namespace DiscordChatExporter.Services public IReadOnlyList GroupMessages(IReadOnlyList messages) { - var groupLimit = _settingsService.MessageGroupLimit; var result = new List(); // Group adjacent messages by timestamp and author @@ -31,7 +30,7 @@ namespace DiscordChatExporter.Services message.Author.Id != groupFirst.Author.Id || (message.TimeStamp - groupFirst.TimeStamp).TotalHours > 1 || message.TimeStamp.Hour != groupFirst.TimeStamp.Hour || - groupBuffer.Count >= groupLimit + groupBuffer.Count >= _settingsService.MessageGroupLimit ); // If condition is true - flush buffer diff --git a/DiscordChatExporter/Views/MainWindow.ammy b/DiscordChatExporter/Views/MainWindow.ammy index f2ae3af..3e7fd9c 100644 --- a/DiscordChatExporter/Views/MainWindow.ammy +++ b/DiscordChatExporter/Views/MainWindow.ammy @@ -20,6 +20,9 @@ Window "DiscordChatExporter.Views.MainWindow" { DialogHost { DockPanel { + IsEnabled: bind IsBusy + convert (bool b) => b ? false : true + // Toolbar Border { DockPanel.Dock: Top @@ -100,8 +103,6 @@ Window "DiscordChatExporter.Views.MainWindow" { Grid { DockPanel { Background: resource dyn "MaterialDesignCardBackground" - IsEnabled: bind IsBusy - convert (bool b) => b ? false : true Visibility: bind IsDataAvailable convert (bool b) => b ? Visibility.Visible : Visibility.Hidden