Skip to content

Commit

Permalink
Add user status indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Dasutein committed Jun 13, 2019
1 parent 6c1424d commit 9845d7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
12 changes: 7 additions & 5 deletions src/DiscordRPC.Main/UI/MainWindow.xaml
Expand Up @@ -7,8 +7,8 @@

mc:Ignorable="d"
Title="Discord Rich Presence Customizer" Height="448.526" Width="494.5" MinHeight="413" MinWidth="390" Background="#FF36393E" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize">
<Grid Margin="7,7,-7,-7">

<Grid Margin="7,7,-7,-7">
<Grid.RowDefinitions>
<RowDefinition Height="175*"/>
<RowDefinition Height="244*"/>
Expand Down Expand Up @@ -57,10 +57,12 @@
<ImageBrush ImageSource="/DiscordRPCMain;component/Resources/icons8_lock_96.png" Stretch="UniformToFill"/>
</Button.Background>
</Button>
<Image x:Name="discordAvatarImage" HorizontalAlignment="Left" Height="62" Margin="11,12,0,0" VerticalAlignment="Top" Width="62" Source="/DiscordRPCMain;component/Resources/icons8_discord_100.png" Stretch="UniformToFill" StretchDirection="DownOnly">
<Image x:Name="discordAvatarImage" HorizontalAlignment="Left" Height="62" Margin="11,12,0,0" VerticalAlignment="Top" Width="62" Source="{Binding discordProfileInfoViewModel.DiscordAvatarUri, UpdateSourceTrigger=PropertyChanged}" Stretch="UniformToFill" StretchDirection="DownOnly">
</Image>
<Label Content="USERNAME" Margin="76,22,303,0" VerticalAlignment="Top" Foreground="#FF8F97A0" FontWeight="Bold" Grid.ColumnSpan="3" FontSize="10"/>
<Label x:Name="usernameLabel" Content="Not found" Margin="76,39,183,0" VerticalAlignment="Top" Foreground="#FFEEEEEE" FontSize="12" FontWeight="Normal" Grid.ColumnSpan="3"/>
<Label Content="USERNAME" Margin="76,12,303,0" VerticalAlignment="Top" Foreground="#FF8F97A0" FontWeight="Bold" Grid.ColumnSpan="3" FontSize="10"/>
<Label x:Name="usernameLabel" Content="{Binding discordProfileInfoViewModel.DiscordUsername, UpdateSourceTrigger=PropertyChanged}" Margin="76,29,183,0" VerticalAlignment="Top" Foreground="#FFEEEEEE" FontSize="12" FontWeight="Normal" Grid.ColumnSpan="3"/>
<Label Content="STATUS" Margin="76,50,13,0" VerticalAlignment="Top" Foreground="#FF8F97A0" FontWeight="Bold" FontSize="10"/>
<Label x:Name="currentStatusLabel" Content="Online" Margin="120,50,139,0" VerticalAlignment="Top" Foreground="#FFEEEEEE" FontSize="10" FontWeight="Normal" Grid.ColumnSpan="3"/>
</Grid>
</TabItem>
<TabItem x:Name="tabItemSettings" Header="Settings" BorderBrush="{x:Null}" TabIndex="11">
Expand Down
22 changes: 14 additions & 8 deletions src/DiscordRPC.Main/UI/MainWindow.xaml.cs
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Threading;
using System.Windows.Media.Imaging;
using System.Windows.Media;

namespace DiscordRPC.Main
{
Expand Down Expand Up @@ -51,7 +52,7 @@ public MainWindow()

protected void ExitApplication(object sender, EventArgs e)
{
// When user closes the application, the application will dispose the Discord RPC client.
// Dispose RPC when user exits application
if (isDiscordPresenceRunning == true)
{
presenceManager.ShutdownPresence();
Expand All @@ -72,29 +73,27 @@ private void StartDiscordPresence()
this.Button_Shutdown.IsEnabled = false;
this.Button_Initialize_Discord.IsEnabled = true;
statusIconImage.Source = new BitmapImage(new Uri("/DiscordRPCMain;component/Resources/icons8_offline.png", UriKind.Relative));
this.SetCurrentStatus("Offline");
return;
}
else
{
hashManager.discordClientId = this.TextBox_clientId.Password;
StartHashManagerThread = new Thread(new ThreadStart(hashManager.HashId));
StartHashManagerThread.IsBackground = true;
StartHashManagerThread.Start();

this.Button_Initialize_Discord.IsEnabled = false;
this.Button_Update.IsEnabled = true;
this.Button_Shutdown.IsEnabled = true;
this.Button_afk_and_lock_pc.IsEnabled = true;
this.TextBox_clientId.IsEnabled = false;

statusIconImage.Source = new BitmapImage(new Uri("/DiscordRPCMain;component/Resources/icons8_online.png", UriKind.Relative));
isDiscordPresenceRunning = true;
this.SetCurrentStatus("Online");

this.usernameLabel.Content = JsonConfig.settings.discordUsername;
this.discordAvatarImage.Source = new BitmapImage(new Uri(JsonConfig.settings.discordAvatarUri));
// Used for checking if Discord presence is running before closing the app
isDiscordPresenceRunning = true;
}
}

private void updatePresence()
{

Expand All @@ -108,6 +107,7 @@ private void updatePresence()
Debug.WriteLine(TAG + "Updated presence and settings");
#endif

this.SetCurrentStatus("Online");
// Show MessageBox to notify user Spotify client is running
if (getSpotifyProcess.IsSpotifyOpened)
{
Expand Down Expand Up @@ -170,12 +170,12 @@ private void SaveUserStatePresence()
private void Shutdown()
{
presenceManager.ShutdownPresence();
this.usernameLabel.Content = "Not found";
this.Button_Update.IsEnabled = false;
this.Button_Shutdown.IsEnabled = false;
this.Button_Initialize_Discord.IsEnabled = true;
this.TextBox_clientId.IsEnabled = true;
this.Button_afk_and_lock_pc.IsEnabled = false;
this.SetCurrentStatus("Offline");
statusIconImage.Source = new BitmapImage(new Uri("/DiscordRPCMain;component/Resources/icons8_offline.png", UriKind.Relative));
}

Expand All @@ -198,6 +198,10 @@ private void Button_Initialize_Click(object sender, RoutedEventArgs e)
}
}

private void SetCurrentStatus(string status)
{
this.currentStatusLabel.Content = status;
}
private void Button_save_settings_Click(object sender, RoutedEventArgs e)
{
SaveUserStatePresence();
Expand Down Expand Up @@ -259,6 +263,7 @@ private void buttonAbout_Click(object sender, RoutedEventArgs e)

private void Button_afk_and_lock_pc_Click(object sender, RoutedEventArgs e)
{
this.SetCurrentStatus("AFK (Last updated on " + DateTime.Now + ")");
presenceManager.useTimeStamp = true;
presenceManager.discordPresenceDetail = JsonConfig.settings.discordUsername;
presenceManager.discordPresenceState = "is away from keyboard for ";
Expand All @@ -269,6 +274,7 @@ private void Button_afk_and_lock_pc_Click(object sender, RoutedEventArgs e)
presenceManager.UpdatePresence();
Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation");
}

}

}

0 comments on commit 9845d7f

Please sign in to comment.