forked from sim0n00ps/OF-DL
Display a warning if a download is attempted without enabling both media types and sources
This commit is contained in:
parent
2a727c7121
commit
3749cd1568
@ -354,6 +354,15 @@ public partial class MainWindowViewModel(
|
||||
|
||||
[ObservableProperty] private string _missingCdmWarningMessage = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(OpenSinglePostOrMessageModalCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(SubmitSinglePostOrMessageCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(DownloadSelectedCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(DownloadPurchasedTabCommand))]
|
||||
private bool _isDownloadSelectionWarningModalOpen;
|
||||
|
||||
[ObservableProperty] private string _downloadSelectionWarningMessage = string.Empty;
|
||||
|
||||
[ObservableProperty] [NotifyCanExecuteChangedFor(nameof(SubmitSinglePostOrMessageCommand))]
|
||||
private string _singlePostOrMessageUrl = string.Empty;
|
||||
|
||||
@ -485,6 +494,7 @@ public partial class MainWindowViewModel(
|
||||
|
||||
private bool _isUpdatingAllUsersSelected;
|
||||
private TaskCompletionSource<bool>? _missingCdmWarningCompletionSource;
|
||||
private TaskCompletionSource<bool>? _downloadSelectionWarningCompletionSource;
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
@ -880,6 +890,28 @@ public partial class MainWindowViewModel(
|
||||
_missingCdmWarningCompletionSource?.TrySetResult(false);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ConfirmDownloadSelectionWarning()
|
||||
{
|
||||
IsDownloadSelectionWarningModalOpen = false;
|
||||
_downloadSelectionWarningCompletionSource?.TrySetResult(true);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CancelDownloadSelectionWarning()
|
||||
{
|
||||
IsDownloadSelectionWarningModalOpen = false;
|
||||
_downloadSelectionWarningCompletionSource?.TrySetResult(false);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenConfigurationFromDownloadSelectionWarning()
|
||||
{
|
||||
IsDownloadSelectionWarningModalOpen = false;
|
||||
_downloadSelectionWarningCompletionSource?.TrySetResult(false);
|
||||
EditConfig();
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanStopWork))]
|
||||
private void StopWork()
|
||||
{
|
||||
@ -904,6 +936,11 @@ public partial class MainWindowViewModel(
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await EnsureDownloadSelectionWarningConfirmedAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await EnsureMissingCdmWarningConfirmedAsync())
|
||||
{
|
||||
return;
|
||||
@ -993,23 +1030,27 @@ public partial class MainWindowViewModel(
|
||||
private bool CanDownloadSelected() =>
|
||||
CurrentScreen == AppScreen.UserSelection &&
|
||||
AvailableUsers.Any(user => user.IsSelected) &&
|
||||
!IsDownloadSelectionWarningModalOpen &&
|
||||
!IsMissingCdmWarningModalOpen &&
|
||||
!IsDownloading;
|
||||
|
||||
private bool CanDownloadPurchasedTab() =>
|
||||
CurrentScreen == AppScreen.UserSelection &&
|
||||
_allUsers.Count > 0 &&
|
||||
!IsDownloadSelectionWarningModalOpen &&
|
||||
!IsMissingCdmWarningModalOpen &&
|
||||
!IsDownloading;
|
||||
|
||||
private bool CanOpenSinglePostOrMessageModal() =>
|
||||
CurrentScreen == AppScreen.UserSelection &&
|
||||
!IsDownloading &&
|
||||
!IsDownloadSelectionWarningModalOpen &&
|
||||
!IsMissingCdmWarningModalOpen &&
|
||||
!IsSinglePostOrMessageModalOpen;
|
||||
|
||||
private bool CanSubmitSinglePostOrMessage() =>
|
||||
IsSinglePostOrMessageModalOpen &&
|
||||
!IsDownloadSelectionWarningModalOpen &&
|
||||
!IsMissingCdmWarningModalOpen &&
|
||||
!IsDownloading &&
|
||||
!string.IsNullOrWhiteSpace(SinglePostOrMessageUrl);
|
||||
@ -1337,6 +1378,47 @@ public partial class MainWindowViewModel(
|
||||
return confirmed;
|
||||
}
|
||||
|
||||
private async Task<bool> EnsureDownloadSelectionWarningConfirmedAsync()
|
||||
{
|
||||
bool hasEnabledMediaType = configService.CurrentConfig.DownloadVideos ||
|
||||
configService.CurrentConfig.DownloadImages ||
|
||||
configService.CurrentConfig.DownloadAudios;
|
||||
bool hasEnabledSource = configService.CurrentConfig.DownloadPosts ||
|
||||
configService.CurrentConfig.DownloadPaidPosts ||
|
||||
configService.CurrentConfig.DownloadMessages ||
|
||||
configService.CurrentConfig.DownloadPaidMessages ||
|
||||
configService.CurrentConfig.DownloadArchived ||
|
||||
configService.CurrentConfig.DownloadStreams ||
|
||||
configService.CurrentConfig.DownloadStories ||
|
||||
configService.CurrentConfig.DownloadHighlights ||
|
||||
configService.CurrentConfig.DownloadAvatarHeaderPhoto;
|
||||
if (hasEnabledMediaType && hasEnabledSource)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
DownloadSelectionWarningMessage =
|
||||
"No files will be downloaded unless at least one media type and at least one source are enabled in \"Download Media Types\" on the Configuration page.\n\n" +
|
||||
"Without enabling these options, only metadata will be saved.";
|
||||
|
||||
_downloadSelectionWarningCompletionSource =
|
||||
new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
IsDownloadSelectionWarningModalOpen = true;
|
||||
|
||||
bool confirmed;
|
||||
try
|
||||
{
|
||||
confirmed = await _downloadSelectionWarningCompletionSource.Task;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_downloadSelectionWarningCompletionSource = null;
|
||||
IsDownloadSelectionWarningModalOpen = false;
|
||||
}
|
||||
|
||||
return confirmed;
|
||||
}
|
||||
|
||||
private static bool TryParseSinglePostOrMessageUrl(
|
||||
string url,
|
||||
out SingleDownloadRequest request,
|
||||
@ -2187,18 +2269,18 @@ public partial class MainWindowViewModel(
|
||||
nameof(Config.FFmpegPath) => "External",
|
||||
nameof(Config.FFprobePath) => "External",
|
||||
|
||||
nameof(Config.DownloadAvatarHeaderPhoto) => "Download Media Types",
|
||||
nameof(Config.DownloadPaidPosts) => "Download Media Types",
|
||||
nameof(Config.DownloadPosts) => "Download Media Types",
|
||||
nameof(Config.DownloadArchived) => "Download Media Types",
|
||||
nameof(Config.DownloadStreams) => "Download Media Types",
|
||||
nameof(Config.DownloadStories) => "Download Media Types",
|
||||
nameof(Config.DownloadHighlights) => "Download Media Types",
|
||||
nameof(Config.DownloadMessages) => "Download Media Types",
|
||||
nameof(Config.DownloadPaidMessages) => "Download Media Types",
|
||||
nameof(Config.DownloadImages) => "Download Media Types",
|
||||
nameof(Config.DownloadVideos) => "Download Media Types",
|
||||
nameof(Config.DownloadAudios) => "Download Media Types",
|
||||
nameof(Config.DownloadAvatarHeaderPhoto) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadPaidPosts) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadPosts) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadArchived) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadStreams) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadStories) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadHighlights) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadMessages) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadPaidMessages) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadImages) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadVideos) => "Download Media Types and Sources",
|
||||
nameof(Config.DownloadAudios) => "Download Media Types and Sources",
|
||||
|
||||
nameof(Config.IgnoreOwnMessages) => "Download Behavior",
|
||||
nameof(Config.DownloadPostsIncrementally) => "Download Behavior",
|
||||
@ -2246,7 +2328,7 @@ public partial class MainWindowViewModel(
|
||||
{
|
||||
"Auth" => 0,
|
||||
"External" => 1,
|
||||
"Download Media Types" => 2,
|
||||
"Download Media Types and Sources" => 2,
|
||||
"Download Behavior" => 3,
|
||||
"File Naming" => 4,
|
||||
"Folder Structure" => 5,
|
||||
|
||||
@ -254,7 +254,7 @@
|
||||
<TextBlock FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Foreground="{DynamicResource TextPrimaryBrush}"
|
||||
Text="Download Media Types" />
|
||||
Text="Download Media Types and Sources" />
|
||||
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock FontWeight="SemiBold"
|
||||
@ -1527,10 +1527,57 @@
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="0" Grid.RowSpan="3"
|
||||
IsVisible="{Binding IsMissingCdmWarningModalOpen}"
|
||||
IsVisible="{Binding IsDownloadSelectionWarningModalOpen}"
|
||||
Background="{DynamicResource OverlayBackgroundBrush}"
|
||||
ZIndex="1002"
|
||||
PointerPressed="OnModalOverlayClicked">
|
||||
<Border Background="{DynamicResource ModalBackgroundBrush}"
|
||||
BorderBrush="{DynamicResource ModalBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="16"
|
||||
Padding="28"
|
||||
Width="720"
|
||||
MaxHeight="500"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
BoxShadow="0 20 25 -5 #19000000, 0 10 10 -5 #0F000000"
|
||||
PointerPressed="OnModalContentClicked">
|
||||
<StackPanel Spacing="16">
|
||||
<TextBlock FontSize="20"
|
||||
FontWeight="Bold"
|
||||
Foreground="{DynamicResource TextPrimaryBrush}"
|
||||
Text="No Media Types/Sources Enabled" />
|
||||
|
||||
<TextBlock Foreground="{DynamicResource TextSecondaryBrush}"
|
||||
TextWrapping="Wrap"
|
||||
Text="{Binding DownloadSelectionWarningMessage}" />
|
||||
|
||||
<Grid ColumnDefinitions="*,Auto,Auto">
|
||||
<Button Grid.Column="0"
|
||||
Classes="secondary"
|
||||
HorizontalAlignment="Left"
|
||||
Content="Open Configuration"
|
||||
Command="{Binding OpenConfigurationFromDownloadSelectionWarningCommand}" />
|
||||
<Button Grid.Column="1"
|
||||
Margin="10,0,0,0"
|
||||
Content="Cancel"
|
||||
Classes="secondary"
|
||||
Command="{Binding CancelDownloadSelectionWarningCommand}" />
|
||||
<Button Grid.Column="2"
|
||||
Margin="10,0,0,0"
|
||||
Content="Continue Anyways"
|
||||
Classes="primary"
|
||||
Command="{Binding ConfirmDownloadSelectionWarningCommand}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="0" Grid.RowSpan="3"
|
||||
IsVisible="{Binding IsMissingCdmWarningModalOpen}"
|
||||
Background="{DynamicResource OverlayBackgroundBrush}"
|
||||
ZIndex="1003"
|
||||
PointerPressed="OnModalOverlayClicked">
|
||||
<Border Background="{DynamicResource ModalBackgroundBrush}"
|
||||
BorderBrush="{DynamicResource ModalBorderBrush}"
|
||||
BorderThickness="1"
|
||||
|
||||
@ -282,6 +282,7 @@ public partial class MainWindow : Window
|
||||
// Execute cancel command on any open modal
|
||||
vm.CreatorConfigEditor.ModalViewModel.CancelCommand.Execute(null);
|
||||
vm.CancelSinglePostOrMessageCommand.Execute(null);
|
||||
vm.CancelDownloadSelectionWarningCommand.Execute(null);
|
||||
vm.CancelMissingCdmWarningCommand.Execute(null);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user