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 5edba74 commit 78f8c20
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 37 deletions.
27 changes: 10 additions & 17 deletions SoundCloudDownloader/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,32 @@
namespace SoundCloudDownloader.Services;

[INotifyPropertyChanged]
public partial class SettingsService : SettingsBase
public partial class SettingsService()
: SettingsBase(
Path.Combine(AppContext.BaseDirectory, "Settings.dat"),
SerializerContext.Default
)
{
[ObservableProperty]
public partial ThemeVariant Theme { get; set; }

[ObservableProperty]
public partial bool IsAutoUpdateEnabled { get; set; }
public partial bool IsAutoUpdateEnabled { get; set; } = true;

[ObservableProperty]
public partial bool ShouldInjectTags { get; set; }
public partial bool ShouldInjectTags { get; set; } = true;

[ObservableProperty]
public partial bool ShouldSkipExistingFiles { get; set; }

[ObservableProperty]
public partial string FileNameTemplate { get; set; }
public partial string FileNameTemplate { get; set; } = "$title";

[ObservableProperty]
public partial int ParallelLimit { get; set; }
public partial int ParallelLimit { get; set; } = 5;

[ObservableProperty]
public partial string LastContainer { get; set; }

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

public partial class SettingsService
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; }
public partial DownloadStatus Status { get; set; } = DownloadStatus.Enqueued;

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CopyErrorMessageCommand))]
Expand All @@ -46,8 +46,6 @@ public DownloadViewModel(ViewModelManager viewModelManager, DialogManager dialog
_viewModelManager = viewModelManager;
_dialogManager = dialogManager;

Status = DownloadStatus.Enqueued;

_eventRoot.Add(
Progress.WatchProperty(
o => o.Current,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ SettingsService settingsService
public partial IReadOnlyList<Track>? AvailableTracks { get; set; }

[ObservableProperty]
string _selectedContainer = "Mp3";

public partial string SelectedContainer { get; set; } = "Mp3";
public ObservableCollection<Track> SelectedTracks { get; } = [];

public IReadOnlyList<string> AvailableContainers { get; } = ["Mp3"];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -25,15 +25,16 @@ SettingsService settingsService
[ObservableProperty]
public partial Track? Track { get; set; }

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

[ObservableProperty]
public partial string? SelectedDownloadOption { get; set; }

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

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

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

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

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 78f8c20

Please sign in to comment.