Added stuff

- Now displays "Jellyfin Discord RPC - Your Jellyfin Servers URL" in the title
- Now only shows "Rich Presence updated!" once
This commit is contained in:
Diamond Creeper 2024-11-30 23:55:30 +13:00
parent b1cbe1988d
commit 3752368156
8 changed files with 44 additions and 12 deletions

4
.editorconfig Normal file
View file

@ -0,0 +1,4 @@
[*.cs]
# Default severity for all analyzer diagnostics
dotnet_analyzer_diagnostic.severity = silent

View file

@ -24,7 +24,7 @@
"RelativeDocumentMoniker": "JellyfinDiscordRPC\\Program.cs", "RelativeDocumentMoniker": "JellyfinDiscordRPC\\Program.cs",
"ToolTip": "C:\\Users\\joshua\\Documents\\GitHub\\jellyfin-discord-rpc\\JellyfinDiscordRPC\\Program.cs", "ToolTip": "C:\\Users\\joshua\\Documents\\GitHub\\jellyfin-discord-rpc\\JellyfinDiscordRPC\\Program.cs",
"RelativeToolTip": "JellyfinDiscordRPC\\Program.cs", "RelativeToolTip": "JellyfinDiscordRPC\\Program.cs",
"ViewState": "AgIAAEEAAAAAAAAAAAAswGQAAAAFAAAAAAAAAA==", "ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAAANAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-11-30T05:30:39.706Z", "WhenOpened": "2024-11-30T05:30:39.706Z",
"EditorCaption": "" "EditorCaption": ""

View file

@ -24,7 +24,7 @@
"RelativeDocumentMoniker": "JellyfinDiscordRPC\\Program.cs", "RelativeDocumentMoniker": "JellyfinDiscordRPC\\Program.cs",
"ToolTip": "C:\\Users\\joshua\\Documents\\GitHub\\jellyfin-discord-rpc\\JellyfinDiscordRPC\\Program.cs", "ToolTip": "C:\\Users\\joshua\\Documents\\GitHub\\jellyfin-discord-rpc\\JellyfinDiscordRPC\\Program.cs",
"RelativeToolTip": "JellyfinDiscordRPC\\Program.cs", "RelativeToolTip": "JellyfinDiscordRPC\\Program.cs",
"ViewState": "AgIAADUAAAAAAAAAAAAswGQAAAAFAAAAAAAAAA==", "ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAAANAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-11-30T05:30:39.706Z", "WhenOpened": "2024-11-30T05:30:39.706Z",
"EditorCaption": "" "EditorCaption": ""

View file

@ -5,6 +5,11 @@ VisualStudioVersion = 17.12.35514.174
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JellyfinDiscordRPC", "JellyfinDiscordRPC\JellyfinDiscordRPC.csproj", "{06FF6B5D-B070-4DB7-9A87-9B6E280A794D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JellyfinDiscordRPC", "JellyfinDiscordRPC\JellyfinDiscordRPC.csproj", "{06FF6B5D-B070-4DB7-9A87-9B6E280A794D}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B615520C-ED8E-4BBE-A88B-96812A61C61F}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU

View file

@ -11,31 +11,54 @@ class Program
private const string ConfigFilePath = "config.json"; private const string ConfigFilePath = "config.json";
private static DiscordRpcClient _discordClient; private static DiscordRpcClient _discordClient;
private static Config _config; private static Config _config;
private static bool isScreenSharing = false; // Track screen sharing status
// Hard-code the Discord Client ID here // Hard-coded the Discord Client ID
private const string DiscordClientId = "1312264302601834578"; // Discord client ID private const string DiscordClientId = "1312264302601834578";
static bool presenceUpdated = false; // Flag to track initial rich presence update
static async Task Main(string[] args) static async Task Main(string[] args)
{ {
Console.WriteLine("Starting Jellyfin Discord Rich Presence..."); // Load or create configuration first
LoadOrCreateConfig(); // Initialize _config first
// Load or create configuration // Now we can safely access _config for the console title
LoadOrCreateConfig(); Console.WriteLine("Starting Jellyfin Discord Rich Presence...");
Console.Title = $"Jellyfin Discord RPC - {_config.JellyfinBaseUrl}";
// Initialize Discord Rich Presence // Initialize Discord Rich Presence
_discordClient = new DiscordRpcClient(DiscordClientId); _discordClient = new DiscordRpcClient(DiscordClientId);
_discordClient.OnReady += (sender, e) => Console.WriteLine("Connected to Discord RPC!"); _discordClient.OnReady += (sender, e) =>
_discordClient.OnPresenceUpdate += (sender, e) => Console.WriteLine("Rich Presence updated!"); {
Console.WriteLine("Connected to Discord RPC!");
// Log message when connection to Discord is established
if (!presenceUpdated)
{
Console.WriteLine("Rich Presence updated!"); // This will only show once
presenceUpdated = true; // Set the flag to true to avoid logging it again
}
};
// Handle presence updates only once at the start
_discordClient.OnPresenceUpdate += (sender, e) =>
{
if (!presenceUpdated)
{
Console.WriteLine("Rich Presence updated!");
presenceUpdated = true; // Set the flag to true so it doesn't display again
}
};
_discordClient.Initialize(); _discordClient.Initialize();
// Poll Jellyfin API for currently playing media // Poll Jellyfin API for currently playing media
var updateTask = UpdateRichPresence(); // Start the rich presence update task var updateTask = UpdateRichPresence(); // Start the rich presence update task
await updateTask; // Wait for the rich presence update task to finish await updateTask; // Wait for the rich presence update task to finish
} }
private static async Task UpdateRichPresence() private static async Task UpdateRichPresence()
{ {
while (true) while (true)
@ -140,7 +163,7 @@ class Program
var configJson = JsonSerializer.Serialize(_config, new JsonSerializerOptions { WriteIndented = true }); var configJson = JsonSerializer.Serialize(_config, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(ConfigFilePath, configJson); File.WriteAllText(ConfigFilePath, configJson);
Console.WriteLine("Configuration saved to config.json."); Console.WriteLine("Configuration saved to config.json.");
} }
} }