diff --git a/PiholePlugin/Actions/Disable.cs b/PiholePlugin/Actions/Disable.cs index c85ee6a..5e179ad 100644 --- a/PiholePlugin/Actions/Disable.cs +++ b/PiholePlugin/Actions/Disable.cs @@ -46,7 +46,8 @@ protected override void RunCommand(String actionParameter) this._plugin.TryGetPluginSetting("ApiToken", out var ApiToken); var httpClient = new HttpClient(); var apiClient = new PiHoleApiClient(httpClient, apiUrl, ApiToken); - var data = Task.Run(() => apiClient.Disable(Int32.Parse(actionParameter))).GetAwaiter().GetResult(); + Task.Run(() => apiClient.Disable(Int32.Parse(actionParameter))).Wait(); + this.Log.Info($"{DateTime.Now} - Disabled PiHole {actionParameter}"); // notify Loupedeck about the change this.ActionImageChanged(actionParameter); } diff --git a/PiholePlugin/Actions/Enable.cs b/PiholePlugin/Actions/Enable.cs index cb8d65c..0360b4b 100644 --- a/PiholePlugin/Actions/Enable.cs +++ b/PiholePlugin/Actions/Enable.cs @@ -33,7 +33,8 @@ protected override void RunCommand(String actionParameter) this._plugin.TryGetPluginSetting("ApiToken", out var ApiToken); var httpClient = new HttpClient(); var apiClient = new PiHoleApiClient(httpClient, apiUrl, ApiToken); - var data = Task.Run(() => apiClient.Enable()).GetAwaiter().GetResult(); + Task.Run(() => apiClient.Enable()).Wait(); + this.Log.Info($"{DateTime.Now} - Enabled PiHole"); // notify Loupedeck about the change this.ActionImageChanged(actionParameter); } diff --git a/PiholePlugin/PiholePlugin.Installer.cs b/PiholePlugin/PiholePlugin.Installer.cs index 07e2667..9b4bd5c 100644 --- a/PiholePlugin/PiholePlugin.Installer.cs +++ b/PiholePlugin/PiholePlugin.Installer.cs @@ -9,10 +9,11 @@ public class PiholePluginInstaller public static Boolean Install() { // Here we ensure the plugin data directory is there. - var helperFunction = new PiholePlugin(); - var pluginDataDirectory = helperFunction.GetPluginDataDirectory(); + var _this = new PiholePlugin(); + var pluginDataDirectory = _this.GetPluginDataDirectory(); if (!IoHelpers.EnsureDirectoryExists(pluginDataDirectory)) { + _this.Log.Info($"{DateTime.Now} - Installer: pluginDataDirectory doesn't exist"); return false; } @@ -20,11 +21,13 @@ public static Boolean Install() var filePath = System.IO.Path.Combine(pluginDataDirectory, System.IO.Path.Combine(pluginDataDirectory, "settings.json")); if (File.Exists(filePath)) { + _this.Log.Info($"{DateTime.Now} - Installer: File exists"); return true; } else { ResourceReader.CreateFileFromResource("Loupedeck.PiholePlugin.settings.json", filePath); + _this.Log.Info($"{DateTime.Now} - Installer: config file does not yet exist, creating default file"); return true; } } diff --git a/PiholePlugin/PiholePlugin.cs b/PiholePlugin/PiholePlugin.cs index b04e131..55ce8aa 100644 --- a/PiholePlugin/PiholePlugin.cs +++ b/PiholePlugin/PiholePlugin.cs @@ -4,6 +4,7 @@ namespace Loupedeck.PiholePlugin using System.IO; using System.Net.Http; using System.Net.Sockets; + using System.Runtime; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -34,6 +35,8 @@ private async void QueryThread() { var httpClient = new HttpClient(); var apiClient = new PiHoleApiClient(httpClient, this.apiUrl, this.ApiToken); + var _this = new PiholePlugin(); + _this.Log.Info($"{DateTime.Now} - Starting query thread"); while (true && !this._cancellationTokenSource.IsCancellationRequested) { @@ -42,9 +45,9 @@ private async void QueryThread() Globals.PiDump = await apiClient.GetSummaryRawAsync(); UpdatedStatus?.Invoke(this, Globals.PiDump); } - catch + catch (Exception ex) { - // + _this.Log.Error($"{DateTime.Now} - QueryThread: Exception caught {ex.Message}"); } await Task.Delay(1000); } @@ -64,16 +67,21 @@ public override void Load() // verify pihole is reachable under given url and the token is correct, set plugin status accordingly to display help if need be if (!this.VerifyConnectivity()) - { this.OnPluginStatusChanged(Loupedeck.PluginStatus.Error, "Can't connect to PiHole! Verify and set URL in settings.json accordingly.", "https://github.com/shells-dw/loupedeck-pihole#settings.json", "GitHub Readme"); } + { + this.OnPluginStatusChanged(Loupedeck.PluginStatus.Error, "Can't connect to PiHole! Verify and set URL in settings.json accordingly.", "https://github.com/shells-dw/loupedeck-pihole#settings.json", "GitHub Readme"); + this.Log.Error($"{DateTime.Now} - Starting... !this.VerifyConnectivity()"); + } else { if (!this.VerifyToken()) { this.OnPluginStatusChanged(Loupedeck.PluginStatus.Error, "It appears the API token isn't set correctly. Verify and set ApiToken in settings.json accordingly.", "https://github.com/shells-dw/loupedeck-pihole#settings.json", "GitHub Readme"); + this.Log.Error($"{DateTime.Now} - Starting... !this.VerifyToken()"); } else { this.OnPluginStatusChanged(Loupedeck.PluginStatus.Normal, "Connected", null, null); + this.Log.Info($"{DateTime.Now} - Starting... plugin in nominal status"); } } @@ -92,8 +100,9 @@ private Boolean VerifyConnectivity() { return tcpClient.ConnectAsync(Regex.Match(this.apiUrl, @"^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)", RegexOptions.Singleline).Groups[1].Value, 80).Wait(5000); } - catch (Exception) + catch (Exception ex) { + this.Log.Error($"{DateTime.Now} - VerifyConnectivity: Exception {ex.Message}"); return false; } } @@ -109,6 +118,7 @@ private Boolean VerifyToken() Boolean apiAccessGranted; if (getSettings.Status == null) { + this.Log.Error($"{DateTime.Now} - VerifyToken: getSettings.Status == null"); return false; } apiAccessGranted = getSettings.Status == "enabled" @@ -119,6 +129,7 @@ private Boolean VerifyToken() public void UpdateConnectionSettings() { + this.Log.Info($"{DateTime.Now} - UpdateConnectionSettings()"); this.TryGetSetting("ApiUrl", out var apiUrl); this.TryGetSetting("ApiToken", out var apiToken); var pluginDataDirectory = this.GetPluginDataDirectory(); diff --git a/PiholePlugin/metadata/LoupedeckPackage.yaml b/PiholePlugin/metadata/LoupedeckPackage.yaml index 1bc4a1a..7c420ab 100644 --- a/PiholePlugin/metadata/LoupedeckPackage.yaml +++ b/PiholePlugin/metadata/LoupedeckPackage.yaml @@ -15,7 +15,7 @@ displayName: PiHole pluginFileName: PiholePlugin.dll # Plugin version. -version: 1.1 +version: 1.2.0 # Author of the plugin. The author can be a company or an individual developer. author: Dominik Werland diff --git a/README.md b/README.md index 3c33a75..3f464e1 100644 --- a/README.md +++ b/README.md @@ -80,13 +80,15 @@ If you'd like to drop me a coffee for the hours I've spent on this: or use Ko-Fi [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Y8Y4CE9LH) # Changelog -## [1.1.0] - 2022-12-22 -### Improved -- process flow +## [1.2.0] - 2022-12-29 +### Added +- Logging
Changelog History

- +## [1.1.0] - 2022-12-22 +### Improved +- process flow ## [1.0.0] - 2022-11-26 ### Added Initial release