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

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shells-dw committed Dec 22, 2022
1 parent 1c74b98 commit 8b55472
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 30 deletions.
3 changes: 0 additions & 3 deletions PiholePlugin/Actions/AdsBlockedPercentage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
namespace Loupedeck.PiholePlugin.Actions
{
using System;
using System.CodeDom;
using System.Globalization;
using System.IO;
using System.Text;

using Loupedeck.PiholePlugin.Helpers;

Expand Down
5 changes: 1 addition & 4 deletions PiholePlugin/Actions/Disable.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
namespace Loupedeck.PiholePlugin.Actions
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Runtime;
using System.Text;
using System.Threading.Tasks;

using Loupedeck.PiholePlugin.Helpers;

internal class Disable : PluginDynamicCommand
Expand Down
5 changes: 1 addition & 4 deletions PiholePlugin/Actions/Enable.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
namespace Loupedeck.PiholePlugin.Actions
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Runtime;
using System.Text;
using System.Threading.Tasks;

using Loupedeck.PiholePlugin.Helpers;

internal class Enable : PluginDynamicCommand
Expand Down
8 changes: 5 additions & 3 deletions PiholePlugin/PiholePlugin.Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;

public class PiholePluginInstaller
{
Expand All @@ -23,8 +22,11 @@ public static Boolean Install()
{
return true;
}
ResourceReader.CreateFileFromResource("Loupedeck.PiholePlugin.settings.json", filePath);
return true;
else
{
ResourceReader.CreateFileFromResource("Loupedeck.PiholePlugin.settings.json", filePath);
return true;
}
}
}
public class ResourceReader
Expand Down
21 changes: 10 additions & 11 deletions PiholePlugin/PiholePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class PiholePlugin : Plugin
private readonly Thread _queryThread;
private String apiUrl;
private String ApiToken;
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();

// Gets a value indicating whether this is an Universal plugin or an Application plugin.
public override Boolean UsesApplicationApiOnly => true;
Expand All @@ -29,23 +30,23 @@ public class PiholePlugin : Plugin

//background updater
public PiholePlugin() => this._queryThread = new Thread(this.QueryThread) { IsBackground = true };
private void QueryThread()
private async void QueryThread()
{
var httpClient = new HttpClient();
var apiClient = new PiHoleApiClient(httpClient, this.apiUrl, this.ApiToken);

while (true)
while (true && !this._cancellationTokenSource.IsCancellationRequested)
{
try
{
Globals.PiDump = Task.Run(() => apiClient.GetSummaryRawAsync()).GetAwaiter().GetResult();
Globals.PiDump = await apiClient.GetSummaryRawAsync();
UpdatedStatus?.Invoke(this, Globals.PiDump);
}
catch
{
//
}
System.Threading.Thread.Sleep(1000);
await Task.Delay(1000);
}
}
// This method is called when the plugin is loaded during the Loupedeck service start-up.
Expand Down Expand Up @@ -81,17 +82,15 @@ public override void Load()
}

// This method is called when the plugin is unloaded during the Loupedeck service shutdown.
public override void Unload()
{
}
public override void Unload() => this._cancellationTokenSource.Cancel();

private Boolean VerifyConnectivity()
{
using (TcpClient tcpClient = new TcpClient())
{
try
{
return tcpClient.ConnectAsync(Regex.Match(this.apiUrl, @"^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)", RegexOptions.Singleline).Groups[1].Value, 80).Wait(1000);
return tcpClient.ConnectAsync(Regex.Match(this.apiUrl, @"^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)", RegexOptions.Singleline).Groups[1].Value, 80).Wait(5000);
}
catch (Exception)
{
Expand All @@ -106,15 +105,15 @@ private Boolean VerifyToken()
var apiClient = new PiHoleApiClient(httpClient, this.apiUrl, this.ApiToken);

// get status
var getSettings = Task.Run(() => apiClient.GetSummaryRawAsync()).GetAwaiter().GetResult();
var getSettings = Task.Run(() => apiClient.GetSummaryRawAsync()).Result;
Boolean apiAccessGranted;
if (getSettings.Status == null)
{
return false;
}
apiAccessGranted = getSettings.Status == "enabled"
? Task.Run(() => apiClient.VerifyConnectivity("enable")).GetAwaiter().GetResult()
: Task.Run(() => apiClient.VerifyConnectivity("disable")).GetAwaiter().GetResult();
? Task.Run(() => apiClient.VerifyConnectivity("enable")).Result
: Task.Run(() => apiClient.VerifyConnectivity("disable")).Result;
return apiAccessGranted == true;
}

Expand Down
1 change: 0 additions & 1 deletion PiholePlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
4 changes: 2 additions & 2 deletions 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.0
version: 1.1

# Author of the plugin. The author can be a company or an individual developer.
author: Dominik Werland
Expand All @@ -41,7 +41,7 @@ supportedDevices:
- LoupedeckCtFamily

# LoupedeckPlusFamily covers Loupedeck+ device. Uncomment the following line to support Loupedeck+.
#- LoupedeckPlusFamily
- LoupedeckPlusFamily

# List of plugin capabilities.
pluginCapabilities:
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,25 @@ If you'd like to drop me a coffee for the hours I've spent on this:
[![Tip](https://img.shields.io/badge/Donate-PayPal-green.svg)]( https://www.paypal.com/donate?hosted_button_id=8KXD334CCEEC2)
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

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


## [1.0.0] - 2022-11-26
### Added
Initial release

</p></details>


<!-- Reference Links -->

[Loupedeck]: https://loupedeck.com "Loupedeck.com"
[Releases]: https://github.com/shells-dw/loupedeck-pihole/releases "Releases"
[PiHole]: https://pi-hole.net "Pi-hole® Network-wide Ad Blocking "
[GitHub issues]: https://github.com/shells-dw/streamdeck-pihole/issues "GitHub issues link"
[GitHub issues]: https://github.com/shells-dw/loupedeck-pihole/issues "GitHub issues link"

0 comments on commit 8b55472

Please sign in to comment.