From feffb4dbe0af5781a073f4b0bd8ff4fc374b139d Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Thu, 26 Dec 2024 02:40:31 +0100 Subject: [PATCH] fix: enable more code analyzers & fix locking on `this` issue --- Shokofin/Plugin.cs | 8 +++++--- Shokofin/Shokofin.csproj | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Shokofin/Plugin.cs b/Shokofin/Plugin.cs index 1d7c0ca6..6f7e6266 100644 --- a/Shokofin/Plugin.cs +++ b/Shokofin/Plugin.cs @@ -24,6 +24,8 @@ public class Plugin : BasePlugin, IHasWebPages { private readonly ILogger Logger; + private readonly object Lock = new(); + /// /// The last time the base URL and base path was updated. /// @@ -43,7 +45,7 @@ public string BaseUrl { if (CachedBaseUrl is not null && LastBaseUrlUpdate is not null && DateTime.Now - LastBaseUrlUpdate < BaseUrlUpdateDelay) return CachedBaseUrl; - lock(this) { + lock (Lock) { LastBaseUrlUpdate = DateTime.Now; if (_configurationManager.GetNetworkConfiguration() is not { } networkOptions) { CachedBaseUrl = "http://localhost:8096/"; @@ -78,12 +80,12 @@ public string BasePath { if (CachedBasePath is not null && LastBaseUrlUpdate is not null && DateTime.Now - LastBaseUrlUpdate < BaseUrlUpdateDelay) return CachedBasePath; - lock(this) { + lock (Lock) { LastBaseUrlUpdate = DateTime.Now; if (_configurationManager.GetNetworkConfiguration() is not { } networkOptions) { CachedBaseUrl = "http://localhost:8096/"; CachedBasePath = string.Empty; - return CachedBaseUrl; + return CachedBasePath; } var protocol = networkOptions.RequireHttps && networkOptions.EnableHttps ? "https" : "http"; diff --git a/Shokofin/Shokofin.csproj b/Shokofin/Shokofin.csproj index acbf003e..96298d44 100644 --- a/Shokofin/Shokofin.csproj +++ b/Shokofin/Shokofin.csproj @@ -14,6 +14,12 @@ + + + + + +