Stats panel in settings
This commit is contained in:
parent
62a3220f7f
commit
0be28ab205
@ -20,6 +20,17 @@ using MpcNET.Types;
|
|||||||
|
|
||||||
namespace unison
|
namespace unison
|
||||||
{
|
{
|
||||||
|
public class Statistics
|
||||||
|
{
|
||||||
|
public int Songs { get; set; }
|
||||||
|
public int Albums { get; set; }
|
||||||
|
public int Artists { get; set; }
|
||||||
|
public string TotalPlaytime { get; set; }
|
||||||
|
public string Uptime { get; set; }
|
||||||
|
public string TotalTimePlayed { get; set; }
|
||||||
|
public string DatabaseUpdate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class MPDHandler
|
public class MPDHandler
|
||||||
{
|
{
|
||||||
private bool _connected;
|
private bool _connected;
|
||||||
@ -36,6 +47,7 @@ namespace unison
|
|||||||
private MpdStatus _currentStatus;
|
private MpdStatus _currentStatus;
|
||||||
private IMpdFile _currentSong;
|
private IMpdFile _currentSong;
|
||||||
private BitmapFrame _cover;
|
private BitmapFrame _cover;
|
||||||
|
public Statistics _stats;
|
||||||
private readonly System.Timers.Timer _elapsedTimer;
|
private readonly System.Timers.Timer _elapsedTimer;
|
||||||
private DispatcherTimer _retryTimer;
|
private DispatcherTimer _retryTimer;
|
||||||
|
|
||||||
@ -58,6 +70,8 @@ namespace unison
|
|||||||
|
|
||||||
Initialize(null, null);
|
Initialize(null, null);
|
||||||
|
|
||||||
|
_stats = new Statistics();
|
||||||
|
|
||||||
_retryTimer = new DispatcherTimer();
|
_retryTimer = new DispatcherTimer();
|
||||||
_retryTimer.Interval = TimeSpan.FromSeconds(5);
|
_retryTimer.Interval = TimeSpan.FromSeconds(5);
|
||||||
_retryTimer.Tick += Initialize;
|
_retryTimer.Tick += Initialize;
|
||||||
@ -417,6 +431,7 @@ namespace unison
|
|||||||
public MpdStatus GetStatus() => _currentStatus;
|
public MpdStatus GetStatus() => _currentStatus;
|
||||||
public BitmapFrame GetCover() => _cover;
|
public BitmapFrame GetCover() => _cover;
|
||||||
public string GetVersion() => _version;
|
public string GetVersion() => _version;
|
||||||
|
public Statistics GetStats() => _stats;
|
||||||
public double GetCurrentTime() => _currentTime;
|
public double GetCurrentTime() => _currentTime;
|
||||||
|
|
||||||
public bool IsConnected() => _connected;
|
public bool IsConnected() => _connected;
|
||||||
@ -479,5 +494,25 @@ namespace unison
|
|||||||
CommandList commandList = new CommandList(new IMpcCommand<object>[] { new ClearCommand(), new AddCommand(Uri), new PlayCommand(0) });
|
CommandList commandList = new CommandList(new IMpcCommand<object>[] { new ClearCommand(), new AddCommand(Uri), new PlayCommand(0) });
|
||||||
SendCommand(commandList);
|
SendCommand(commandList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async void QueryStats()
|
||||||
|
{
|
||||||
|
Dictionary<string, string> response = await SafelySendCommandAsync(new StatsCommand());
|
||||||
|
|
||||||
|
_stats.Songs = int.Parse(response["songs"]);
|
||||||
|
_stats.Albums = int.Parse(response["albums"]);
|
||||||
|
_stats.Artists = int.Parse(response["artists"]);
|
||||||
|
|
||||||
|
TimeSpan time;
|
||||||
|
time = TimeSpan.FromSeconds(int.Parse(response["uptime"]));
|
||||||
|
_stats.Uptime = time.ToString(@"dd\:hh\:mm\:ss");
|
||||||
|
time = TimeSpan.FromSeconds(int.Parse(response["db_playtime"]));
|
||||||
|
_stats.TotalPlaytime = time.ToString(@"dd\:hh\:mm\:ss");
|
||||||
|
time = TimeSpan.FromSeconds(int.Parse(response["playtime"]));
|
||||||
|
_stats.TotalTimePlayed = time.ToString(@"dd\:hh\:mm\:ss");
|
||||||
|
|
||||||
|
DateTime date = new DateTime(1970, 1, 1).AddSeconds(int.Parse(response["db_update"])).ToLocalTime();
|
||||||
|
_stats.DatabaseUpdate = date.ToString("dd-MM-yyyy @ HH:mm");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -135,6 +135,9 @@ namespace unison
|
|||||||
DefaultState();
|
DefaultState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_mpd.QueryStats();
|
||||||
|
_settingsWin.UpdateStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DefaultState(bool LostConnection = false)
|
private void DefaultState(bool LostConnection = false)
|
||||||
|
@ -46,6 +46,29 @@
|
|||||||
</DockPanel>
|
</DockPanel>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem Header="Stats">
|
||||||
|
<DockPanel Margin="8">
|
||||||
|
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
|
||||||
|
<GroupBox.Header>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<emoji:TextBlock Text="📊 Stats"/>
|
||||||
|
</StackPanel>
|
||||||
|
</GroupBox.Header>
|
||||||
|
<Grid VerticalAlignment="Top">
|
||||||
|
<TextBlock>
|
||||||
|
<Run Text="Songs: "></Run><Run x:Name="StatSong"/><LineBreak/>
|
||||||
|
<Run Text="Albums: "></Run><Run x:Name="StatAlbum"/><LineBreak/>
|
||||||
|
<Run Text="Artists: "></Run><Run x:Name="StatArtist"/><LineBreak/>
|
||||||
|
<Run Text="Total playtime: "></Run><Run x:Name="StatTotalPlaytime"/><LineBreak/><LineBreak/>
|
||||||
|
<Run Text="MPD uptime: "></Run><Run x:Name="StatUptime"/><LineBreak/>
|
||||||
|
<Run Text="Total time played: "></Run><Run x:Name="StatTotalTimePlayed"/><LineBreak/>
|
||||||
|
<Run Text="Last database update: "></Run><Run x:Name="StatDatabaseUpdate"/>
|
||||||
|
</TextBlock>
|
||||||
|
</Grid>
|
||||||
|
</GroupBox>
|
||||||
|
</DockPanel>
|
||||||
|
</TabItem>
|
||||||
|
|
||||||
<TabItem Header="Snapcast">
|
<TabItem Header="Snapcast">
|
||||||
<DockPanel Margin="8">
|
<DockPanel Margin="8">
|
||||||
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
|
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
|
||||||
|
@ -88,6 +88,18 @@ namespace unison
|
|||||||
SnapcastPort.Text = (string)Application.Current.FindResource("snapcastPort");
|
SnapcastPort.Text = (string)Application.Current.FindResource("snapcastPort");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateStats()
|
||||||
|
{
|
||||||
|
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||||
|
StatSong.Text = mpd.GetStats().Songs.ToString();
|
||||||
|
StatAlbum.Text = mpd.GetStats().Albums.ToString();
|
||||||
|
StatArtist.Text = mpd.GetStats().Artists.ToString();
|
||||||
|
StatTotalPlaytime.Text = mpd.GetStats().TotalPlaytime.ToString();
|
||||||
|
StatUptime.Text = mpd.GetStats().Uptime.ToString();
|
||||||
|
StatTotalTimePlayed.Text = mpd.GetStats().TotalTimePlayed.ToString();
|
||||||
|
StatDatabaseUpdate.Text = mpd.GetStats().DatabaseUpdate.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public void SaveSettings()
|
public void SaveSettings()
|
||||||
{
|
{
|
||||||
Properties.Settings.Default.mpd_host = MpdHost.Text;
|
Properties.Settings.Default.mpd_host = MpdHost.Text;
|
||||||
|
Loading…
Reference in New Issue
Block a user