mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-11 05:42:06 +00:00
Use CSharpier
This commit is contained in:
@@ -52,7 +52,8 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
IViewModelFactory viewModelFactory,
|
||||
IEventAggregator eventAggregator,
|
||||
DialogManager dialogManager,
|
||||
SettingsService settingsService)
|
||||
SettingsService settingsService
|
||||
)
|
||||
{
|
||||
_viewModelFactory = viewModelFactory;
|
||||
_eventAggregator = eventAggregator;
|
||||
@@ -61,10 +62,7 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
|
||||
_progressMuxer = Progress.CreateMuxer().WithAutoReset();
|
||||
|
||||
this.Bind(
|
||||
o => o.IsBusy,
|
||||
(_, _) => NotifyOfPropertyChange(() => IsProgressIndeterminate)
|
||||
);
|
||||
this.Bind(o => o.IsBusy, (_, _) => NotifyOfPropertyChange(() => IsProgressIndeterminate));
|
||||
|
||||
Progress.Bind(
|
||||
o => o.Current,
|
||||
@@ -125,9 +123,7 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
}
|
||||
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
|
||||
{
|
||||
_eventAggregator.Publish(
|
||||
new NotificationMessage(ex.Message.TrimEnd('.'))
|
||||
);
|
||||
_eventAggregator.Publish(new NotificationMessage(ex.Message.TrimEnd('.')));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -145,7 +141,8 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanPullChannelsAsync => !IsBusy && _discord is not null && SelectedGuild is not null;
|
||||
public bool CanPullChannelsAsync =>
|
||||
!IsBusy && _discord is not null && SelectedGuild is not null;
|
||||
|
||||
public async ValueTask PullChannelsAsync()
|
||||
{
|
||||
@@ -174,9 +171,12 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
// Threads
|
||||
if (_settingsService.ShouldShowThreads)
|
||||
{
|
||||
await foreach (var thread in _discord.GetGuildThreadsAsync(
|
||||
SelectedGuild.Id,
|
||||
_settingsService.ShouldShowArchivedThreads))
|
||||
await foreach (
|
||||
var thread in _discord.GetGuildThreadsAsync(
|
||||
SelectedGuild.Id,
|
||||
_settingsService.ShouldShowArchivedThreads
|
||||
)
|
||||
)
|
||||
{
|
||||
channels.Add(thread);
|
||||
}
|
||||
@@ -187,9 +187,7 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
}
|
||||
catch (DiscordChatExporterException ex) when (!ex.IsFatal)
|
||||
{
|
||||
_eventAggregator.Publish(
|
||||
new NotificationMessage(ex.Message.TrimEnd('.'))
|
||||
);
|
||||
_eventAggregator.Publish(new NotificationMessage(ex.Message.TrimEnd('.')));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -208,10 +206,10 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
}
|
||||
|
||||
public bool CanExportAsync =>
|
||||
!IsBusy &&
|
||||
_discord is not null &&
|
||||
SelectedGuild is not null &&
|
||||
SelectedChannels?.Any() is true;
|
||||
!IsBusy
|
||||
&& _discord is not null
|
||||
&& SelectedGuild is not null
|
||||
&& SelectedChannels?.Any() is true;
|
||||
|
||||
public async ValueTask ExportAsync()
|
||||
{
|
||||
@@ -219,20 +217,26 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
|
||||
try
|
||||
{
|
||||
if (_discord is null || SelectedGuild is null || SelectedChannels is null || !SelectedChannels.Any())
|
||||
if (
|
||||
_discord is null
|
||||
|| SelectedGuild is null
|
||||
|| SelectedChannels is null
|
||||
|| !SelectedChannels.Any()
|
||||
)
|
||||
return;
|
||||
|
||||
var dialog = _viewModelFactory.CreateExportSetupViewModel(SelectedGuild, SelectedChannels);
|
||||
var dialog = _viewModelFactory.CreateExportSetupViewModel(
|
||||
SelectedGuild,
|
||||
SelectedChannels
|
||||
);
|
||||
if (await _dialogManager.ShowDialogAsync(dialog) != true)
|
||||
return;
|
||||
|
||||
var exporter = new ChannelExporter(_discord);
|
||||
|
||||
var channelProgressPairs = dialog.Channels!.Select(c => new
|
||||
{
|
||||
Channel = c,
|
||||
Progress = _progressMuxer.CreateInput()
|
||||
}).ToArray();
|
||||
var channelProgressPairs = dialog.Channels!
|
||||
.Select(c => new { Channel = c, Progress = _progressMuxer.CreateInput() })
|
||||
.ToArray();
|
||||
|
||||
var successfulExportCount = 0;
|
||||
|
||||
@@ -286,7 +290,9 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
if (successfulExportCount > 0)
|
||||
{
|
||||
_eventAggregator.Publish(
|
||||
new NotificationMessage($"Successfully exported {successfulExportCount} channel(s)")
|
||||
new NotificationMessage(
|
||||
$"Successfully exported {successfulExportCount} channel(s)"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -305,9 +311,8 @@ public class DashboardViewModel : PropertyChangedBase
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenDiscord() =>
|
||||
ProcessEx.StartShellExecute("https://discord.com/app");
|
||||
public void OpenDiscord() => ProcessEx.StartShellExecute("https://discord.com/app");
|
||||
|
||||
public void OpenDiscordDeveloperPortal() =>
|
||||
ProcessEx.StartShellExecute("https://discord.com/developers/applications");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,15 +49,17 @@ public class ExportSetupViewModel : DialogScreen
|
||||
|
||||
public string? PartitionLimitValue { get; set; }
|
||||
|
||||
public PartitionLimit PartitionLimit => !string.IsNullOrWhiteSpace(PartitionLimitValue)
|
||||
? PartitionLimit.Parse(PartitionLimitValue)
|
||||
: PartitionLimit.Null;
|
||||
public PartitionLimit PartitionLimit =>
|
||||
!string.IsNullOrWhiteSpace(PartitionLimitValue)
|
||||
? PartitionLimit.Parse(PartitionLimitValue)
|
||||
: PartitionLimit.Null;
|
||||
|
||||
public string? MessageFilterValue { get; set; }
|
||||
|
||||
public MessageFilter MessageFilter => !string.IsNullOrWhiteSpace(MessageFilterValue)
|
||||
? MessageFilter.Parse(MessageFilterValue)
|
||||
: MessageFilter.Null;
|
||||
public MessageFilter MessageFilter =>
|
||||
!string.IsNullOrWhiteSpace(MessageFilterValue)
|
||||
? MessageFilter.Parse(MessageFilterValue)
|
||||
: MessageFilter.Null;
|
||||
|
||||
public bool ShouldFormatMarkdown { get; set; }
|
||||
|
||||
@@ -86,13 +88,13 @@ public class ExportSetupViewModel : DialogScreen
|
||||
// Show the "advanced options" section by default if any
|
||||
// of the advanced options are set to non-default values.
|
||||
IsAdvancedSectionDisplayed =
|
||||
After is not null ||
|
||||
Before is not null ||
|
||||
!string.IsNullOrWhiteSpace(PartitionLimitValue) ||
|
||||
!string.IsNullOrWhiteSpace(MessageFilterValue) ||
|
||||
ShouldDownloadAssets ||
|
||||
ShouldReuseAssets ||
|
||||
!string.IsNullOrWhiteSpace(AssetsDirPath);
|
||||
After is not null
|
||||
|| Before is not null
|
||||
|| !string.IsNullOrWhiteSpace(PartitionLimitValue)
|
||||
|| !string.IsNullOrWhiteSpace(MessageFilterValue)
|
||||
|| ShouldDownloadAssets
|
||||
|| ShouldReuseAssets
|
||||
|| !string.IsNullOrWhiteSpace(AssetsDirPath);
|
||||
}
|
||||
|
||||
public void ToggleAdvancedSection() => IsAdvancedSectionDisplayed = !IsAdvancedSectionDisplayed;
|
||||
@@ -161,7 +163,8 @@ public static class ExportSetupViewModelExtensions
|
||||
public static ExportSetupViewModel CreateExportSetupViewModel(
|
||||
this IViewModelFactory factory,
|
||||
Guild guild,
|
||||
IReadOnlyList<Channel> channels)
|
||||
IReadOnlyList<Channel> channels
|
||||
)
|
||||
{
|
||||
var viewModel = factory.CreateExportSetupViewModel();
|
||||
|
||||
@@ -170,4 +173,4 @@ public static class ExportSetupViewModelExtensions
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,7 @@ public class MessageBoxViewModel : DialogScreen
|
||||
|
||||
public string? CancelButtonText { get; set; }
|
||||
|
||||
public int ButtonsCount =>
|
||||
(IsOkButtonVisible ? 1 : 0) +
|
||||
(IsCancelButtonVisible ? 1 : 0);
|
||||
public int ButtonsCount => (IsOkButtonVisible ? 1 : 0) + (IsCancelButtonVisible ? 1 : 0);
|
||||
}
|
||||
|
||||
public static class MessageBoxViewModelExtensions
|
||||
@@ -28,7 +26,8 @@ public static class MessageBoxViewModelExtensions
|
||||
string title,
|
||||
string message,
|
||||
string? okButtonText,
|
||||
string? cancelButtonText)
|
||||
string? cancelButtonText
|
||||
)
|
||||
{
|
||||
var viewModel = factory.CreateMessageBoxViewModel();
|
||||
|
||||
@@ -45,6 +44,6 @@ public static class MessageBoxViewModelExtensions
|
||||
public static MessageBoxViewModel CreateMessageBoxViewModel(
|
||||
this IViewModelFactory factory,
|
||||
string title,
|
||||
string message) =>
|
||||
factory.CreateMessageBoxViewModel(title, message, "CLOSE", null);
|
||||
}
|
||||
string message
|
||||
) => factory.CreateMessageBoxViewModel(title, message, "CLOSE", null);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,5 @@ public class SettingsViewModel : DialogScreen
|
||||
set => _settingsService.ParallelLimit = Math.Clamp(value, 1, 10);
|
||||
}
|
||||
|
||||
public SettingsViewModel(SettingsService settingsService) =>
|
||||
_settingsService = settingsService;
|
||||
}
|
||||
public SettingsViewModel(SettingsService settingsService) => _settingsService = settingsService;
|
||||
}
|
||||
|
||||
@@ -68,10 +68,7 @@ public class DialogManager : IDisposable
|
||||
|
||||
public string? PromptDirectoryPath(string defaultDirPath = "")
|
||||
{
|
||||
var dialog = new VistaFolderBrowserDialog
|
||||
{
|
||||
SelectedPath = defaultDirPath
|
||||
};
|
||||
var dialog = new VistaFolderBrowserDialog { SelectedPath = defaultDirPath };
|
||||
|
||||
return dialog.ShowDialog() == true ? dialog.SelectedPath : null;
|
||||
}
|
||||
@@ -80,4 +77,4 @@ public class DialogManager : IDisposable
|
||||
{
|
||||
_dialogLock.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,4 @@ public abstract class DialogScreen<T> : PropertyChangedBase
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class DialogScreen : DialogScreen<bool?>
|
||||
{
|
||||
}
|
||||
public abstract class DialogScreen : DialogScreen<bool?> { }
|
||||
|
||||
@@ -7,10 +7,10 @@ namespace DiscordChatExporter.Gui.ViewModels.Framework;
|
||||
public interface IViewModelFactory
|
||||
{
|
||||
DashboardViewModel CreateDashboardViewModel();
|
||||
|
||||
|
||||
ExportSetupViewModel CreateExportSetupViewModel();
|
||||
|
||||
MessageBoxViewModel CreateMessageBoxViewModel();
|
||||
|
||||
SettingsViewModel CreateSettingsViewModel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace DiscordChatExporter.Gui.ViewModels.Messages;
|
||||
|
||||
public record NotificationMessage(string Text);
|
||||
public record NotificationMessage(string Text);
|
||||
|
||||
@@ -27,7 +27,8 @@ public class RootViewModel : Screen, IHandle<NotificationMessage>, IDisposable
|
||||
IEventAggregator eventAggregator,
|
||||
DialogManager dialogManager,
|
||||
SettingsService settingsService,
|
||||
UpdateService updateService)
|
||||
UpdateService updateService
|
||||
)
|
||||
{
|
||||
_viewModelFactory = viewModelFactory;
|
||||
_dialogManager = dialogManager;
|
||||
@@ -78,7 +79,8 @@ public class RootViewModel : Screen, IHandle<NotificationMessage>, IDisposable
|
||||
|
||||
Notifications.Enqueue(
|
||||
"Update has been downloaded and will be installed when you exit",
|
||||
"INSTALL NOW", () =>
|
||||
"INSTALL NOW",
|
||||
() =>
|
||||
{
|
||||
_updateService.FinalizeUpdate(true);
|
||||
RequestClose();
|
||||
@@ -115,11 +117,15 @@ public class RootViewModel : Screen, IHandle<NotificationMessage>, IDisposable
|
||||
}
|
||||
|
||||
// App has just been updated, display the changelog
|
||||
if (_settingsService.LastAppVersion is not null && _settingsService.LastAppVersion != App.Version)
|
||||
if (
|
||||
_settingsService.LastAppVersion is not null
|
||||
&& _settingsService.LastAppVersion != App.Version
|
||||
)
|
||||
{
|
||||
Notifications.Enqueue(
|
||||
$"Successfully updated to {App.Name} v{App.VersionString}",
|
||||
"CHANGELOG", () => ProcessEx.StartShellExecute(App.ChangelogUrl)
|
||||
"CHANGELOG",
|
||||
() => ProcessEx.StartShellExecute(App.ChangelogUrl)
|
||||
);
|
||||
|
||||
_settingsService.LastAppVersion = App.Version;
|
||||
@@ -138,4 +144,4 @@ public class RootViewModel : Screen, IHandle<NotificationMessage>, IDisposable
|
||||
public void Handle(NotificationMessage message) => Notifications.Enqueue(message.Text);
|
||||
|
||||
public void Dispose() => Notifications.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user