diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8e8cbad --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# Default severity for all analyzer diagnostics +dotnet_analyzer_diagnostic.severity = silent diff --git a/.vs/JellyfinDiscordRPC/FileContentIndex/7446f8db-1993-4f61-8cd6-bbe9de0002d2.vsidx b/.vs/JellyfinDiscordRPC/FileContentIndex/7446f8db-1993-4f61-8cd6-bbe9de0002d2.vsidx deleted file mode 100644 index b5daebf..0000000 Binary files a/.vs/JellyfinDiscordRPC/FileContentIndex/7446f8db-1993-4f61-8cd6-bbe9de0002d2.vsidx and /dev/null differ diff --git a/.vs/JellyfinDiscordRPC/FileContentIndex/94a53a54-1f49-4d32-ab2b-3f3feb9118c6.vsidx b/.vs/JellyfinDiscordRPC/FileContentIndex/94a53a54-1f49-4d32-ab2b-3f3feb9118c6.vsidx new file mode 100644 index 0000000..6d66554 Binary files /dev/null and b/.vs/JellyfinDiscordRPC/FileContentIndex/94a53a54-1f49-4d32-ab2b-3f3feb9118c6.vsidx differ diff --git a/.vs/JellyfinDiscordRPC/FileContentIndex/e0abf749-404d-4324-b860-80672677e6e3.vsidx b/.vs/JellyfinDiscordRPC/FileContentIndex/e0abf749-404d-4324-b860-80672677e6e3.vsidx new file mode 100644 index 0000000..f0f3912 Binary files /dev/null and b/.vs/JellyfinDiscordRPC/FileContentIndex/e0abf749-404d-4324-b860-80672677e6e3.vsidx differ diff --git a/.vs/JellyfinDiscordRPC/v17/DocumentLayout.backup.json b/.vs/JellyfinDiscordRPC/v17/DocumentLayout.backup.json index 7bd1f1e..6996ba6 100644 --- a/.vs/JellyfinDiscordRPC/v17/DocumentLayout.backup.json +++ b/.vs/JellyfinDiscordRPC/v17/DocumentLayout.backup.json @@ -24,7 +24,7 @@ "RelativeDocumentMoniker": "JellyfinDiscordRPC\\Program.cs", "ToolTip": "C:\\Users\\joshua\\Documents\\GitHub\\jellyfin-discord-rpc\\JellyfinDiscordRPC\\Program.cs", "RelativeToolTip": "JellyfinDiscordRPC\\Program.cs", - "ViewState": "AgIAAEEAAAAAAAAAAAAswGQAAAAFAAAAAAAAAA==", + "ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAAANAAAAAAAAAA==", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2024-11-30T05:30:39.706Z", "EditorCaption": "" diff --git a/.vs/JellyfinDiscordRPC/v17/DocumentLayout.json b/.vs/JellyfinDiscordRPC/v17/DocumentLayout.json index a2d9884..6996ba6 100644 --- a/.vs/JellyfinDiscordRPC/v17/DocumentLayout.json +++ b/.vs/JellyfinDiscordRPC/v17/DocumentLayout.json @@ -24,7 +24,7 @@ "RelativeDocumentMoniker": "JellyfinDiscordRPC\\Program.cs", "ToolTip": "C:\\Users\\joshua\\Documents\\GitHub\\jellyfin-discord-rpc\\JellyfinDiscordRPC\\Program.cs", "RelativeToolTip": "JellyfinDiscordRPC\\Program.cs", - "ViewState": "AgIAADUAAAAAAAAAAAAswGQAAAAFAAAAAAAAAA==", + "ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAAANAAAAAAAAAA==", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2024-11-30T05:30:39.706Z", "EditorCaption": "" diff --git a/JellyfinDiscordRPC.sln b/JellyfinDiscordRPC.sln index 08422f4..686a7a5 100644 --- a/JellyfinDiscordRPC.sln +++ b/JellyfinDiscordRPC.sln @@ -5,6 +5,11 @@ VisualStudioVersion = 17.12.35514.174 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JellyfinDiscordRPC", "JellyfinDiscordRPC\JellyfinDiscordRPC.csproj", "{06FF6B5D-B070-4DB7-9A87-9B6E280A794D}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B615520C-ED8E-4BBE-A88B-96812A61C61F}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/JellyfinDiscordRPC/Program.cs b/JellyfinDiscordRPC/Program.cs index f13da8a..a74bda3 100644 --- a/JellyfinDiscordRPC/Program.cs +++ b/JellyfinDiscordRPC/Program.cs @@ -11,31 +11,54 @@ class Program private const string ConfigFilePath = "config.json"; private static DiscordRpcClient _discordClient; private static Config _config; - private static bool isScreenSharing = false; // Track screen sharing status - // Hard-code the Discord Client ID here - private const string DiscordClientId = "1312264302601834578"; // Discord client ID + // Hard-coded the 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) { - Console.WriteLine("Starting Jellyfin Discord Rich Presence..."); + // Load or create configuration first + LoadOrCreateConfig(); // Initialize _config first - // Load or create configuration - LoadOrCreateConfig(); + // Now we can safely access _config for the console title + Console.WriteLine("Starting Jellyfin Discord Rich Presence..."); + Console.Title = $"Jellyfin Discord RPC - {_config.JellyfinBaseUrl}"; // Initialize Discord Rich Presence _discordClient = new DiscordRpcClient(DiscordClientId); - _discordClient.OnReady += (sender, e) => Console.WriteLine("Connected to Discord RPC!"); - _discordClient.OnPresenceUpdate += (sender, e) => Console.WriteLine("Rich Presence updated!"); + _discordClient.OnReady += (sender, e) => + { + 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(); // Poll Jellyfin API for currently playing media var updateTask = UpdateRichPresence(); // Start the rich presence update task - await updateTask; // Wait for the rich presence update task to finish } + private static async Task UpdateRichPresence() { while (true) @@ -140,7 +163,7 @@ class Program var configJson = JsonSerializer.Serialize(_config, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(ConfigFilePath, configJson); - Console.WriteLine("Configuration saved to config.json."); + Console.WriteLine("Configuration saved to config.json."); } }