Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shells-dw committed Dec 29, 2022
1 parent 8b55472 commit bbc1407
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion PiholePlugin/Actions/Disable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion PiholePlugin/Actions/Enable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions PiholePlugin/PiholePlugin.Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ 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;
}

// Now we put a template configuration file
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;
}
}
Expand Down
19 changes: 15 additions & 4 deletions PiholePlugin/PiholePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand All @@ -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");
}
}

Expand All @@ -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;
}
}
Expand All @@ -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"
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion PiholePlugin/metadata/LoupedeckPackage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<details><summary>Changelog History</summary><p>


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

0 comments on commit bbc1407

Please sign in to comment.