Skip to content

Commit

Permalink
update main window to show listening bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Dyvinia committed Sep 26, 2024
1 parent cbe71d1 commit 38eaea5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Config : SettingsManager<Config> {

public string TemplateL1 { get; set; } = "{title}";
public string TemplateL2 { get; set; } = "by {artist}";
public string TemplateL3 { get; set; } = "{album}";

public string DiscordClientID { get; set; } = "1100233636491563069";

Expand Down
2 changes: 1 addition & 1 deletion Themes/DarkTheme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@
</VisualStateManager.VisualStateGroups>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"/>
<Rectangle x:Name="PART_Track"/>
<Grid x:Name="PART_Indicator" ClipToBounds="true" HorizontalAlignment="Left" Margin="1">
<Grid x:Name="PART_Indicator" ClipToBounds="true" HorizontalAlignment="Left" Margin="0">
<Rectangle x:Name="Indicator" Fill="{TemplateBinding Foreground}"/>
<Rectangle x:Name="Animation" Fill="{TemplateBinding Foreground}" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
Expand Down
18 changes: 11 additions & 7 deletions Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,30 @@
<TextBlock TextWrapping="Wrap" Text="Preview" Foreground="#FFF1F1F1" FontSize="14" Height="20" FontWeight="Bold" VerticalAlignment="Top"/>

<DockPanel Margin="0 4">
<Grid Height="64" Width="64">
<Grid Height="64" Width="64" VerticalAlignment="Top">
<Image x:Name="PreviewArt" Source="https://raw.githubusercontent.com/Dyvinia/PlexampRPC/master/Resources/PlexIconSquare.png" RenderOptions.BitmapScalingMode="Fant" Height="64" Width="64" HorizontalAlignment="Left" DockPanel.Dock="Left" VerticalAlignment="Top">
<Image.OpacityMask>
<VisualBrush>
<VisualBrush.Visual>
<Border Height="{Binding ElementName=PreviewArt, Path=ActualHeight}"
Width="{Binding ElementName=PreviewArt, Path=ActualWidth}"
Background="White" CornerRadius="8" />
Background="White" CornerRadius="4" />
</VisualBrush.Visual>
</VisualBrush>
</Image.OpacityMask>
</Image>
<Image x:Name="PreviewPaused" Source="/Resources/PlexPaused.png" Margin="46,44,-2,-8" RenderOptions.BitmapScalingMode="Fant" Visibility="Collapsed"/>
</Grid>

<StackPanel HorizontalAlignment="Left" DockPanel.Dock="Right" Margin="6 0 0 0">
<TextBlock x:Name="PreviewPlexamp" Text="Plexamp" Foreground="#dddddd" FontSize="14" Height="18" FontWeight="Bold" VerticalAlignment="Top"/>
<TextBlock x:Name="PreviewL1" Text="Title" Foreground="#dddddd" FontSize="14" Height="18" VerticalAlignment="Top"/>
<TextBlock x:Name="PreviewL2" Text="Author" Foreground="#dddddd" FontSize="14" Height="18" VerticalAlignment="Top"/>
<TextBlock x:Name="PreviewL3" Visibility="Collapsed" Text="00:00 elapsed" Foreground="#dddddd" FontSize="14" Height="18" VerticalAlignment="Top"/>
<StackPanel HorizontalAlignment="Left" DockPanel.Dock="Right" Margin="7 -1 0 0">
<TextBlock x:Name="PreviewL1" Text="Title" Foreground="#dddddd" FontSize="14" Height="18" FontWeight="DemiBold" VerticalAlignment="Top" />
<TextBlock x:Name="PreviewL2" Text="Author" Foreground="#dddddd" FontSize="12" Height="18" VerticalAlignment="Top"/>
<TextBlock x:Name="PreviewL3" Text="Album" Foreground="#dddddd" FontSize="12" Height="18" VerticalAlignment="Top"/>
<StackPanel Orientation="Horizontal" x:Name="PreviewTime" Margin="0 3 0 0">
<TextBlock x:Name="PreviewTimeStart" Text="00:00" Foreground="#dddddd" FontSize="12" Height="18" VerticalAlignment="Top" FontFamily="Consolas"/>
<ProgressBar x:Name="PreviewTimeProgress" Width="100" Margin="7 0 7 3" Height="2" Foreground="#dddddd" BorderThickness="0" Value="50"/>
<TextBlock x:Name="PreviewTimeEnd" Text="00:00" Foreground="#dddddd" FontSize="12" Height="18" VerticalAlignment="Top" FontFamily="Consolas"/>
</StackPanel>
</StackPanel>
</DockPanel>
</StackPanel>
Expand Down
39 changes: 24 additions & 15 deletions Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class MainWindow : Window {

public Uri? Address {
get {
if (!String.IsNullOrEmpty(Config.Settings.PlexAddress))
if (!string.IsNullOrEmpty(Config.Settings.PlexAddress))
return new UriBuilder(Config.Settings.PlexAddress).Uri;
else if (UserServerComboBox.SelectedItem != null) {
if (Config.Settings.LocalAddress)
Expand Down Expand Up @@ -133,7 +133,7 @@ public void GetAccountInfo() {
UserIcon.Source = new BitmapImage(new Uri(App.Account?.Thumb ?? "/Resources/PlexIcon.png"));
UserNameText = App.Account?.Title ?? App.Account?.Username ?? "Name";

if (String.IsNullOrEmpty(Config.Settings.PlexAddress)) {
if (string.IsNullOrEmpty(Config.Settings.PlexAddress)) {
if (App.PlexResources != null)
UserServerComboBox.ItemsSource = App.PlexResources;
}
Expand Down Expand Up @@ -233,18 +233,25 @@ private void SetPresence(PresenceData presence) {
LargeImageKey = presence.ArtLink,
LargeImageText = presence.ImageTooltip
},
Buttons = presence.Url != null ? new Button[] {
new() { Label = "More...", Url = presence.Url }
} : null
//Buttons = presence.Url != null ? [
// new() { Label = "More...", Url = presence.Url }
//] : null
});

PreviewArt.Source = new BitmapImage(new Uri(presence.ArtLink));
PreviewL1.Text = presence.Line1;
PreviewL2.Text = presence.Line2;
PreviewL3.Text = presence.ImageTooltip;

TimeSpan t = TimeSpan.FromMilliseconds(presence.TimeOffset);
PreviewL3.Text = $"{String.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds)} elapsed";
PreviewL3.Visibility = Visibility.Visible;
PreviewTime.Visibility = Visibility.Visible;

TimeSpan timeStart = TimeSpan.FromMilliseconds(presence.TimeOffset);
PreviewTimeStart.Text = $"{string.Format("{0:D2}:{1:D2}", timeStart.Minutes, timeStart.Seconds)}";

TimeSpan timeEnd = TimeSpan.FromMilliseconds(presence.Duration);
PreviewTimeEnd.Text = $"{string.Format("{0:D2}:{1:D2}", timeEnd.Minutes, timeEnd.Seconds)}";

PreviewTimeProgress.Value = 100d * presence.TimeOffset / presence.Duration;

PreviewPaused.Visibility = Visibility.Collapsed;
}
Expand All @@ -264,10 +271,9 @@ private void SetPresence(PresenceData presence) {
PreviewArt.Source = new BitmapImage(new Uri(presence.ArtLink));
PreviewL1.Text = presence.Line1;
PreviewL2.Text = presence.Line2;
PreviewL3.Text = presence.ImageTooltip;

PreviewL3.Text = "";
PreviewL3.Visibility = Visibility.Collapsed;

PreviewTime.Visibility = Visibility.Collapsed;
PreviewPaused.Visibility = Visibility.Visible;
}
}
Expand All @@ -284,9 +290,12 @@ private void ResetPresence() {
.Replace("{artist}", "Artist")
.Replace("{album}", "Album");

PreviewL3.Text = "";
PreviewL3.Visibility = Visibility.Collapsed;
PreviewL3.Text = Config.Settings.TemplateL3
.Replace("{title}", "Title")
.Replace("{artist}", "Artist")
.Replace("{album}", "Album");

PreviewTime.Visibility = Visibility.Collapsed;
PreviewPaused.Visibility = Visibility.Collapsed;

App.DiscordClient.ClearPresence();
Expand All @@ -301,10 +310,10 @@ private async Task<string> GetThumbnail(string? thumb) {
if (File.Exists(cacheFile)) {
thumbnailsJson = File.ReadAllText(cacheFile);
try { thumbnails = JsonSerializer.Deserialize<Dictionary<string, string>>(File.ReadAllText(cacheFile))!; }
catch { thumbnails = new(); }
catch { thumbnails = []; }
}
else
thumbnails = new();
thumbnails = [];

string thumbnailLink;
if (thumb is not null && thumbnails.TryGetValue(thumb, out string? value)) {
Expand Down
1 change: 1 addition & 0 deletions Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<TextBlock TextWrapping="Wrap" Text="Template" Foreground="#FFF1F1F1" FontSize="14" Height="20" FontWeight="Bold" VerticalAlignment="Top"/>
<TextBox x:Name="TemplateL1" Margin="0 4 0 0" HorizontalAlignment="Stretch" Text="{Binding Path=(local:Config.TemplateL1), Mode=TwoWay}" ToolTip="{}{title}, {artist}, {album}"/>
<TextBox x:Name="TemplateL2" Margin="0 1 0 0" HorizontalAlignment="Stretch" Text="{Binding Path=(local:Config.TemplateL2), Mode=TwoWay}" ToolTip="{}{title}, {artist}, {album}"/>
<TextBox x:Name="TemplateL3" Margin="0 1 0 0" HorizontalAlignment="Stretch" Text="{Binding Path=(local:Config.TemplateL3), Mode=TwoWay}" ToolTip="{}{title}, {artist}, {album}"/>
</StackPanel>
</StackPanel>
</Grid>
Expand Down

0 comments on commit 38eaea5

Please sign in to comment.