-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
77 lines (67 loc) · 3.21 KB
/
MainWindow.xaml.cs
File metadata and controls
77 lines (67 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Windows;
using richcord.Services;
namespace richcord
{
/// <summary>
/// Main window for the Custom Rich Presence application.
/// Handles user interaction and communicates with the Discord Rich Presence service.
/// </summary>
public partial class MainWindow : Window
{
// Service responsible for managing Discord Rich Presence connection and updates
private readonly DiscordPresenceService _discordService = new DiscordPresenceService();
public MainWindow()
{
InitializeComponent();
this.Closed += MainWindow_Closed;
}
// Connects to Discord and activates Rich Presence when the "Connect" button is clicked
private void btnConnect_Click(object sender, RoutedEventArgs e)
{
var appId = txtAppId.Text.Trim();
if (_discordService.Connect(appId))
{
// Immediately update Rich Presence after connecting
var details = txtDetails.Text.Trim();
var state = txtState.Text.Trim();
var largeImageKey = txtLargeImageKey.Text.Trim();
var smallImageKey = txtSmallImageKey.Text.Trim();
_discordService.UpdatePresence(details, state, largeImageKey, smallImageKey);
MessageBox.Show("Successfully connected to Discord and Rich Presence is now active on your profile!", "Connection Status", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
MessageBox.Show("Failed to connect. Please check your Application ID (numbers only) and make sure Discord is running.", "Connection Status", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
// Updates the Rich Presence information when the "Update Presence" button is clicked
private void btnUpdatePresence_Click(object sender, RoutedEventArgs e)
{
var details = txtDetails.Text.Trim();
var state = txtState.Text.Trim();
var largeImageKey = txtLargeImageKey.Text.Trim();
var smallImageKey = txtSmallImageKey.Text.Trim();
try
{
_discordService.UpdatePresence(details, state, largeImageKey, smallImageKey);
MessageBox.Show("Rich Presence updated on Discord!", "Presence Update", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Error updating presence: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
// Disconnects from Discord and removes Rich Presence when the "Disconnect" button is clicked
private void btnDisconnect_Click(object sender, RoutedEventArgs e)
{
_discordService.Dispose();
MessageBox.Show("Disconnected from Discord. Rich Presence has been removed from your profile.", "Disconnected", MessageBoxButton.OK, MessageBoxImage.Information);
}
// Ensures resources are released when the window is closed
private void MainWindow_Closed(object sender, EventArgs e)
{
_discordService.Dispose();
}
}
}