Chg - Save Auto Download & Remove Finished in settings
Fix - Search popup didn't close when dismissed
This commit is contained in:
parent
18c99f2a02
commit
9d499682ba
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -55,7 +58,7 @@ public class CrunchyrollManager{
|
|||
public CrEpisode CrEpisode;
|
||||
public CrSeries CrSeries;
|
||||
public History History;
|
||||
|
||||
|
||||
#region Singelton
|
||||
|
||||
private static CrunchyrollManager? _instance;
|
||||
|
@ -78,42 +81,50 @@ public class CrunchyrollManager{
|
|||
#endregion
|
||||
|
||||
public CrunchyrollManager(){
|
||||
CrunOptions = new CrDownloadOptions();
|
||||
_optionsLazy = new Lazy<CrDownloadOptions>(InitDownloadOptions, LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
}
|
||||
|
||||
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;
|
||||
private CrDownloadOptions InitDownloadOptions(){
|
||||
|
||||
CfgManager.UpdateSettingsFromFile();
|
||||
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(){
|
||||
_widevine = Widevine.Instance;
|
||||
|
||||
CrAuth = new CrAuth();
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
||||
|
|
|
@ -93,7 +93,6 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
|
|||
|
||||
SearchItems.Add(episode);
|
||||
}
|
||||
|
||||
SearchPopupVisible = true;
|
||||
RaisePropertyChanged(nameof(SearchItems));
|
||||
RaisePropertyChanged(nameof(SearchVisible));
|
||||
|
|
|
@ -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();
|
||||
|
@ -28,16 +29,18 @@ public partial class DownloadsPageViewModel : ViewModelBase{
|
|||
AutoDownload = CrunchyrollManager.Instance.CrunOptions.AutoDownload;
|
||||
RemoveFinished = CrunchyrollManager.Instance.CrunOptions.RemoveFinishedDownload;
|
||||
}
|
||||
|
||||
|
||||
partial void OnAutoDownloadChanged(bool value){
|
||||
CrunchyrollManager.Instance.CrunOptions.AutoDownload = value;
|
||||
if (value){
|
||||
QueueManager.Instance.UpdateDownloadListItems();
|
||||
}
|
||||
CfgManager.WriteSettingsToFile();
|
||||
}
|
||||
|
||||
partial void OnRemoveFinishedChanged(bool value){
|
||||
CrunchyrollManager.Instance.CrunOptions.RemoveFinishedDownload = value;
|
||||
CfgManager.WriteSettingsToFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,27 +20,26 @@ public partial class MainWindowViewModel : ViewModelBase{
|
|||
|
||||
[ObservableProperty]
|
||||
private bool _updateAvailable = true;
|
||||
|
||||
|
||||
public MainWindowViewModel(){
|
||||
_faTheme = App.Current.Styles[0] as FluentAvaloniaTheme;
|
||||
|
||||
Init();
|
||||
|
||||
CleanUpOldUpdater();
|
||||
|
||||
}
|
||||
|
||||
private void CleanUpOldUpdater() {
|
||||
private void CleanUpOldUpdater(){
|
||||
string backupFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Updater.exe.bak");
|
||||
|
||||
if (File.Exists(backupFilePath)) {
|
||||
try {
|
||||
if (File.Exists(backupFilePath)){
|
||||
try{
|
||||
File.Delete(backupFilePath);
|
||||
Console.WriteLine($"Deleted old updater file: {backupFilePath}");
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception ex){
|
||||
Console.Error.WriteLine($"Failed to delete old updater file: {ex.Message}");
|
||||
}
|
||||
} else {
|
||||
} else{
|
||||
Console.WriteLine("No old updater file found to delete.");
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +47,7 @@ public partial class MainWindowViewModel : ViewModelBase{
|
|||
|
||||
public async void Init(){
|
||||
UpdateAvailable = await Updater.Instance.CheckForUpdatesAsync();
|
||||
|
||||
|
||||
CrunchyrollManager.Instance.InitOptions();
|
||||
|
||||
if (CrunchyrollManager.Instance.CrunOptions.AccentColor != null){
|
||||
|
@ -64,8 +63,7 @@ public partial class MainWindowViewModel : ViewModelBase{
|
|||
_faTheme.PreferSystemTheme = false;
|
||||
Application.Current.RequestedThemeVariant = ThemeVariant.Light;
|
||||
}
|
||||
|
||||
|
||||
await CrunchyrollManager.Instance.Init();
|
||||
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue