From 138b8c9cf77e2a34a1357259c5590886dfd506d8 Mon Sep 17 00:00:00 2001 From: Royce551 Date: Sun, 9 May 2021 20:04:58 -0500 Subject: [PATCH] Avalonia:Volume persistence --- .../Configuration/ConfigurationFile.cs | 4 +++- .../ViewModels/MainWindowViewModel.cs | 22 ++++++++++++++++++- .../MainWindow.xaml.cs | 14 ++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Handlers/Configuration/ConfigurationFile.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Handlers/Configuration/ConfigurationFile.cs index b36d956..4012aff 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Handlers/Configuration/ConfigurationFile.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Handlers/Configuration/ConfigurationFile.cs @@ -35,7 +35,9 @@ namespace FRESHMusicPlayer.Handlers.Configuration /// /// The volume that FMP was set to before closing /// - public int Volume { get; set; } = 100; + public float Volume { get; set; } = 1f; + public string FilePath { get; set; } + public double FilePosition { get; set; } = 0; /// /// The last tab FMP was on before closing /// diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs index bbc046e..9dfc327 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs @@ -22,13 +22,14 @@ namespace FRESHMusicPlayer.ViewModels { public class MainWindowViewModel : ViewModelBase { - public Player Player { get; private set; } = new(); + 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 MainWindowViewModel() { + Player = new(); StartThings(); var library = new LiteDatabase($"Filename=\"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer", "database.fdb2")}\";Connection=shared"); Library = new Library(library); @@ -296,11 +297,30 @@ namespace FRESHMusicPlayer.ViewModels public async void StartThings() { Config = await ConfigurationHandler.Read(); + Volume = Config?.Volume ?? 1f; + var args = Environment.GetCommandLineArgs(); + if (args.Length != 0) + { + Player.Queue.Add(args); + Player.PlayMusic(); + Player.CurrentTime.Add(TimeSpan.FromSeconds(Config.FilePosition)); + } + else + { + if (!string.IsNullOrEmpty(Config.FilePath)) + { + Player.PlayMusic(Config.FilePath); + Player.CurrentTime.Add(TimeSpan.FromSeconds(Config.FilePosition)); + } + } } public async void CloseThings() { Library?.Database.Dispose(); + Config.Volume = Volume; + Config.FilePath = Config.FilePath; + if (Player.FileLoaded) Config.FilePosition = Player.CurrentTime.TotalSeconds; await ConfigurationHandler.Write(Config); } diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/MainWindow.xaml.cs b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/MainWindow.xaml.cs index dd04cbc..0f1ac6e 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/MainWindow.xaml.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/MainWindow.xaml.cs @@ -20,6 +20,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; @@ -672,6 +673,19 @@ namespace FRESHMusicPlayer case Key.F4: Topmost = !Topmost; break; + case Key.F12: + if (WindowStyle == WindowStyle.SingleBorderWindow) + { + WindowStyle = WindowStyle.None; + WindowState = WindowState.Maximized; + + } + else + { + WindowState = WindowState.Normal; + WindowStyle = WindowStyle.SingleBorderWindow; + } + break; } }