Skip to content

Commit

Permalink
update app icon, implement #4 and fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
PKBeam committed Apr 29, 2023
1 parent bc82ed4 commit 6d77146
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 46 deletions.
16 changes: 10 additions & 6 deletions AMWin-RichPresence/AMWin-RichPresence.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
<RootNamespace>AMWin_RichPresence</RootNamespace>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\AppleMusicTray.ico</ApplicationIcon>
<ApplicationIcon>Resources\AMWinRP.ico</ApplicationIcon>
<AssemblyVersion>1.0</AssemblyVersion>
<FileVersion>1.1.0</FileVersion>
<FileVersion>1.1.1</FileVersion>
</PropertyGroup>

<ItemGroup>
<None Remove="Resources\AppleMusic64x.png" />
<None Remove="Resources\AppleMusicTray.ico" />
<None Remove="Resources\AMWinRP-128x.png" />
<None Remove="Resources\AMWinRP.ico" />
</ItemGroup>

<ItemGroup>
<Content Include="Resources\AMWinRP.ico" />
</ItemGroup>

<ItemGroup>
Expand All @@ -25,8 +29,8 @@
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\AppleMusic64x.png" />
<Resource Include="Resources\AppleMusicTray.ico" />
<Resource Include="Resources\AMWinRP-128x.png" />
<Resource Include="Resources\AMWinRP.ico" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions AMWin-RichPresence/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<setting name="ShowAppleMusicIcon" serializeAs="String">
<value>True</value>
</setting>
<setting name="EnableDiscordRP" serializeAs="String">
<value>True</value>
</setting>
</AMWin_RichPresence.Properties.Settings>
</userSettings>
</configuration>
12 changes: 8 additions & 4 deletions AMWin-RichPresence/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ public partial class App : Application {
public App() {

// start Discord RPC
discordClient = new(Constants.DiscordClientID, enabled: false, subtitleOptions: (AppleMusicDiscordClient.RPSubtitleDisplayOptions)AMWin_RichPresence.Properties.Settings.Default.RPSubtitleChoice);
var subtitleOptions = (AppleMusicDiscordClient.RPSubtitleDisplayOptions)AMWin_RichPresence.Properties.Settings.Default.RPSubtitleChoice;
discordClient = new(Constants.DiscordClientID, enabled: false, subtitleOptions: subtitleOptions);

// start Last.FM scrobbler
scrobblerClient = new AppleMusicScrobbler();
scrobblerClient.init();

// start scraper
// start Apple Music scraper
amScraper = new(Constants.RefreshPeriod, (newInfo) => {
// disable RPC when Apple Music is paused or not open
if (newInfo != null && ((AppleMusicInfo)newInfo).HasSong && !((AppleMusicInfo)newInfo).IsPaused) {
bool userEnabledRP = AMWin_RichPresence.Properties.Settings.Default.EnableDiscordRP;
// disable RPC when requested by the user, and also when Apple Music is paused/not open
if (userEnabledRP && newInfo != null && ((AppleMusicInfo)newInfo).HasSong && !((AppleMusicInfo)newInfo).IsPaused) {
discordClient.Enable();
discordClient.SetPresence((AppleMusicInfo)newInfo, AMWin_RichPresence.Properties.Settings.Default.ShowAppleMusicIcon);
scrobblerClient.Scrobbleit((AppleMusicInfo)newInfo, scrobblerClient.GetLastFmScrobbler());
Expand Down
6 changes: 3 additions & 3 deletions AMWin-RichPresence/AppleMusicScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Print() {
internal class AppleMusicScraper {

public delegate void RefreshHandler(AppleMusicInfo? newInfo);

Timer timer;

RefreshHandler refreshHandler;
Expand Down Expand Up @@ -121,8 +121,8 @@ public void Refresh(object? source, ElapsedEventArgs? e) {
var currentTimeElement = amWinChild.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "CurrentTime"));
var remainingDurationElement = amWinChild.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "Duration"));

var currentTime = ParseTimeString(currentTimeElement.Current.Name);
var remainingDuration = ParseTimeString(remainingDurationElement.Current.Name);
var currentTime = ParseTimeString(currentTimeElement?.Current.Name ?? "0:00");
var remainingDuration = ParseTimeString(remainingDurationElement?.Current.Name ?? "0:00");

// check if the song is paused or not
var playPauseButton = amWinChild.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "TransportControl_PlayPauseStop"));
Expand Down
16 changes: 8 additions & 8 deletions AMWin-RichPresence/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions AMWin-RichPresence/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="AppleMusic64x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\AppleMusic64x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="AMWinRP" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\AMWinRP.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="AppleMusicTray" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\AppleMusicTray.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="AMWinRP-128x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\AMWinRP-128x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
14 changes: 13 additions & 1 deletion AMWin-RichPresence/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions AMWin-RichPresence/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
<Setting Name="ShowAppleMusicIcon" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="EnableDiscordRP" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
Binary file added AMWin-RichPresence/Resources/AMWinRP-128x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AMWin-RichPresence/Resources/AMWinRP.ico
Binary file not shown.
Binary file removed AMWin-RichPresence/Resources/AppleMusic64x.png
Binary file not shown.
Binary file removed AMWin-RichPresence/Resources/AppleMusicTray.ico
Binary file not shown.
46 changes: 27 additions & 19 deletions AMWin-RichPresence/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
xmlns:local="clr-namespace:AMWin_RichPresence"
xmlns:properties="clr-namespace:AMWin_RichPresence.Properties"
mc:Ignorable="d"
Icon="/Resources/AppleMusicTray.ico"
Title="AMWin-RichPresence" Height="360" Width="440" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
Icon="/Resources/AMWinRP.ico"
Title="AMWin-RichPresence" Height="385" Width="450" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Grid Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<DockPanel>
<Border DockPanel.Dock="Top" Height="64" Padding="10" Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderThickness="0 0 0 1.5">
<StackPanel Orientation="Horizontal">
<Image Margin="0 0 10 0" Source="/Resources/AppleMusic64x.png"/>
<Image Margin="0 0 10 0" Source="/Resources/AMWinRP-128x.png"/>
<StackPanel Orientation="Vertical">
<TextBlock VerticalAlignment="Center" FontWeight="SemiBold" FontSize="18">AMWin-Rich Presence</TextBlock>
<TextBlock x:Name="TextBlock_VersionString" VerticalAlignment="Bottom" FontSize="11">v1.0.0-dev</TextBlock>
Expand All @@ -23,7 +23,7 @@
<StackPanel Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="160"/>
<ColumnDefinition Width="120"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
Expand All @@ -36,34 +36,42 @@
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Grid.Column="0">Run when Windows starts</TextBlock>
<CheckBox Grid.Row="0" Grid.Column="1" x:Name="CheckBox_RunOnStartup" Margin="0 2 0 0" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=RunOnStartup, Mode=TwoWay}" Click="CheckBox_RunOnStartup_Click"/>

<TextBlock Grid.Row="1" Grid.Column="0">Apple Music icon in status</TextBlock>
<CheckBox Grid.Row="1" Grid.Column="1" x:Name="CheckBox_ShowAppleMusicIcon" Margin="0 2 0 0" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=ShowAppleMusicIcon, Mode=TwoWay}" Click="CheckBox_ShowAppleMusicIcon_Click"></CheckBox>
<TextBlock Grid.Row="1" Grid.Column="0">Enable Discord Rich Presence</TextBlock>
<CheckBox Grid.Row="1" Grid.Column="1" x:Name="CheckBox_EnableDiscordRP" Margin="0,2,0,0" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=EnableDiscordRP, Mode=TwoWay}" Click="CheckBox_EnableDiscordRP_Click" HorizontalAlignment="Right" Width="120"/>

<TextBlock Grid.Row="2" Grid.Column="0">Apple Music icon in status</TextBlock>
<CheckBox Grid.Row="2" Grid.Column="1" x:Name="CheckBox_ShowAppleMusicIcon" Margin="0 2 0 0" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=ShowAppleMusicIcon, Mode=TwoWay}" Click="CheckBox_ShowAppleMusicIcon_Click"></CheckBox>

<TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="0 0 0 2">Rich Presence subtitle</TextBlock>
<ComboBox Grid.Row="2" Grid.Column="1" x:Name="ComboBox_RPSubtitleChoice" SelectedIndex="{Binding Source={x:Static properties:Settings.Default}, Path=RPSubtitleChoice, Mode=TwoWay}" Height="22" SelectionChanged="ComboBox_RPSubtitleChoice_SelectionChanged">
<TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Margin="0 0 0 2">Rich Presence subtitle</TextBlock>
<ComboBox Grid.Row="3" Grid.Column="1" x:Name="ComboBox_RPSubtitleChoice" SelectedIndex="{Binding Source={x:Static properties:Settings.Default}, Path=RPSubtitleChoice, Mode=TwoWay}" Height="22" SelectionChanged="ComboBox_RPSubtitleChoice_SelectionChanged">
<!-- The order of these items matters! (check the enum in AppleMusicDiscordClient.cs) -->
<ComboBoxItem>Artist and album</ComboBoxItem>
<ComboBoxItem>Artist only</ComboBoxItem>
<ComboBoxItem>Album only</ComboBoxItem>
</ComboBox>

<TextBlock Grid.Row="3" VerticalAlignment="Center" FontWeight="Bold" Padding="0 3 0 0">Last.FM settings</TextBlock>
<TextBlock Grid.Row="4" VerticalAlignment="Center" FontWeight="Bold" Padding="0 3 0 0">Last.FM settings</TextBlock>

<TextBlock Grid.Row="5" Grid.Column="0" VerticalAlignment="Center" Padding="10 0 0 0">API Key</TextBlock>
<TextBox Grid.Row="5" Grid.Column="1" x:Name="LastfmAPIKey" Text="{Binding Source={x:Static properties:Settings.Default}, Path=Default.LastfmAPIKey}" TextWrapping="Wrap" Margin="0,0,-121,0" FontFamily="Lucida Sans Typewriter" VerticalAlignment="Center"/>

<TextBlock Grid.Row="6" Grid.Column="0" VerticalAlignment="Center" Padding="10 0 0 0">API Secret</TextBlock>
<TextBox Grid.Row="6" Grid.Column="1" x:Name="LastfmSecret" Text="{Binding Source={x:Static properties:Settings.Default}, Path=Default.LastfmSecret}" TextWrapping="Wrap" Margin="0,0,-121,0" FontFamily="Lucida Sans Typewriter" VerticalAlignment="Center"/>

<TextBlock Grid.Row="7" Grid.Column="0" VerticalAlignment="Center" Padding="10 0 0 0">Username</TextBlock>
<TextBox Grid.Row="7" Grid.Column="1" x:Name="LastfmUsername" Text="{Binding Source={x:Static properties:Settings.Default}, Path=Default.LastfmUsername}" TextWrapping="Wrap" Margin="0,0,-121,0" VerticalAlignment="Center"/>

<TextBlock Grid.Row="8" Grid.Column="0" VerticalAlignment="Center" Padding="10 0 0 0">Password</TextBlock>
<PasswordBox Grid.Row="8" Grid.Column="1" x:Name="LastfmPassword" VerticalAlignment="Center" Margin="0,0,-121,0"/>

<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Padding="10 0 0 0">API Key</TextBlock>
<TextBox Grid.Row="4" Grid.Column="1" x:Name="LastfmAPIKey" Text="{Binding Source={x:Static properties:Settings.Default}, Path=Default.LastfmAPIKey}" TextWrapping="Wrap" Margin="0,0,-121,0" FontFamily="Lucida Sans Typewriter" VerticalAlignment="Center"/>
<TextBlock Grid.Row="5" Grid.Column="0" VerticalAlignment="Center" Padding="10 0 0 0">API Secret</TextBlock>
<TextBox Grid.Row="5" Grid.Column="1" x:Name="LastfmSecret" Text="{Binding Source={x:Static properties:Settings.Default}, Path=Default.LastfmSecret}" TextWrapping="Wrap" Margin="0,0,-121,0" FontFamily="Lucida Sans Typewriter" VerticalAlignment="Center"/>
<TextBlock Grid.Row="6" Grid.Column="0" VerticalAlignment="Center" Padding="10 0 0 0">Username</TextBlock>
<TextBox Grid.Row="6" Grid.Column="1" x:Name="LastfmUsername" Text="{Binding Source={x:Static properties:Settings.Default}, Path=Default.LastfmUsername}" TextWrapping="Wrap" Margin="0,0,-121,0" VerticalAlignment="Center"/>
<TextBlock Grid.Row="7" Grid.Column="0" VerticalAlignment="Center" Padding="10 0 0 0">Password</TextBlock>
<PasswordBox Grid.Row="7" Grid.Column="1" x:Name="LastfmPassword" VerticalAlignment="Center" Margin="0,0,-121,0"/>
<Button Grid.Row="8" Grid.Column="1" Content="Button" HorizontalAlignment="Left" Margin="201,10,0,0" VerticalAlignment="Top" Width="0"/>
<Button Grid.Row="8" Grid.Column="1" x:Name="SaveLastFMCreds" Content="Save Last.FM Credentials" VerticalAlignment="Center" Margin="99,0,-121,0" Click="SaveLastFMCreds_Click"/>
<Button Grid.Row="9" Grid.Column="1" Content="Button" HorizontalAlignment="Left" Margin="201,10,0,0" VerticalAlignment="Top" Width="0"/>
<Button Grid.Row="9" Grid.Column="1" x:Name="SaveLastFMCreds" Content="Save Last.FM Credentials" VerticalAlignment="Center" Margin="99,0,-121,0" Click="SaveLastFMCreds_Click"/>
</Grid>
</StackPanel>
</Border>
Expand Down
3 changes: 3 additions & 0 deletions AMWin-RichPresence/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ private void CheckBox_RunOnStartup_Click(object sender, RoutedEventArgs e) {

SaveSettings();
}
private void CheckBox_EnableDiscordRP_Click(object sender, RoutedEventArgs e) {
SaveSettings();
}

private void CheckBox_ShowAppleMusicIcon_Click(object sender, RoutedEventArgs e) {
SaveSettings();
Expand Down
2 changes: 1 addition & 1 deletion AMWin-RichPresence/TaskbarIconResources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<MenuItem Header="Exit" Click="MenuItemExit_Click"/>
</ContextMenu>

<tb:TaskbarIcon x:Key="TaskbarIcon" ContextMenu="{StaticResource SysTrayMenu}" IconSource="/Resources/AppleMusicTray.ico" TrayMouseDoubleClick="TaskbarIcon_DoubleClick"/>
<tb:TaskbarIcon x:Key="TaskbarIcon" ContextMenu="{StaticResource SysTrayMenu}" IconSource="/Resources/AMWinRP.ico" TrayMouseDoubleClick="TaskbarIcon_DoubleClick"/>

</ResourceDictionary>

0 comments on commit 6d77146

Please sign in to comment.