forked from sim0n00ps/OF-DL
Add ShowScrapeSize config option to the GUI with a warning modal
This commit is contained in:
parent
aaed5bc906
commit
73bd188699
@ -94,6 +94,8 @@ public class Config : IFileNameFormatConfig
|
||||
|
||||
[ToggleableConfig] public bool HideMissingCdmKeysWarning { get; set; }
|
||||
|
||||
[ToggleableConfig] public bool HideShowScrapeSizeWarning { get; set; }
|
||||
|
||||
[ToggleableConfig] public bool IgnoreOwnMessages { get; set; }
|
||||
|
||||
[ToggleableConfig] public bool DisableBrowserAuth { get; set; }
|
||||
|
||||
@ -241,6 +241,9 @@ public class ConfigService(ILoggingService loggingService) : IConfigService
|
||||
HideMissingCdmKeysWarning =
|
||||
bool.TryParse(hoconConfig.GetString("Appearance.HideMissingCdmKeysWarning", "false"),
|
||||
out bool hideMissingCdmKeysWarning) && hideMissingCdmKeysWarning,
|
||||
HideShowScrapeSizeWarning =
|
||||
bool.TryParse(hoconConfig.GetString("Appearance.HideShowScrapeSizeWarning", "false"),
|
||||
out bool hideShowScrapeSizeWarning) && hideShowScrapeSizeWarning,
|
||||
|
||||
// Logging/Debug Settings
|
||||
LoggingLevel = Enum.Parse<LoggingLevel>(hoconConfig.GetString("Logging.LoggingLevel"), true)
|
||||
@ -417,6 +420,7 @@ public class ConfigService(ILoggingService loggingService) : IConfigService
|
||||
hocon.AppendLine("Appearance {");
|
||||
hocon.AppendLine($" Theme = \"{config.Theme.ToString().ToLower()}\"");
|
||||
hocon.AppendLine($" HideMissingCdmKeysWarning = {config.HideMissingCdmKeysWarning.ToString().ToLower()}");
|
||||
hocon.AppendLine($" HideShowScrapeSizeWarning = {config.HideShowScrapeSizeWarning.ToString().ToLower()}");
|
||||
hocon.AppendLine("}");
|
||||
|
||||
hocon.AppendLine("# Logging/Debug Settings");
|
||||
|
||||
@ -58,7 +58,8 @@ public partial class ConfigFieldViewModel : ViewModelBase
|
||||
[nameof(Config.RenameExistingFilesWhenCustomFormatIsSelected)] =
|
||||
"Rename Existing Files with Custom Formats",
|
||||
[nameof(Config.DownloadPath)] = "Download Folder",
|
||||
[nameof(Config.HideMissingCdmKeysWarning)] = "Hide Missing CDM Keys Warning"
|
||||
[nameof(Config.HideMissingCdmKeysWarning)] = "Hide Missing CDM Keys Warning",
|
||||
[nameof(Config.HideShowScrapeSizeWarning)] = "Hide Show Scrape Size Warning"
|
||||
};
|
||||
|
||||
public ConfigFieldViewModel(
|
||||
|
||||
@ -118,7 +118,7 @@ public partial class MainWindowViewModel(
|
||||
[nameof(Config.CustomDate)] =
|
||||
"Date used for post filtering (yyyy-MM-dd).",
|
||||
[nameof(Config.ShowScrapeSize)] =
|
||||
"Show estimated total bytes instead of item counts while preparing downloads.",
|
||||
"Warning! Enabling this option will significantly increase the scraping/downloading time. Enabling this option will show estimated total bytes instead of item counts while downloading content.",
|
||||
[nameof(Config.DisableTextSanitization)] =
|
||||
"Store post and message text as-is without XML stripping.",
|
||||
[nameof(Config.DownloadVideoResolution)] =
|
||||
@ -159,6 +159,8 @@ public partial class MainWindowViewModel(
|
||||
"Choose the GUI theme.",
|
||||
[nameof(Config.HideMissingCdmKeysWarning)] =
|
||||
"Skip the missing CDM keys confirmation before downloads start.",
|
||||
[nameof(Config.HideShowScrapeSizeWarning)] =
|
||||
"Skip the show scrape size confirmation before downloads start.",
|
||||
[nameof(Config.LoggingLevel)] =
|
||||
"Minimum log level written to logs/OFDL.txt."
|
||||
};
|
||||
@ -355,6 +357,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 _isShowScrapeSizeWarningModalOpen;
|
||||
|
||||
[ObservableProperty] private string _showScrapeSizeWarningMessage = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(OpenSinglePostOrMessageModalCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(SubmitSinglePostOrMessageCommand))]
|
||||
@ -495,6 +506,7 @@ public partial class MainWindowViewModel(
|
||||
|
||||
private bool _isUpdatingAllUsersSelected;
|
||||
private TaskCompletionSource<bool>? _missingCdmWarningCompletionSource;
|
||||
private TaskCompletionSource<bool>? _showScrapeSizeWarningCompletionSource;
|
||||
private TaskCompletionSource<bool>? _downloadSelectionWarningCompletionSource;
|
||||
|
||||
public async Task InitializeAsync()
|
||||
@ -891,6 +903,20 @@ public partial class MainWindowViewModel(
|
||||
_missingCdmWarningCompletionSource?.TrySetResult(false);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ConfirmShowScrapeSizeWarning()
|
||||
{
|
||||
IsShowScrapeSizeWarningModalOpen = false;
|
||||
_showScrapeSizeWarningCompletionSource?.TrySetResult(true);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CancelShowScrapeSizeWarning()
|
||||
{
|
||||
IsShowScrapeSizeWarningModalOpen = false;
|
||||
_showScrapeSizeWarningCompletionSource?.TrySetResult(false);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ConfirmDownloadSelectionWarning()
|
||||
{
|
||||
@ -947,6 +973,11 @@ public partial class MainWindowViewModel(
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await EnsureShowScrapeSizeWarningConfirmedAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
downloadErrorLogTracker.StartSession();
|
||||
IsDownloading = true;
|
||||
_workCancellationSource?.Dispose();
|
||||
@ -1055,6 +1086,7 @@ public partial class MainWindowViewModel(
|
||||
AvailableUsers.Any(user => user.IsSelected) &&
|
||||
!IsDownloadSelectionWarningModalOpen &&
|
||||
!IsMissingCdmWarningModalOpen &&
|
||||
!IsShowScrapeSizeWarningModalOpen &&
|
||||
!IsDownloading;
|
||||
|
||||
private bool CanDownloadPurchasedTab() =>
|
||||
@ -1062,6 +1094,7 @@ public partial class MainWindowViewModel(
|
||||
_allUsers.Count > 0 &&
|
||||
!IsDownloadSelectionWarningModalOpen &&
|
||||
!IsMissingCdmWarningModalOpen &&
|
||||
!IsShowScrapeSizeWarningModalOpen &&
|
||||
!IsDownloading;
|
||||
|
||||
private bool CanOpenSinglePostOrMessageModal() =>
|
||||
@ -1069,12 +1102,14 @@ public partial class MainWindowViewModel(
|
||||
!IsDownloading &&
|
||||
!IsDownloadSelectionWarningModalOpen &&
|
||||
!IsMissingCdmWarningModalOpen &&
|
||||
!IsShowScrapeSizeWarningModalOpen &&
|
||||
!IsSinglePostOrMessageModalOpen;
|
||||
|
||||
private bool CanSubmitSinglePostOrMessage() =>
|
||||
IsSinglePostOrMessageModalOpen &&
|
||||
!IsDownloadSelectionWarningModalOpen &&
|
||||
!IsMissingCdmWarningModalOpen &&
|
||||
!IsShowScrapeSizeWarningModalOpen &&
|
||||
!IsDownloading &&
|
||||
!string.IsNullOrWhiteSpace(SinglePostOrMessageUrl);
|
||||
|
||||
@ -1251,6 +1286,11 @@ public partial class MainWindowViewModel(
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await EnsureShowScrapeSizeWarningConfirmedAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
downloadErrorLogTracker.StartSession();
|
||||
IsDownloading = true;
|
||||
_workCancellationSource?.Dispose();
|
||||
@ -1423,6 +1463,41 @@ public partial class MainWindowViewModel(
|
||||
return confirmed;
|
||||
}
|
||||
|
||||
private async Task<bool> EnsureShowScrapeSizeWarningConfirmedAsync()
|
||||
{
|
||||
if (!configService.CurrentConfig.ShowScrapeSize || configService.CurrentConfig.HideShowScrapeSizeWarning)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ShowScrapeSizeWarningMessage =
|
||||
"Show Scrape Size is enabled.\n\n" +
|
||||
"This mode estimates total bytes before downloads and can significantly increase scraping/downloading time.\n\n" +
|
||||
"You can hide this warning in the future by enabling \"Hide Show Scrape Size Warning\" in the configuration settings.\n\n";
|
||||
|
||||
_showScrapeSizeWarningCompletionSource =
|
||||
new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
IsShowScrapeSizeWarningModalOpen = true;
|
||||
|
||||
bool confirmed;
|
||||
try
|
||||
{
|
||||
confirmed = await _showScrapeSizeWarningCompletionSource.Task;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_showScrapeSizeWarningCompletionSource = null;
|
||||
IsShowScrapeSizeWarningModalOpen = false;
|
||||
}
|
||||
|
||||
if (!confirmed)
|
||||
{
|
||||
AppendLog("Download canceled after show scrape size warning.");
|
||||
}
|
||||
|
||||
return confirmed;
|
||||
}
|
||||
|
||||
private async Task<bool> EnsureDownloadSelectionWarningConfirmedAsync()
|
||||
{
|
||||
bool hasEnabledMediaType = configService.CurrentConfig.DownloadVideos ||
|
||||
@ -1906,6 +1981,7 @@ public partial class MainWindowViewModel(
|
||||
{
|
||||
nameof(Config.Theme) => 0,
|
||||
nameof(Config.HideMissingCdmKeysWarning) => 1,
|
||||
nameof(Config.HideShowScrapeSizeWarning) => 2,
|
||||
_ => 100
|
||||
};
|
||||
}
|
||||
@ -2284,7 +2360,7 @@ public partial class MainWindowViewModel(
|
||||
return JsonConvert.DeserializeObject<Config>(json) ?? new Config();
|
||||
}
|
||||
|
||||
private static void EnforceGuiOnlyConfigValues(Config config) => config.ShowScrapeSize = false;
|
||||
private static void EnforceGuiOnlyConfigValues(Config config) => _ = config;
|
||||
|
||||
private static bool IsHiddenConfigField(string propertyName) =>
|
||||
propertyName is nameof(Config.NonInteractiveMode)
|
||||
@ -2304,8 +2380,7 @@ public partial class MainWindowViewModel(
|
||||
or nameof(Config.DownloadStories)
|
||||
or nameof(Config.DownloadHighlights)
|
||||
or nameof(Config.DownloadMessages)
|
||||
or nameof(Config.DownloadPaidMessages)
|
||||
or nameof(Config.ShowScrapeSize);
|
||||
or nameof(Config.DownloadPaidMessages);
|
||||
|
||||
private static string GetConfigCategory(string propertyName) =>
|
||||
propertyName switch
|
||||
@ -2362,6 +2437,7 @@ public partial class MainWindowViewModel(
|
||||
|
||||
nameof(Config.Theme) => "Appearance",
|
||||
nameof(Config.HideMissingCdmKeysWarning) => "Appearance",
|
||||
nameof(Config.HideShowScrapeSizeWarning) => "Appearance",
|
||||
|
||||
nameof(Config.LoggingLevel) => "Logging",
|
||||
|
||||
|
||||
@ -1611,6 +1611,44 @@
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="0" Grid.RowSpan="3"
|
||||
IsVisible="{Binding IsShowScrapeSizeWarningModalOpen}"
|
||||
Background="{DynamicResource OverlayBackgroundBrush}"
|
||||
ZIndex="1004"
|
||||
PointerPressed="OnModalOverlayClicked">
|
||||
<Border Background="{DynamicResource ModalBackgroundBrush}"
|
||||
BorderBrush="{DynamicResource ModalBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="16"
|
||||
Padding="28"
|
||||
Width="680"
|
||||
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="Show Scrape Size Enabled" />
|
||||
|
||||
<TextBlock Foreground="{DynamicResource TextSecondaryBrush}"
|
||||
TextWrapping="Wrap"
|
||||
Text="{Binding ShowScrapeSizeWarningMessage}" />
|
||||
|
||||
<StackPanel Orientation="Horizontal" Spacing="10" HorizontalAlignment="Right">
|
||||
<Button Content="Cancel"
|
||||
Classes="secondary"
|
||||
Command="{Binding CancelShowScrapeSizeWarningCommand}" />
|
||||
<Button Content="Continue Download"
|
||||
Classes="primary"
|
||||
Command="{Binding ConfirmShowScrapeSizeWarningCommand}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<Border x:Name="CopyToastBorder"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="3"
|
||||
|
||||
@ -284,6 +284,7 @@ public partial class MainWindow : Window
|
||||
vm.CancelSinglePostOrMessageCommand.Execute(null);
|
||||
vm.CancelDownloadSelectionWarningCommand.Execute(null);
|
||||
vm.CancelMissingCdmWarningCommand.Execute(null);
|
||||
vm.CancelShowScrapeSizeWarningCommand.Execute(null);
|
||||
}
|
||||
|
||||
private void OnModalContentClicked(object? sender, PointerPressedEventArgs e) =>
|
||||
|
||||
@ -25,6 +25,7 @@ public class ConfigServiceTests
|
||||
Assert.Equal(0.98, service.CurrentConfig.DrmVideoDurationMatchThreshold, 3);
|
||||
Assert.Equal(Theme.dark, service.CurrentConfig.Theme);
|
||||
Assert.False(service.CurrentConfig.HideMissingCdmKeysWarning);
|
||||
Assert.False(service.CurrentConfig.HideShowScrapeSizeWarning);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -120,6 +121,25 @@ public class ConfigServiceTests
|
||||
Assert.True(service.CurrentConfig.HideMissingCdmKeysWarning);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task LoadConfigurationAsync_ParsesHideShowScrapeSizeWarning()
|
||||
{
|
||||
using TempFolder temp = new();
|
||||
using CurrentDirectoryScope _ = new(temp.Path);
|
||||
FakeLoggingService loggingService = new();
|
||||
ConfigService service = new(loggingService);
|
||||
await service.SaveConfigurationAsync();
|
||||
|
||||
string hocon = await File.ReadAllTextAsync("config.conf");
|
||||
hocon = hocon.Replace("HideShowScrapeSizeWarning = false", "HideShowScrapeSizeWarning = true");
|
||||
await File.WriteAllTextAsync("config.conf", hocon);
|
||||
|
||||
bool result = await service.LoadConfigurationAsync([]);
|
||||
|
||||
Assert.True(result);
|
||||
Assert.True(service.CurrentConfig.HideShowScrapeSizeWarning);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyToggleableSelections_UpdatesConfigAndReturnsChange()
|
||||
{
|
||||
|
||||
@ -399,6 +399,18 @@ Description: If set to `false`, OF-DL will show a warning and ask for confirmati
|
||||
`device_client_id_blob` and/or `device_private_key` is missing.
|
||||
If set to `true`, this warning is hidden and downloads start immediately.
|
||||
|
||||
## HideShowScrapeSizeWarning
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Default: `false`
|
||||
|
||||
Allowed values: `true`, `false`
|
||||
|
||||
Description: If set to `false`, OF-DL will show a warning and ask for confirmation before starting downloads when
|
||||
[ShowScrapeSize](#showscrapesize) is enabled.
|
||||
If set to `true`, this warning is hidden and downloads start immediately.
|
||||
|
||||
## IgnoreOwnMessages
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
@ -71,6 +71,7 @@ information about what it does, its default value, and the allowed values.
|
||||
- Appearance
|
||||
- [Theme](/config/all-configuration-options#theme)
|
||||
- [HideMissingCdmKeysWarning](/config/all-configuration-options#hidemissingcdmkeyswarning)
|
||||
- [HideShowScrapeSizeWarning](/config/all-configuration-options#hideshowscrapesizewarning)
|
||||
|
||||
- Logging
|
||||
- [LoggingLevel](/config/all-configuration-options#logginglevel)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user