Chg - Save Auto Download & Remove Finished in settings

Fix - Search popup didn't close when dismissed
This commit is contained in:
Elwador 2024-07-22 21:11:13 +02:00
parent 18c99f2a02
commit 9d499682ba
9 changed files with 74 additions and 56 deletions

View File

@ -148,8 +148,6 @@ public class CalendarManager{
public async Task<CalendarWeek> BuildCustomCalendar(bool forceUpdate){
Console.WriteLine("C" + DateTime.Now.ToString("yyyy-MM-dd"));
if (!forceUpdate && calendar.TryGetValue("C" + DateTime.Now.ToString("yyyy-MM-dd"), out var forDate)){
return forDate;
}

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using Avalonia.Media;
@ -18,6 +19,7 @@ using CRD.Utils.Muxing;
using CRD.Utils.Sonarr;
using CRD.Utils.Structs;
using CRD.Utils.Structs.History;
using CRD.ViewModels;
using CRD.Views;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -30,7 +32,8 @@ public class CrunchyrollManager{
public CrCmsToken? CmsToken;
public CrProfile Profile = new();
public CrDownloadOptions CrunOptions;
private readonly Lazy<CrDownloadOptions> _optionsLazy;
public CrDownloadOptions CrunOptions => _optionsLazy.Value;
#region History Variables
@ -78,42 +81,50 @@ public class CrunchyrollManager{
#endregion
public CrunchyrollManager(){
CrunOptions = new CrDownloadOptions();
_optionsLazy = new Lazy<CrDownloadOptions>(InitDownloadOptions, LazyThreadSafetyMode.ExecutionAndPublication);
}
private CrDownloadOptions InitDownloadOptions(){
var options = new CrDownloadOptions();
options.AutoDownload = false;
options.RemoveFinishedDownload = false;
options.Chapters = true;
options.Hslang = "none";
options.Force = "Y";
options.FileName = "${seriesTitle} - S${season}E${episode} [${height}p]";
options.Partsize = 10;
options.DlSubs = new List<string>{ "de-DE" };
options.Skipmux = false;
options.MkvmergeOptions = new List<string>{ "--no-date", "--disable-track-statistics-tags", "--engage no_variable_data" };
options.FfmpegOptions = new();
options.DefaultAudio = "ja-JP";
options.DefaultSub = "de-DE";
options.CcTag = "cc";
options.FsRetryTime = 5;
options.Numbers = 2;
options.Timeout = 15000;
options.DubLang = new List<string>(){ "ja-JP" };
options.SimultaneousDownloads = 2;
options.AccentColor = Colors.SlateBlue.ToString();
options.Theme = "System";
options.SelectedCalendarLanguage = "en-us";
options.CalendarDubFilter = "none";
options.DlVideoOnce = true;
options.StreamEndpoint = "web/firefox";
options.SubsAddScaledBorder = ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes;
options.HistoryLang = DefaultLocale;
options.History = true;
CfgManager.UpdateSettingsFromFile(options);
return options;
}
public void InitOptions(){
CrunOptions.AutoDownload = false;
CrunOptions.RemoveFinishedDownload = false;
CrunOptions.Chapters = true;
CrunOptions.Hslang = "none";
CrunOptions.Force = "Y";
CrunOptions.FileName = "${seriesTitle} - S${season}E${episode} [${height}p]";
CrunOptions.Partsize = 10;
CrunOptions.DlSubs = new List<string>{ "de-DE" };
CrunOptions.Skipmux = false;
CrunOptions.MkvmergeOptions = new List<string>{ "--no-date", "--disable-track-statistics-tags", "--engage no_variable_data" };
CrunOptions.FfmpegOptions = new();
CrunOptions.DefaultAudio = "ja-JP";
CrunOptions.DefaultSub = "de-DE";
CrunOptions.CcTag = "cc";
CrunOptions.FsRetryTime = 5;
CrunOptions.Numbers = 2;
CrunOptions.Timeout = 15000;
CrunOptions.DubLang = new List<string>(){ "ja-JP" };
CrunOptions.SimultaneousDownloads = 2;
CrunOptions.AccentColor = Colors.SlateBlue.ToString();
CrunOptions.Theme = "System";
CrunOptions.SelectedCalendarLanguage = "en-us";
CrunOptions.CalendarDubFilter = "none";
CrunOptions.DlVideoOnce = true;
CrunOptions.StreamEndpoint = "web/firefox";
CrunOptions.SubsAddScaledBorder = ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes;
CrunOptions.HistoryLang = DefaultLocale;
CrunOptions.History = true;
CfgManager.UpdateSettingsFromFile();
_widevine = Widevine.Instance;
CrAuth = new CrAuth();

View File

@ -147,7 +147,7 @@ public class CfgManager{
}
public static void UpdateSettingsFromFile(){
public static void UpdateSettingsFromFile(CrDownloadOptions options){
string dirPath = Path.GetDirectoryName(PathCrDownloadOptions) ?? string.Empty;
if (!Directory.Exists(dirPath)){
@ -174,7 +174,7 @@ public class CfgManager{
var propertiesPresentInYaml = GetTopLevelPropertiesInYaml(input);
var loadedOptions = deserializer.Deserialize<CrDownloadOptions>(new StringReader(input));
var instanceOptions = CrunchyrollManager.Instance.CrunOptions;
var instanceOptions = options;
foreach (PropertyInfo property in typeof(CrDownloadOptions).GetProperties()){
var yamlMemberAttribute = property.GetCustomAttribute<YamlMemberAttribute>();

View File

@ -7,11 +7,11 @@ namespace CRD.Utils.Structs;
public class CrDownloadOptions{
[YamlIgnore]
[YamlMember(Alias = "auto_download", ApplyNamingConventions = false)]
public bool AutoDownload{ get; set; }
[YamlIgnore]
[YamlMember(Alias = "remove_finished_downloads", ApplyNamingConventions = false)]
public bool RemoveFinishedDownload{ get; set; }

View File

@ -93,7 +93,6 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
SearchItems.Add(episode);
}
SearchPopupVisible = true;
RaisePropertyChanged(nameof(SearchItems));
RaisePropertyChanged(nameof(SearchVisible));

View File

@ -9,6 +9,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CRD.Downloader;
using CRD.Downloader.Crunchyroll;
using CRD.Utils;
using CRD.Utils.Structs;
namespace CRD.ViewModels;
@ -17,10 +18,10 @@ public partial class DownloadsPageViewModel : ViewModelBase{
public ObservableCollection<DownloadItemModel> Items{ get; }
[ObservableProperty]
public bool _autoDownload;
private bool _autoDownload;
[ObservableProperty]
public bool _removeFinished;
private bool _removeFinished;
public DownloadsPageViewModel(){
QueueManager.Instance.UpdateDownloadListItems();
@ -34,10 +35,12 @@ public partial class DownloadsPageViewModel : ViewModelBase{
if (value){
QueueManager.Instance.UpdateDownloadListItems();
}
CfgManager.WriteSettingsToFile();
}
partial void OnRemoveFinishedChanged(bool value){
CrunchyrollManager.Instance.CrunOptions.RemoveFinishedDownload = value;
CfgManager.WriteSettingsToFile();
}
}

View File

@ -27,7 +27,6 @@ public partial class MainWindowViewModel : ViewModelBase{
Init();
CleanUpOldUpdater();
}
private void CleanUpOldUpdater(){
@ -66,6 +65,5 @@ public partial class MainWindowViewModel : ViewModelBase{
}
await CrunchyrollManager.Instance.Init();
}
}

View File

@ -25,12 +25,13 @@
<TextBox x:Name="SearchBar" Watermark="Enter series or episode url" Text="{Binding UrlInput}" Margin="10"
VerticalAlignment="Top" />
<Popup IsLightDismissEnabled="False"
<Popup IsLightDismissEnabled="True"
MaxWidth="{Binding Bounds.Width, ElementName=SearchBar}"
MaxHeight="{Binding Bounds.Height, ElementName=Grid}"
IsOpen="{Binding SearchPopupVisible}"
Placement="Bottom"
PlacementTarget="{Binding ElementName=SearchBar}">
PlacementTarget="{Binding ElementName=SearchBar}"
Closed="Popup_Closed">
<Border BorderThickness="1" Background="{DynamicResource ComboBoxDropDownBackground}">
<ListBox x:Name="ListBoxDubsSelection"

View File

@ -1,6 +1,8 @@
using Avalonia;
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using CRD.ViewModels;
namespace CRD.Views;
@ -8,4 +10,10 @@ public partial class AddDownloadPageView : UserControl{
public AddDownloadPageView(){
InitializeComponent();
}
private void Popup_Closed(object? sender, EventArgs e){
if (DataContext is AddDownloadPageViewModel viewModel){
viewModel.SearchPopupVisible = false;
}
}
}