mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-14 15:53:30 -07:00
ExportService is pseudo async now
This commit is contained in:
parent
b7979d6d1f
commit
d8db4fca90
|
|
@ -3,6 +3,7 @@ using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Resources;
|
using System.Resources;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using DiscordChatExporter.Models;
|
using DiscordChatExporter.Models;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
using Tyrrrz.Extensions;
|
using Tyrrrz.Extensions;
|
||||||
|
|
@ -18,7 +19,9 @@ namespace DiscordChatExporter.Services
|
||||||
_settingsService = settingsService;
|
_settingsService = settingsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Export(string filePath, ChannelChatLog log, Theme theme)
|
public Task ExportAsync(string filePath, ChannelChatLog log, Theme theme)
|
||||||
|
{
|
||||||
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
var doc = GetTemplate();
|
var doc = GetTemplate();
|
||||||
var style = GetStyle(theme);
|
var style = GetStyle(theme);
|
||||||
|
|
@ -53,14 +56,16 @@ namespace DiscordChatExporter.Services
|
||||||
var messageHtml = logHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg\"></div>"));
|
var messageHtml = logHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg\"></div>"));
|
||||||
|
|
||||||
// Left
|
// Left
|
||||||
var messageLeftHtml = messageHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg-left\"></div>"));
|
var messageLeftHtml =
|
||||||
|
messageHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg-left\"></div>"));
|
||||||
|
|
||||||
// Avatar
|
// Avatar
|
||||||
messageLeftHtml.AppendChild(
|
messageLeftHtml.AppendChild(
|
||||||
HtmlNode.CreateNode($"<img class=\"msg-avatar\" src=\"{messageGroup.Author.AvatarUrl}\" />"));
|
HtmlNode.CreateNode($"<img class=\"msg-avatar\" src=\"{messageGroup.Author.AvatarUrl}\" />"));
|
||||||
|
|
||||||
// Right
|
// Right
|
||||||
var messageRightHtml = messageHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg-right\"></div>"));
|
var messageRightHtml =
|
||||||
|
messageHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg-right\"></div>"));
|
||||||
|
|
||||||
// Author
|
// Author
|
||||||
var authorName = HtmlDocument.HtmlEncode(messageGroup.Author.Name);
|
var authorName = HtmlDocument.HtmlEncode(messageGroup.Author.Name);
|
||||||
|
|
@ -116,6 +121,7 @@ namespace DiscordChatExporter.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.Save(filePath);
|
doc.Save(filePath);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
using DiscordChatExporter.Models;
|
using System.Threading.Tasks;
|
||||||
|
using DiscordChatExporter.Models;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Services
|
namespace DiscordChatExporter.Services
|
||||||
{
|
{
|
||||||
public interface IExportService
|
public interface IExportService
|
||||||
{
|
{
|
||||||
void Export(string filePath, ChannelChatLog log, Theme theme);
|
Task ExportAsync(string filePath, ChannelChatLog log, Theme theme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +176,7 @@ namespace DiscordChatExporter.ViewModels
|
||||||
var chatLog = new ChannelChatLog(SelectedGuild, channel, messageGroups);
|
var chatLog = new ChannelChatLog(SelectedGuild, channel, messageGroups);
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
_exportService.Export(sfd.FileName, chatLog, _settingsService.Theme);
|
await _exportService.ExportAsync(sfd.FileName, chatLog, _settingsService.Theme);
|
||||||
|
|
||||||
// Show dialog
|
// Show dialog
|
||||||
MessengerInstance.Send(new ShowExportDoneMessage(sfd.FileName));
|
MessengerInstance.Send(new ShowExportDoneMessage(sfd.FileName));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue