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

View file

@ -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.");
}
}