From ef509caad123d0be6167cb2254ab9c0a90182c26 Mon Sep 17 00:00:00 2001 From: Royce551 Date: Tue, 3 Aug 2021 12:30:00 -0500 Subject: [PATCH] various changes, maintenance options --- .../FRESHMusicPlayer-Avalonia.csproj | 1 - .../ViewModels/MainWindowViewModel.cs | 4 +- .../ViewModels/MessageBoxViewModel.cs | 28 +++++++++++++ .../ViewModels/SettingsViewModel.cs | 27 +++++++++++++ .../Views/MainWindow.axaml | 4 +- .../Views/MainWindow.axaml.cs | 7 ++-- .../Views/MessageBox.axaml | 7 +++- .../Views/MessageBox.axaml.cs | 40 +++++++++++++++++-- .../Views/Settings.axaml | 10 +++-- .../Views/Settings.axaml.cs | 4 +- 10 files changed, 113 insertions(+), 19 deletions(-) diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/FRESHMusicPlayer-Avalonia.csproj b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/FRESHMusicPlayer-Avalonia.csproj index e2c5f21..0dfe3b9 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/FRESHMusicPlayer-Avalonia.csproj +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/FRESHMusicPlayer-Avalonia.csproj @@ -13,7 +13,6 @@ - diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs index 46a5a58..3d391d8 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs @@ -34,7 +34,7 @@ namespace FRESHMusicPlayer.ViewModels public Player Player { get; private set; } public Timer ProgressTimer { get; private set; } = new(100); public Library Library { get; private set; } - public ConfigurationFile Config { get; private set; } + public ConfigurationFile Config { get; set; } public Track CurrentTrack { get; private set; } public IntegrationHandler Integrations { get; private set; } = new(); public NotificationHandler Notifications { get; private set; } = new(); @@ -755,7 +755,7 @@ namespace FRESHMusicPlayer.ViewModels #region NavBar public void OpenSettingsCommand() { - new Views.Settings().SetThings(Config).Show(Window); + new Views.Settings().SetThings(Config, Library).Show(Window); } public void OpenQueueManagementCommand() diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MessageBoxViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MessageBoxViewModel.cs index 52520ad..5c02319 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MessageBoxViewModel.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MessageBoxViewModel.cs @@ -22,5 +22,33 @@ namespace FRESHMusicPlayer.ViewModels get => content; set => this.RaiseAndSetIfChanged(ref content, value); } + + private bool hasOK = true; + public bool HasOK + { + get => hasOK; + set => this.RaiseAndSetIfChanged(ref hasOK, value); + } + + private bool hasYes = false; + public bool HasYes + { + get => hasYes; + set => this.RaiseAndSetIfChanged(ref hasYes, value); + } + + private bool hasNo = false; + public bool HasNo + { + get => hasNo; + set => this.RaiseAndSetIfChanged(ref hasNo, value); + } + + private bool hasCancel = false; + public bool HasCancel + { + get => hasCancel; + set => this.RaiseAndSetIfChanged(ref hasCancel, value); + } } } diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/SettingsViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/SettingsViewModel.cs index 9304d59..69def91 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/SettingsViewModel.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/SettingsViewModel.cs @@ -15,12 +15,14 @@ using System.Diagnostics; using System.IO; using FRESHMusicPlayer.Handlers; using Avalonia.Controls; +using FRESHMusicPlayer.Views; namespace FRESHMusicPlayer.ViewModels { public class SettingsViewModel : ViewModelBase { public ConfigurationFile Config; + public Library Library; public bool IsRunningOnLinux { get => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); } public bool IsRunningOnMac { get => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); } @@ -149,6 +151,7 @@ namespace FRESHMusicPlayer.ViewModels this.RaisePropertyChanged(nameof(IntegrateMPRIS)); this.RaisePropertyChanged(nameof(MPRISShowCoverArt)); this.RaisePropertyChanged(nameof(CheckForUpdates)); + this.RaisePropertyChanged(nameof(IsRestartNeeded)); } public void ReportIssueCommand() => InterfaceUtils.OpenURL(@"https://github.com/Royce551/FRESHMusicPlayer/issues/new"); @@ -179,6 +182,30 @@ namespace FRESHMusicPlayer.ViewModels this.RaisePropertyChanged(nameof(AutoImportText)); } + public void ResetSettingsCommand() + { + var mainWindow = GetMainWindow().DataContext as MainWindowViewModel; // little messy, maybe figure out how to make this cleaner + mainWindow.Config = new ConfigurationFile(); + Program.Config = mainWindow.Config; + Config = mainWindow.Config; + StartThings(); + } + public async void CleanLibraryCommand() + { + await Task.Run(() => + { + var tracks = Library.Read().Select(x => x.Path).Distinct(); + Library.Nuke(false); + Library.Import(tracks.ToArray()); + }); + } + public async void NukeLibraryCommand() + { + var messageBox = new MessageBox().SetStuff(MainWindowViewModel.ProjectName, "You are about to irreversibly clear your library.", true, false, false, true); + await messageBox.ShowDialog(Window); + if (messageBox.OK) Library.Nuke(); + } + private void CheckRestartNeeded() { if (workingConfig.Language == Config.Language && workingConfig.IntegrateDiscordRPC == Config.IntegrateDiscordRPC && workingConfig.IntegrateMPRIS == Config.IntegrateMPRIS) IsRestartNeeded = false; diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml index 56ea73d..f34fa5c 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml @@ -166,13 +166,13 @@ - + - + diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs index 91d3db0..31d314d 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs @@ -30,10 +30,9 @@ namespace FRESHMusicPlayer.Views #endif DoStuff(); RootPanel = this.FindControl("RootPanel"); - DragDrop.SetAllowDrop(RootPanel, true); - RootPanel.AddHandler(DragDrop.DragEnterEvent, OnDragEnter); - RootPanel.AddHandler(DragDrop.DragOverEvent, OnDragEnter); - RootPanel.AddHandler(DragDrop.DropEvent, OnDragDrop); + SetValue(DragDrop.AllowDropProperty, true); + AddHandler(DragDrop.DragEnterEvent, (s, e) => OnDragEnter(s, e)); + AddHandler(DragDrop.DropEvent, (s, e) => OnDragDrop(s, e)); } private void InitializeComponent() diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MessageBox.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MessageBox.axaml index 2d4a216..92eceb1 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MessageBox.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MessageBox.axaml @@ -4,7 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:FRESHMusicPlayer.ViewModels" mc:Ignorable="d" SizeToContent="Height" Width="450" - x:Class="FRESHMusicPlayer.Views.MessageBox" WindowStartupLocation="CenterOwner" + x:Class="FRESHMusicPlayer.Views.MessageBox" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" CanResize="False" Icon="/Assets/icon.ico" Title="{Binding Title}"> @@ -14,7 +14,10 @@ -