mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-01 11:19:05 +00:00
@@ -1,5 +1,6 @@
|
||||
using DiscordChatExporter.Core.Services;
|
||||
using DiscordChatExporter.Gui.ViewModels.Framework;
|
||||
using Tyrrrz.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
||||
{
|
||||
@@ -25,6 +26,12 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
||||
set => _settingsService.IsTokenPersisted = value;
|
||||
}
|
||||
|
||||
public int ParallelLimit
|
||||
{
|
||||
get => _settingsService.ParallelLimit;
|
||||
set => _settingsService.ParallelLimit = value.Clamp(1, 10);
|
||||
}
|
||||
|
||||
public SettingsViewModel(SettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Models.Exceptions;
|
||||
@@ -260,10 +261,13 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
|
||||
// Export channels
|
||||
var successfulExportCount = 0;
|
||||
for (var i = 0; i < dialog.Channels.Count; i++)
|
||||
using var semaphore = new SemaphoreSlim(_settingsService.ParallelLimit.ClampMin(1));
|
||||
|
||||
await Task.WhenAll(dialog.Channels.Select(async (channel, i) =>
|
||||
{
|
||||
var operation = operations[i];
|
||||
var channel = dialog.Channels[i];
|
||||
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -288,8 +292,9 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
finally
|
||||
{
|
||||
operation.Dispose();
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
// Notify of overall completion
|
||||
if (successfulExportCount > 0)
|
||||
|
||||
@@ -56,6 +56,21 @@
|
||||
IsChecked="{Binding IsTokenPersisted}" />
|
||||
</DockPanel>
|
||||
|
||||
<!-- Parallel limit -->
|
||||
<StackPanel Background="Transparent" ToolTip="How many channels can be exported at the same time">
|
||||
<TextBlock Margin="16,8">
|
||||
<Run Text="Parallel limit:" />
|
||||
<Run Foreground="{DynamicResource PrimaryTextBrush}" Text="{Binding ParallelLimit, Mode=OneWay}" />
|
||||
</TextBlock>
|
||||
<Slider
|
||||
Margin="16,8"
|
||||
IsSnapToTickEnabled="True"
|
||||
Maximum="10"
|
||||
Minimum="1"
|
||||
TickFrequency="1"
|
||||
Value="{Binding ParallelLimit}" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Save button -->
|
||||
<Button
|
||||
Margin="8"
|
||||
|
||||
Reference in New Issue
Block a user