mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-06-05 23:28:33 +00:00
Refactor busy state and progress reporting
This commit is contained in:
@@ -121,6 +121,9 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
|
||||
public async void PopulateGuildsAndChannels()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Set busy state and indeterminate progress
|
||||
IsEnabled = false;
|
||||
Progress = -1;
|
||||
|
||||
@@ -135,11 +138,9 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
// Save token
|
||||
_settingsService.LastToken = token;
|
||||
|
||||
// Clear existing
|
||||
// Clear guild to channel map
|
||||
_guildChannelsMap.Clear();
|
||||
|
||||
try
|
||||
{
|
||||
// Get DM channels
|
||||
{
|
||||
var channels = await _dataService.GetDirectMessageChannelsAsync(token);
|
||||
@@ -158,6 +159,12 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
// Update available guilds
|
||||
AvailableGuilds = _guildChannelsMap.Keys.ToArray();
|
||||
|
||||
// Select the first guild
|
||||
SelectedGuild = AvailableGuilds.FirstOrDefault();
|
||||
}
|
||||
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
@@ -167,18 +174,21 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
{
|
||||
Notifications.Enqueue("Forbidden – account may be locked by 2FA");
|
||||
}
|
||||
|
||||
AvailableGuilds = _guildChannelsMap.Keys.ToArray();
|
||||
SelectedGuild = AvailableGuilds.FirstOrDefault();
|
||||
|
||||
finally
|
||||
{
|
||||
// Reset busy state and progress
|
||||
Progress = 0;
|
||||
IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanExportChannel => IsEnabled;
|
||||
|
||||
public async void ExportChannel(Channel channel)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Set busy state and indeterminate progress
|
||||
IsEnabled = false;
|
||||
Progress = -1;
|
||||
|
||||
@@ -190,12 +200,10 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
dialog.Guild = SelectedGuild;
|
||||
dialog.Channel = channel;
|
||||
|
||||
// Show dialog
|
||||
if (await _dialogManager.ShowDialogAsync(dialog) == true)
|
||||
{
|
||||
// Export
|
||||
try
|
||||
{
|
||||
// Show dialog, if canceled - return
|
||||
if (await _dialogManager.ShowDialogAsync(dialog) != true)
|
||||
return;
|
||||
|
||||
// Create progress handler
|
||||
var progressHandler = new Progress<double>(p => Progress = p);
|
||||
|
||||
@@ -218,10 +226,12 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
{
|
||||
Notifications.Enqueue("This channel doesn't exist");
|
||||
}
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
// Reset busy state and progress
|
||||
Progress = 0;
|
||||
IsEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user