This commit is contained in:
Royce551 2021-03-25 22:33:22 -05:00
parent 3bd50a38a0
commit a5bcc4db27
9 changed files with 105 additions and 42 deletions

View file

@ -6,6 +6,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using FRESHMusicPlayer.Handlers;
namespace FRESHMusicPlayer
{
@ -23,11 +24,15 @@ namespace FRESHMusicPlayer
private Player player;
void App_Startup(object sender, StartupEventArgs e )
{
LoggingHandler.Log("Handling configuration...");
Config = ConfigurationHandler.Read();
player = new Player { Volume = Config.Volume };
if (Config.Language != "automatic") System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Config.Language);
ChangeSkin(Config.Theme);
LoggingHandler.Log("Handling command line args...");
if (e.Args.Length > 0)
{
var args = e.Args.Where(x => x.Contains('.'));

View file

@ -125,6 +125,7 @@
<Compile Include="Handlers\Integrations\DiscordIntegration.cs" />
<Compile Include="Handlers\Integrations\IPlaybackIntegration.cs" />
<Compile Include="Handlers\Integrations\SMTCIntegration.cs" />
<Compile Include="Handlers\LoggingHandler.cs" />
<Compile Include="Handlers\Notifications\Notification.cs" />
<Compile Include="Handlers\PlaytimeTrackingHandler.cs" />
<Compile Include="Handlers\UpdateHandler.cs" />

View file

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FRESHMusicPlayer.Handlers
{
public class LoggingHandler
{
[Conditional("DEBUG")]
public static void Log(string message)
{
#if DEBUG
var line = $"[{DateTime.Now:T}] {message}";
Console.WriteLine(line);
Console.ResetColor();
var logFilePath = "log.txt";
using (var sw = File.AppendText(logFilePath))
{
sw.WriteLine(line);
}
#endif
}
}
}

View file

@ -66,6 +66,7 @@ namespace FRESHMusicPlayer
private IPlaybackIntegration discordIntegration;
public MainWindow(Player player, string[] initialFile = null)
{
LoggingHandler.Log("Starting main window...");
Player = player;
InitializeComponent();
Player.SongChanged += Player_SongChanged;
@ -77,6 +78,7 @@ namespace FRESHMusicPlayer
Interval = 1000
};
progressTimer.Tick += ProgressTimer_Tick;
LoggingHandler.Log("Reading library...");
LiteDatabase library;
try
{
@ -111,7 +113,8 @@ namespace FRESHMusicPlayer
TracksTab.Visibility = ArtistsTab.Visibility = AlbumsTab.Visibility = PlaylistsTab.Visibility = Visibility.Collapsed;
SearchButton.Visibility = QueueManagementButton.Visibility = Visibility.Collapsed;
}
LoggingHandler.Log("Ready to go!");
if (initialFile != null)
{
Player.Queue.Add(initialFile);
@ -203,6 +206,7 @@ namespace FRESHMusicPlayer
}
public void ShowAuxilliaryPane(AuxiliaryPane pane, int width = 235, bool openleft = false)
{
LoggingHandler.Log($"Showing pane --> {pane}");
if (SelectedAuxiliaryPane == pane)
{
HideAuxilliaryPane();
@ -350,9 +354,10 @@ namespace FRESHMusicPlayer
discordIntegration?.Update(CurrentTrack, status);
}
}
#region Tabs
private void ChangeTabs(Menu tab, string search = null)
{
LoggingHandler.Log($"Changing tabs -> {tab}");
SelectedMenu = tab;
TextBlock tabLabel;
switch (SelectedMenu)
@ -388,9 +393,6 @@ namespace FRESHMusicPlayer
}
#endregion
#endregion
#region Events
#region Player
private void Player_SongStopped(object sender, EventArgs e)
@ -401,6 +403,8 @@ namespace FRESHMusicPlayer
CoverArtBox.Source = null;
SetIntegrations(PlaybackStatus.Stopped);
SetCoverArtVisibility(false);
LoggingHandler.Log("Stopping!");
}
private void Player_SongChanged(object sender, EventArgs e)
@ -439,6 +443,8 @@ namespace FRESHMusicPlayer
PlayPauseMethod();
PauseAfterCurrentTrack = false;
}
LoggingHandler.Log("Changing tracks");
}
private void Player_SongException(object sender, PlaybackExceptionEventArgs e)
{

View file

@ -7,11 +7,11 @@
xmlns:local="clr-namespace:FRESHMusicPlayer.Pages.Library"
mc:Ignorable="d"
d:DesignHeight="372" d:DesignWidth="694"
Title="LibraryPage" Unloaded="Page_Unloaded" DragEnter="Page_DragEnter" Drop="Page_Drop" AllowDrop="True">
Title="LibraryPage" Unloaded="Page_Unloaded" DragEnter="Page_DragEnter" Drop="Page_Drop" AllowDrop="True" Loaded="Page_Loaded">
<Grid Background="{StaticResource BackgroundColor}">
<Grid.RowDefinitions>
<RowDefinition Height="23*"/>
<RowDefinition x:Name="DetailsPane" Height="45px"/>
<RowDefinition x:Name="DetailsPane" Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="LeftSide" Width="222"/>
@ -35,15 +35,35 @@
/>
<ListBox x:Name="CategoryPanel" Margin="0,0,5,0" Background="{StaticResource SecondaryColor}" Foreground="{StaticResource PrimaryTextColor}" Grid.RowSpan="2" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" FontSize="14" VirtualizingPanel.IsVirtualizing="True" BorderBrush="{x:Null}" SelectionChanged="CategoryPanel_SelectionChanged" BorderThickness="0" ScrollViewer.PanningMode="Both"/>
<Grid x:Name="InfoPanel" Grid.Column="1" Grid.Row="2" Margin="0" Background="{StaticResource BackgroundColor}">
<Grid x:Name="InfoPanel" Grid.Column="1" Grid.Row="2" Margin="0" Height="45" Background="{StaticResource BackgroundColor}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="InfoLabel" Text="99 Tracks ・ 10:00:00" Grid.Column="0" Foreground="{StaticResource SecondaryTextColor}" FontSize="12" Margin="10" VerticalAlignment="Center"/>
<Button x:Name="QueueAllButton" Content="{x:Static resx:Resources.LIBRARY_ENQUEUEALL}" Grid.Column="1" Margin="10,10,0,10" Padding="5,1" Click="QueueAllButton_Click"/>
<Button x:Name="PlayAllButton" Content="{x:Static resx:Resources.LIBRARY_PLAYALL}" Grid.Column="2" Margin="10" Padding="5,1" Click="PlayAllButton_Click"/>
<!--<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>-->
<!--<DockPanel Grid.Column="0" Margin="10,5,5,5" LastChildFill="False">
<TextBlock DockPanel.Dock="Left" Text="Sort" FontSize="14" Foreground="{StaticResource PrimaryTextColor}"/>
<ComboBox DockPanel.Dock="Left" Margin="10,0,0,0" Width="120">
<ComboBoxItem Content="{x:Static resx:Resources.TAGEDITOR_TITLE}"/>
<ComboBoxItem Content="{x:Static resx:Resources.TAGEDITOR_ARTIST}"/>
<ComboBoxItem Content="{x:Static resx:Resources.TRACKINFO_ALBUM}"/>
<ComboBoxItem Content="{x:Static resx:Resources.TAGEDITOR_TRACKNUM}"/>
<ComboBoxItem Content="Length"/>
</ComboBox>
<ComboBox DockPanel.Dock="Left" Margin="10,0,0,0" Width="50">
<ComboBoxItem Content="↑"/>
<ComboBoxItem Content="↓"/>
</ComboBox>
</DockPanel>-->
<TextBlock x:Name="InfoLabel" Text="99 Tracks ・ 10:00:00" Grid.Column="0" Foreground="{StaticResource SecondaryTextColor}" Grid.Row="2" FontSize="12" Margin="10" VerticalAlignment="Center"/>
<Button x:Name="QueueAllButton" Content="{x:Static resx:Resources.LIBRARY_ENQUEUEALL}" Grid.Column="1" Grid.Row="2" Margin="10,10,0,10" Padding="5,1" Click="QueueAllButton_Click"/>
<Button x:Name="PlayAllButton" Content="{x:Static resx:Resources.LIBRARY_PLAYALL}" Grid.Column="2" Grid.Row="2" Margin="10" Padding="5,1" Click="PlayAllButton_Click"/>
</Grid>
</Grid>

View file

@ -16,8 +16,6 @@ namespace FRESHMusicPlayer.Pages.Library
/// </summary>
public partial class LibraryPage : Page
{
private Menu previousPage;
private readonly MainWindow window;
public LibraryPage(MainWindow window, string search = null)
{
@ -32,7 +30,7 @@ namespace FRESHMusicPlayer.Pages.Library
}
}
public void LoadLibrary()
public async void LoadLibrary() // TODO: figure out how to make this not async void
{
TracksPanel.Items.Clear();
CategoryPanel.Items.Clear();
@ -40,20 +38,20 @@ namespace FRESHMusicPlayer.Pages.Library
switch (window.SelectedMenu) // all of this stuff is here so that i can avoid copying and pasting the same page thrice, maybe there's a better way?
{
case Menu.Tracks:
ShowTracks();
await ShowTracks();
break;
case Menu.Artists:
ShowArtists();
await ShowArtists();
break;
case Menu.Albums:
ShowAlbums();
await ShowAlbums();
break;
case Menu.Playlists:
ShowPlaylists();
await ShowPlaylists();
break;
}
}
public async void ShowTracks()
public async Task ShowTracks()
{
LeftSide.Width = new GridLength(0);
int length = 0;
@ -72,7 +70,7 @@ namespace FRESHMusicPlayer.Pages.Library
InfoLabel.Visibility = Visibility.Visible;
InfoLabel.Text = $@"{Properties.Resources.MAINWINDOW_TRACKS}: {TracksPanel.Items.Count} ・ {Math.Floor(lengthTimeSpan.TotalHours)}:{lengthTimeSpan:mm}:{lengthTimeSpan:ss}";
}
public async void ShowArtists()
public async Task ShowArtists()
{
await Task.Run(() =>
{
@ -83,7 +81,7 @@ namespace FRESHMusicPlayer.Pages.Library
}
});
}
public async void ShowAlbums()
public async Task ShowAlbums()
{
await Task.Run(() =>
{
@ -94,7 +92,7 @@ namespace FRESHMusicPlayer.Pages.Library
}
});
}
public async void ShowPlaylists()
public async Task ShowPlaylists()
{
var x = window.Library.Database.GetCollection<DatabasePlaylist>("playlists").Query().OrderBy("Name").ToList();
await Task.Run(() =>
@ -107,7 +105,7 @@ namespace FRESHMusicPlayer.Pages.Library
}
});
}
public async void ShowTracksforArtist(string selectedItem)
public async Task ShowTracksforArtist(string selectedItem)
{
TracksPanel.Items.Clear();
int length = 0;
@ -122,7 +120,7 @@ namespace FRESHMusicPlayer.Pages.Library
InfoLabel.Visibility = Visibility.Visible;
InfoLabel.Text = $"{Properties.Resources.MAINWINDOW_TRACKS}: {TracksPanel.Items.Count} ・ {new TimeSpan(0, 0, 0, length):hh\\:mm\\:ss}";
}
public async void ShowTracksforAlbum(string selectedItem)
public async Task ShowTracksforAlbum(string selectedItem)
{
TracksPanel.Items.Clear();
int length = 0;
@ -137,7 +135,7 @@ namespace FRESHMusicPlayer.Pages.Library
InfoLabel.Visibility = Visibility.Visible;
InfoLabel.Text = $"{Properties.Resources.MAINWINDOW_TRACKS}: {TracksPanel.Items.Count} ・ {new TimeSpan(0, 0, 0, length):hh\\:mm\\:ss}";
}
public async void ShowTracksforPlaylist(string selectedItem)
public async Task ShowTracksforPlaylist(string selectedItem)
{
TracksPanel.Items.Clear();
int length = 0;
@ -152,24 +150,29 @@ namespace FRESHMusicPlayer.Pages.Library
InfoLabel.Visibility = Visibility.Visible;
InfoLabel.Text = $"{Properties.Resources.MAINWINDOW_TRACKS}: {TracksPanel.Items.Count} ・ {new TimeSpan(0, 0, 0, length):hh\\:mm\\:ss}";
}
private void CategoryPanel_SelectionChanged(object sender, SelectionChangedEventArgs e)
private async void CategoryPanel_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItem = (string)CategoryPanel.SelectedItem;
if (selectedItem == null) return;
if (window.SelectedMenu == Menu.Artists) ShowTracksforArtist(selectedItem);
else if (window.SelectedMenu == Menu.Playlists) ShowTracksforPlaylist(selectedItem);
else ShowTracksforAlbum(selectedItem);
if (window.SelectedMenu == Menu.Artists) await ShowTracksforArtist(selectedItem);
else if (window.SelectedMenu == Menu.Playlists) await ShowTracksforPlaylist(selectedItem);
else await ShowTracksforAlbum(selectedItem);
}
private void MainWindow_TabChanged(object sender, string e)
//private void MainWindow_TabChanged(object sender, string e)
//{
// if (previousPage == Menu.Tracks) LeftSide.Width = new GridLength(222);
// LoadLibrary();
// if (e != null)
// {
// Thread.Sleep(10);
// CategoryPanel.SelectedItem = e;
// }
// previousPage = window.SelectedMenu;
//}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
if (previousPage == Menu.Tracks) LeftSide.Width = new GridLength(222);
LoadLibrary();
if (e != null)
{
Thread.Sleep(10);
CategoryPanel.SelectedItem = e;
}
previousPage = window.SelectedMenu;
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
@ -207,5 +210,7 @@ namespace FRESHMusicPlayer.Pages.Library
window.Player.Queue.Add(tracks);
window.Player.PlayMusic();
}
}
}

View file

@ -25,7 +25,7 @@
</Grid.ColumnDefinitions>
<TextBox x:Name="SearchBox" Grid.Row="0" TextWrapping="Wrap" FontSize="14" Margin="10,5" BorderBrush="{StaticResource SecondaryTextColor}" Foreground="{StaticResource PrimaryTextColor}" TextChanged="SearchBox_TextChanged" TabIndex="0">
<TextBox.Style>
<Style TargetType="TextBox" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Style.Resources>
<VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None">
<VisualBrush.Visual>

View file

@ -56,7 +56,7 @@
<ComboBoxItem Content="English"/>
<ComboBoxItem Content="German"/>
<ComboBoxItem Content="Vietnamese"/>
<ComboBoxItem Content="Portuguese"/>
<ComboBoxItem Content="Portuguese"/>
<ComboBoxItem Content="Turkish"/>
<ComboBoxItem Content="Dutch"/>
</ComboBox>

View file

@ -325,8 +325,6 @@
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="MinWidth" Value="120"/>
<Setter Property="MinHeight" Value="20"/>
<Setter Property="BorderBrush" Value="{StaticResource ForegroundColor}"/>
<Setter Property="Foreground" Value="{StaticResource PrimaryTextColor}"/>
<Setter Property="Template">