Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry08 committed Dec 28, 2024
1 parent 69480ac commit ffc9726
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 54 deletions.
70 changes: 23 additions & 47 deletions SoundCloudDownloader/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,39 @@

namespace SoundCloudDownloader.Services;

// Can't use [ObservableProperty] here because System.Text.Json's source generator doesn't see
// the generated properties.
[INotifyPropertyChanged]
public partial class SettingsService()
: SettingsBase(
Path.Combine(AppContext.BaseDirectory, "Settings.dat"),
SerializerContext.Default
)
public partial class SettingsService : SettingsBase
{
private ThemeVariant _theme;
public ThemeVariant Theme
{
get => _theme;
set => SetProperty(ref _theme, value);
}
[ObservableProperty]
public partial ThemeVariant Theme { get; set; }

private bool _isAutoUpdateEnabled = true;
public bool IsAutoUpdateEnabled
{
get => _isAutoUpdateEnabled;
set => SetProperty(ref _isAutoUpdateEnabled, value);
}
[ObservableProperty]
public partial bool IsAutoUpdateEnabled { get; set; }

private bool _shouldInjectTags = true;
public bool ShouldInjectTags
{
get => _shouldInjectTags;
set => SetProperty(ref _shouldInjectTags, value);
}
[ObservableProperty]
public partial bool ShouldInjectTags { get; set; }

private bool _shouldSkipExistingFiles;
public bool ShouldSkipExistingFiles
{
get => _shouldSkipExistingFiles;
set => SetProperty(ref _shouldSkipExistingFiles, value);
}
[ObservableProperty]
public partial bool ShouldSkipExistingFiles { get; set; }

private string _fileNameTemplate = "$title";
public string FileNameTemplate
{
get => _fileNameTemplate;
set => SetProperty(ref _fileNameTemplate, value);
}
[ObservableProperty]
public partial string FileNameTemplate { get; set; }

private int _parallelLimit = 5;
public int ParallelLimit
{
get => _parallelLimit;
set => SetProperty(ref _parallelLimit, value);
}
[ObservableProperty]
public partial int ParallelLimit { get; set; }

private string _lastContainer = "Mp3";
[ObservableProperty]
public partial string LastContainer { get; set; }

public string LastContainer
public SettingsService()
: base(Path.Combine(AppContext.BaseDirectory, "Settings.dat"), SerializerContext.Default)
{
get => _lastContainer;
set => SetProperty(ref _lastContainer, value);
// Initialize properties here to prevent linux build error CS8050
IsAutoUpdateEnabled = true;
ShouldInjectTags = true;
FileNameTemplate = "$title";
ParallelLimit = 5;
LastContainer = "Mp3";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class DownloadViewModel : ViewModelBase
[NotifyCanExecuteChangedFor(nameof(CancelCommand))]
[NotifyCanExecuteChangedFor(nameof(ShowFileCommand))]
[NotifyCanExecuteChangedFor(nameof(OpenFileCommand))]
public partial DownloadStatus Status { get; set; } = DownloadStatus.Enqueued;
DownloadStatus _status = DownloadStatus.Enqueued;

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CopyErrorMessageCommand))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ SettingsService settingsService
public partial IReadOnlyList<Track>? AvailableTracks { get; set; }

[ObservableProperty]
public partial string SelectedContainer { get; set; } = "Mp3";
string _selectedContainer = "Mp3";

public ObservableCollection<Track> SelectedTracks { get; } = [];

public IReadOnlyList<string> AvailableContainers { get; } = ["Mp3"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SettingsService settingsService
public partial Track? Track { get; set; }

[ObservableProperty]
public partial IReadOnlyList<string>? AvailableDownloadOptions { get; set; } = ["Mp3"];
IReadOnlyList<string>? _availableDownloadOptions = ["Mp3"];

[ObservableProperty]
public partial string? SelectedDownloadOption { get; set; }
Expand Down
16 changes: 12 additions & 4 deletions SoundCloudDownloader/ViewModels/Dialogs/MessageBoxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,32 @@ namespace SoundCloudDownloader.ViewModels.Dialogs;
public partial class MessageBoxViewModel : DialogViewModelBase
{
[ObservableProperty]
public partial string? Title { get; set; } = "Title";
public partial string? Title { get; set; }

[ObservableProperty]
public partial string? Message { get; set; } = "Message";
public partial string? Message { get; set; }

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsDefaultButtonVisible))]
[NotifyPropertyChangedFor(nameof(ButtonsCount))]
public partial string? DefaultButtonText { get; set; } = "OK";
public partial string? DefaultButtonText { get; set; }

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsCancelButtonVisible))]
[NotifyPropertyChangedFor(nameof(ButtonsCount))]
public partial string? CancelButtonText { get; set; } = "Cancel";
public partial string? CancelButtonText { get; set; }

public bool IsDefaultButtonVisible => !string.IsNullOrWhiteSpace(DefaultButtonText);

public bool IsCancelButtonVisible => !string.IsNullOrWhiteSpace(CancelButtonText);

public int ButtonsCount => (IsDefaultButtonVisible ? 1 : 0) + (IsCancelButtonVisible ? 1 : 0);

public MessageBoxViewModel()
{
Title = "Title";
Message = "Message";
DefaultButtonText = "Ok";
CancelButtonText = "Cancel";
}
}

0 comments on commit ffc9726

Please sign in to comment.