Skip to content

Commit ab13c2d

Browse files
committed
🧢 Use separate Settings for STJ source generation
Renamed the original `Settings` to `ObservableSettings`. Added a new clean `Settings` without all the Reactive fuss for STJ source generation.
1 parent bdaa262 commit ab13c2d

File tree

12 files changed

+378
-260
lines changed

12 files changed

+378
-260
lines changed

‎YoutubeDl.Wpf/Models/BackendInstance.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace YoutubeDl.Wpf.Models;
1717

1818
public class BackendInstance : ReactiveObject, IEnableLogger
1919
{
20-
private readonly Settings _settings;
20+
private readonly ObservableSettings _settings;
2121
private readonly Process _dlProcess;
2222
private readonly BackendService _backendService;
2323
private readonly string[] outputSeparators =
@@ -50,7 +50,7 @@ public class BackendInstance : ReactiveObject, IEnableLogger
5050
[Reactive]
5151
public string DownloadETAString { get; set; } = "";
5252

53-
public BackendInstance(Settings settings, BackendService backendService)
53+
public BackendInstance(ObservableSettings settings, BackendService backendService)
5454
{
5555
_settings = settings;
5656
_backendService = backendService;

‎YoutubeDl.Wpf/Models/BackendService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace YoutubeDl.Wpf.Models;
99

1010
public class BackendService : ReactiveObject, IEnableLogger
1111
{
12-
private readonly Settings _settings;
12+
private readonly ObservableSettings _settings;
1313

1414
public List<BackendInstance> Instances { get; } = new();
1515

@@ -22,7 +22,7 @@ public class BackendService : ReactiveObject, IEnableLogger
2222
[Reactive]
2323
public TaskbarItemProgressState ProgressState { get; set; }
2424

25-
public BackendService(Settings settings) => _settings = settings;
25+
public BackendService(ObservableSettings settings) => _settings = settings;
2626

2727
public BackendInstance CreateInstance()
2828
{
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
using MaterialDesignThemes.Wpf;
2+
using ReactiveUI;
3+
using ReactiveUI.Fody.Helpers;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Collections.ObjectModel;
7+
using System.Linq;
8+
9+
namespace YoutubeDl.Wpf.Models;
10+
11+
public class ObservableSettings : ReactiveObject
12+
{
13+
public BaseTheme AppColorMode { get; set; }
14+
15+
[Reactive]
16+
public BackendTypes Backend { get; set; }
17+
18+
[Reactive]
19+
public string BackendPath { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the list of arguments passed
23+
/// to the backend process for all types of operations.
24+
/// </summary>
25+
public ObservableCollection<BackendArgument> BackendGlobalArguments { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the list of arguments passed
29+
/// to the backend process for download operations.
30+
/// </summary>
31+
public List<BackendArgument> BackendDownloadArguments { get; set; }
32+
33+
[Reactive]
34+
public bool BackendAutoUpdate { get; set; }
35+
36+
[Reactive]
37+
public DateTimeOffset BackendLastUpdateCheck { get; set; }
38+
39+
[Reactive]
40+
public string FfmpegPath { get; set; }
41+
42+
[Reactive]
43+
public string Proxy { get; set; }
44+
45+
[Reactive]
46+
public int LoggingMaxEntries { get; set; }
47+
48+
[Reactive]
49+
public Preset? SelectedPreset { get; set; }
50+
51+
/// <summary>
52+
/// This is a hack to prevent <see cref="SelectedPreset"/> from being changed to null.
53+
/// Another solution is to manually implement equality for <see cref="Preset"/>,
54+
/// which is much harder to get it right, and would look terrible compared to this little hack.
55+
/// </summary>
56+
[Reactive]
57+
public string SelectedPresetText { get; set; }
58+
59+
public List<Preset> CustomPresets { get; set; }
60+
61+
[Reactive]
62+
public bool AddMetadata { get; set; }
63+
64+
[Reactive]
65+
public bool DownloadThumbnail { get; set; }
66+
67+
[Reactive]
68+
public bool DownloadSubtitles { get; set; }
69+
70+
[Reactive]
71+
public bool DownloadSubtitlesAllLanguages { get; set; }
72+
73+
[Reactive]
74+
public bool DownloadAutoGeneratedSubtitles { get; set; }
75+
76+
[Reactive]
77+
public bool DownloadPlaylist { get; set; }
78+
79+
[Reactive]
80+
public bool UseCustomOutputTemplate { get; set; }
81+
82+
[Reactive]
83+
public string CustomOutputTemplate { get; set; }
84+
85+
[Reactive]
86+
public bool UseCustomPath { get; set; }
87+
88+
[Reactive]
89+
public string DownloadPath { get; set; }
90+
91+
/// <summary>
92+
/// Gets the list of download path history.
93+
/// New paths are always appended to the list.
94+
/// </summary>
95+
public List<string> DownloadPathHistory { get; set; }
96+
97+
public ObservableSettings(Settings settings)
98+
{
99+
AppColorMode = settings.AppColorMode;
100+
Backend = settings.Backend;
101+
BackendPath = settings.BackendPath;
102+
BackendGlobalArguments = new(settings.BackendGlobalArguments);
103+
BackendDownloadArguments = new(settings.BackendDownloadArguments);
104+
BackendAutoUpdate = settings.BackendAutoUpdate;
105+
BackendLastUpdateCheck = settings.BackendLastUpdateCheck;
106+
FfmpegPath = settings.FfmpegPath;
107+
Proxy = settings.Proxy;
108+
LoggingMaxEntries = settings.LoggingMaxEntries;
109+
SelectedPreset = settings.SelectedPreset;
110+
SelectedPresetText = settings.SelectedPresetText;
111+
CustomPresets = new(settings.CustomPresets);
112+
AddMetadata = settings.AddMetadata;
113+
DownloadThumbnail = settings.DownloadThumbnail;
114+
DownloadSubtitles = settings.DownloadSubtitles;
115+
DownloadSubtitlesAllLanguages = settings.DownloadSubtitlesAllLanguages;
116+
DownloadAutoGeneratedSubtitles = settings.DownloadAutoGeneratedSubtitles;
117+
DownloadPlaylist = settings.DownloadPlaylist;
118+
UseCustomOutputTemplate = settings.UseCustomOutputTemplate;
119+
CustomOutputTemplate = settings.CustomOutputTemplate;
120+
UseCustomPath = settings.UseCustomPath;
121+
DownloadPath = settings.DownloadPath;
122+
DownloadPathHistory = new(settings.DownloadPathHistory);
123+
}
124+
125+
public void UpdateSettings(Settings settings)
126+
{
127+
settings.AppColorMode = AppColorMode;
128+
settings.Backend = Backend;
129+
settings.BackendPath = BackendPath;
130+
settings.BackendGlobalArguments = BackendGlobalArguments.ToArray();
131+
settings.BackendDownloadArguments = BackendDownloadArguments.ToArray();
132+
settings.BackendAutoUpdate = BackendAutoUpdate;
133+
settings.BackendLastUpdateCheck = BackendLastUpdateCheck;
134+
settings.FfmpegPath = FfmpegPath;
135+
settings.Proxy = Proxy;
136+
settings.LoggingMaxEntries = LoggingMaxEntries;
137+
settings.SelectedPreset = SelectedPreset;
138+
settings.SelectedPresetText = SelectedPresetText;
139+
settings.CustomPresets = CustomPresets.ToArray();
140+
settings.AddMetadata = AddMetadata;
141+
settings.DownloadThumbnail = DownloadThumbnail;
142+
settings.DownloadSubtitles = DownloadSubtitles;
143+
settings.DownloadSubtitlesAllLanguages = DownloadSubtitlesAllLanguages;
144+
settings.DownloadAutoGeneratedSubtitles = DownloadAutoGeneratedSubtitles;
145+
settings.DownloadPlaylist = DownloadPlaylist;
146+
settings.UseCustomOutputTemplate = UseCustomOutputTemplate;
147+
settings.CustomOutputTemplate = CustomOutputTemplate;
148+
settings.UseCustomPath = UseCustomPath;
149+
settings.DownloadPath = DownloadPath;
150+
settings.DownloadPathHistory = DownloadPathHistory.ToArray();
151+
}
152+
}

‎YoutubeDl.Wpf/Models/QueuedTextBoxSink.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace YoutubeDl.Wpf.Models;
1212
public class QueuedTextBoxSink : ReactiveObject, ILogEventSink
1313
{
1414
private readonly object _locker = new();
15-
private readonly Settings _settings;
15+
private readonly ObservableSettings _settings;
1616
private readonly Queue<LogEvent> _queuedLogEvents;
1717
private readonly IFormatProvider? _formatProvider;
1818

1919
[Reactive]
2020
public string Content { get; set; } = "";
2121

22-
public QueuedTextBoxSink(Settings settings, IFormatProvider? formatProvider = null)
22+
public QueuedTextBoxSink(ObservableSettings settings, IFormatProvider? formatProvider = null)
2323
{
2424
_settings = settings;
2525
_queuedLogEvents = new(settings.LoggingMaxEntries);

0 commit comments

Comments
 (0)