From 7358be85e30ceb9b751911a13ef09f9c534b52c8 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Mon, 23 Apr 2018 21:40:25 +0200 Subject: [PATCH] Disable RPC by default --- .../Classes/Core.cs | 37 ++++++++++--------- .../Classes/Settings.cs | 1 + Discord Media Loader.Application/MainForm.cs | 17 +++++---- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Discord Media Loader.Application/Classes/Core.cs b/Discord Media Loader.Application/Classes/Core.cs index d4c51f8..35da35f 100644 --- a/Discord Media Loader.Application/Classes/Core.cs +++ b/Discord Media Loader.Application/Classes/Core.cs @@ -261,25 +261,28 @@ namespace DML.Application.Classes } } - Logger.Info("Initializing RPC client"); - Logger.Trace("Registering RPC handlers"); - RpcHandlers.readyCallback += RpcReadyCallback; - RpcHandlers.disconnectedCallback += RpcDisconnectedCallback; - RpcHandlers.errorCallback += RpcErrorCallback; - RpcPresence.startTimestamp = DiscordRpcHelper.DateTimeToTimestamp(DateTime.UtcNow); - - Logger.Debug("Calling RPC initialize"); - DiscordRpc.Initialize("430025401851707393", ref RpcHandlers, true, null); - - // Do not await ;) - Task.Run(async () => + if (Settings.UseRPC) { - while (!ShuttingDown) + Logger.Info("Initializing RPC client"); + Logger.Trace("Registering RPC handlers"); + RpcHandlers.readyCallback += RpcReadyCallback; + RpcHandlers.disconnectedCallback += RpcDisconnectedCallback; + RpcHandlers.errorCallback += RpcErrorCallback; + RpcPresence.startTimestamp = DiscordRpcHelper.DateTimeToTimestamp(DateTime.UtcNow); + + Logger.Debug("Calling RPC initialize"); + DiscordRpc.Initialize("430025401851707393", ref RpcHandlers, true, null); + + // Do not await ;) + Task.Run(async () => { - Logger.Trace("Running RPC callbacks"); - await Task.Delay(5000); - } - }); + while (!ShuttingDown) + { + Logger.Trace("Running RPC callbacks"); + await Task.Delay(5000); + } + }); + } splash.Close(); diff --git a/Discord Media Loader.Application/Classes/Settings.cs b/Discord Media Loader.Application/Classes/Settings.cs index a9544ee..6297af9 100644 --- a/Discord Media Loader.Application/Classes/Settings.cs +++ b/Discord Media Loader.Application/Classes/Settings.cs @@ -15,6 +15,7 @@ namespace DML.Application.Classes public string FileNameScheme { get; set; } = @"%guild%\%channel%\%id%"; public bool SkipExistingFiles { get; set; } = true; public int ThreadLimit { get; set; } = 50; + public bool UseRPC { get; set; } = false; public void Store() { diff --git a/Discord Media Loader.Application/MainForm.cs b/Discord Media Loader.Application/MainForm.cs index 066285d..87aa8e9 100644 --- a/Discord Media Loader.Application/MainForm.cs +++ b/Discord Media Loader.Application/MainForm.cs @@ -252,14 +252,17 @@ namespace DML.Application lbProgress.Text = $"Scanned: {scanned} Downloaded: {done} Open: {totalAttachments - done}"; - Core.RpcPresence.details = "Downloading media files"; - Core.RpcPresence.state = $"{done} / {totalAttachments} ({pgbProgress.Value}%)"; - Core.RpcPresence.largeImageKey = "main"; - Core.RpcPresence.largeImageText = "Visit discordmedialoader.net"; - Core.RpcPresence.smallImageKey = "author"; - Core.RpcPresence.smallImageText = "Made by Serraniel"; + if (Core.Settings.UseRPC) + { + Core.RpcPresence.details = "Downloading media files"; + Core.RpcPresence.state = $"{done} / {totalAttachments} ({pgbProgress.Value}%)"; + Core.RpcPresence.largeImageKey = "main"; + Core.RpcPresence.largeImageText = "Visit discordmedialoader.net"; + Core.RpcPresence.smallImageKey = "author"; + Core.RpcPresence.smallImageText = "Made by Serraniel"; - Core.RpcUpdatePresence(); + Core.RpcUpdatePresence(); + } } private void aboutToolStripMenuItem_Click(object sender, System.EventArgs e)