Skip to content

Commit

Permalink
Disable buttons before initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nostrenz committed Nov 11, 2017
1 parent 7033a74 commit d6bd1e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
6 changes: 3 additions & 3 deletions DiscordRpcDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
Title="Discord RPC demo" Height="413" Width="480" MinHeight="413" MinWidth="390" Background="#FF36393E">
<Grid>
<Button Content="Initialize" Margin="0,10,18,0" VerticalAlignment="Top" Height="42" Click="Button_Initialize_Click" HorizontalAlignment="Right" Width="136" Background="#FF3CB21A" Foreground="White" BorderBrush="{x:Null}" FontSize="14"/>
<Button Content="RunCallbacks" Margin="10,0,0,46" Click="Button_RunCallbacks_Click" Height="42" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="145" Background="#FFF57F08" Foreground="White" BorderBrush="{x:Null}" FontSize="14"/>
<Button Content="Shutdown" Margin="0,0,17,46" RenderTransformOrigin="0.511,-1.601" Click="Button_Shutdown_Click" Height="42" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="145" Background="#FFE82B0D" Foreground="White" BorderBrush="{x:Null}" FontSize="14"/>
<Button Content="Update" Margin="160,0,167,46" Click="Button_Update_Click" Height="42" VerticalAlignment="Bottom" Background="#FF337AE0" Foreground="White" BorderBrush="{x:Null}" FontSize="14" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Button x:Name="Button_RunCallbacks" Content="RunCallbacks" Margin="10,0,0,46" Click="Button_RunCallbacks_Click" Height="42" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="145" Background="#FFF57F08" Foreground="White" BorderBrush="{x:Null}" FontSize="14" IsEnabled="False"/>
<Button x:Name="Button_Shutdown" Content="Shutdown" Margin="0,0,17,46" RenderTransformOrigin="0.511,-1.601" Click="Button_Shutdown_Click" Height="42" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="145" Background="#FFE82B0D" Foreground="White" BorderBrush="{x:Null}" FontSize="14" IsEnabled="False"/>
<Button x:Name="Button_Update" Content="Update" Margin="160,0,167,46" Click="Button_Update_Click" Height="42" VerticalAlignment="Bottom" Background="#FF337AE0" Foreground="White" BorderBrush="{x:Null}" FontSize="14" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsEnabled="False"/>
<TextBox x:Name="TextBox_state" Height="23" Margin="111,88,18,0" TextWrapping="Wrap" Text="Playing Solo" VerticalAlignment="Top" MaxLength="128" MaxLines="1" VerticalContentAlignment="Center" Background="#FF484B51" BorderBrush="{x:Null}" Foreground="#FFD1D1D1"/>
<TextBox x:Name="TextBox_details" Height="23" Margin="111,60,18,0" TextWrapping="Wrap" Text="In Queue" VerticalAlignment="Top" MaxLength="128" MaxLines="1" VerticalContentAlignment="Center" Background="#FF484B51" BorderBrush="{x:Null}" Foreground="#FFD1D1D1"/>
<TextBox x:Name="TextBox_clientId" Height="42" Margin="10,10,159,0" TextWrapping="Wrap" Text="Client ID" VerticalAlignment="Top" MaxLines="1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="18" Background="#FF484B51" BorderBrush="{x:Null}" Foreground="#FFD1D1D1"/>
Expand Down
42 changes: 34 additions & 8 deletions DiscordRpcDemo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace DiscordRpcDemo
public partial class MainWindow : Window
{
private DiscordRpc.RichPresence presence;
private int callbackCalls;

DiscordRpc.EventHandlers handlers;

Expand All @@ -28,9 +27,12 @@ public MainWindow()
=============================================
*/

/// <summary>
/// Initialize the RPC.
/// </summary>
/// <param name="clientId"></param>
private void Initialize(string clientId)
{
callbackCalls = 0;
handlers = new DiscordRpc.EventHandlers();

handlers.readyCallback = ReadyCallback;
Expand All @@ -42,6 +44,9 @@ private void Initialize(string clientId)
this.SetStatusBarMessage("Initialized.");
}

/// <summary>
/// Update the presence status from what's in the UI fields.
/// </summary>
private void UpdatePresence()
{
presence.details = this.TextBox_details.Text;
Expand All @@ -65,38 +70,51 @@ private void UpdatePresence()
this.SetStatusBarMessage("Presence updated.");
}

/// <summary>
/// Calls ReadyCallback(), DisconnectedCallback(), ErrorCallback().
/// </summary>
private void RunCallbacks()
{
DiscordRpc.RunCallbacks();

this.SetStatusBarMessage("Rallbacks run.");
}

/// <summary>
/// Stop RPC.
/// </summary>
private void Shutdown()
{
DiscordRpc.Shutdown();

this.SetStatusBarMessage("Shuted down.");
}

/// <summary>
/// Called after RunCallbacks() when ready.
/// </summary>
private void ReadyCallback()
{
++callbackCalls;

this.SetStatusBarMessage("Ready.");
}

/// <summary>
/// Called after RunCallbacks() in cause of disconnection.
/// </summary>
/// <param name="errorCode"></param>
/// <param name="message"></param>
private void DisconnectedCallback(int errorCode, string message)
{
++callbackCalls;

this.SetStatusBarMessage(string.Format("Disconnect {0}: {1}", errorCode, message));
}

/// <summary>
/// Called after RunCallbacks() in cause of error.
/// </summary>
/// <param name="errorCode"></param>
/// <param name="message"></param>
private void ErrorCallback(int errorCode, string message)
{
++callbackCalls;

this.SetStatusBarMessage(string.Format("Error {0}: {1}", errorCode, message));
}

Expand Down Expand Up @@ -142,6 +160,10 @@ private void Button_Initialize_Click(object sender, RoutedEventArgs e)
}

this.Initialize(clientId);

this.Button_RunCallbacks.IsEnabled = true;
this.Button_Update.IsEnabled = true;
this.Button_Shutdown.IsEnabled = true;
}

/// <summary>
Expand Down Expand Up @@ -172,6 +194,10 @@ private void Button_RunCallbacks_Click(object sender, RoutedEventArgs e)
private void Button_Shutdown_Click(object sender, RoutedEventArgs e)
{
this.Shutdown();

this.Button_RunCallbacks.IsEnabled = false;
this.Button_Update.IsEnabled = false;
this.Button_Shutdown.IsEnabled = false;
}
}
}

0 comments on commit d6bd1e1

Please sign in to comment.