Skip to content

Commit

Permalink
Cleanup plugin loading locations
Browse files Browse the repository at this point in the history
  • Loading branch information
habibrehmansg committed Dec 21, 2024
1 parent b8316c6 commit 25d6156
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 197 deletions.
2 changes: 1 addition & 1 deletion InfoPanel.Extras/DriveInfoPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class DriveInfoPlugin : BasePlugin

private readonly List<PluginContainer> _containers = [];

public DriveInfoPlugin() : base("Drive Info Plugin")
public DriveInfoPlugin() : base("drive-info-plugin", "Drive Info")
{
}

Expand Down
5 changes: 0 additions & 5 deletions InfoPanel.Extras/InfoPanel.Extras.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="if not exist &quot;$(SolutionDir)InfoPanel\bin\$(Platform)\$(ConfigurationName)\$(TargetFramework)\plugins&quot; mkdir &quot;$(SolutionDir)InfoPanel\bin\$(Platform)\$(ConfigurationName)\$(TargetFramework)\plugins&quot;&#xD;&#xA;xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;$(SolutionDir)InfoPanel\bin\$(Platform)\$(ConfigurationName)\$(TargetFramework)\plugins&quot; /Y /I&#xD;&#xA;" />
</Target>

</Project>
2 changes: 1 addition & 1 deletion InfoPanel.Extras/IpifyPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class IpifyPlugin : BasePlugin

public override TimeSpan UpdateInterval => TimeSpan.FromMinutes(5);

public IpifyPlugin() : base("Ipify Plugin")
public IpifyPlugin() : base("ipify-plugin", "Public IP - Ipify")
{
}

Expand Down
58 changes: 9 additions & 49 deletions InfoPanel.Extras/VolumePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public class VolumePlugin : BasePlugin
{
private readonly List<PluginContainer> _containers = [];

public VolumePlugin() : base("Volume Plugin")
private MMDeviceEnumerator? _deviceEnumerator;

public VolumePlugin() : base("volume-plugin","Volume Info")
{
}

Expand All @@ -17,18 +19,15 @@ public VolumePlugin() : base("Volume Plugin")
public override void Initialize()
{
//add default first
using MMDeviceEnumerator deviceEnumerator = new();
using var defaultDevice = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
_deviceEnumerator = new();
using var defaultDevice = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);

PluginContainer container = new("Default");
container.Entries.Add(new PluginText("device_friendly_name", "Device Name", defaultDevice.DeviceFriendlyName));
container.Entries.Add(new PluginText("friendly_name", "Name", defaultDevice.FriendlyName));
container.Entries.Add(new PluginText("short_name", "Short Name", defaultDevice.FriendlyName.Replace($"({defaultDevice.DeviceFriendlyName})", "")));
container.Entries.Add(new PluginSensor("volume", "Volume", (float)Math.Round(defaultDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100), "%"));
container.Entries.Add(new PluginText("mute", "Mute", defaultDevice.AudioEndpointVolume.Mute.ToString()));
_containers.Add(container);

var devices = deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
var devices = _deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
foreach (var device in devices)
{
container = new(device.ID, device.FriendlyName);
Expand All @@ -44,6 +43,7 @@ public override void Initialize()

public override void Close()
{
_deviceEnumerator?.Dispose();
}

public override void Load(List<IPluginContainer> containers)
Expand All @@ -59,8 +59,6 @@ public override Task UpdateAsync(CancellationToken cancellationToken)

public override void Update()
{
using MMDeviceEnumerator deviceEnumerator = new();

foreach(var container in _containers)
{
MMDevice? device = null;
Expand All @@ -69,11 +67,11 @@ public override void Update()
{
if (container.Name == "Default")
{
device = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
device = _deviceEnumerator?.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
}
else
{
device = deviceEnumerator.GetDevice(container.Id);
device = _deviceEnumerator?.GetDevice(container.Id);
}

if (device != null)
Expand All @@ -82,30 +80,6 @@ public override void Update()
{
switch (entry.Id)
{
case "device_friendly_name":
{
if (entry is PluginText text)
{
text.Value = device.DeviceFriendlyName;
}
}
break;
case "friendly_name":
{
if (entry is PluginText text)
{
text.Value = device.FriendlyName;
}
}
break;
case "short_name":
{
if (entry is PluginText text)
{
text.Value = device.FriendlyName.Replace($"({device.DeviceFriendlyName})", "");
}
}
break;
case "volume":
{
if (entry is PluginSensor sensor)
Expand All @@ -131,20 +105,6 @@ public override void Update()
device?.Dispose();
}
}

//var devices = deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
//foreach (var device in devices)
//{
// container = new(device.DeviceFriendlyName);
// container.Entries.Add(new PluginText("name", "Name", device.DeviceFriendlyName));
// container.Entries.Add(new PluginSensor("volume", "Volume", (float)Math.Round(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100), "%"));
// container.Entries.Add(new PluginText("mute", "Mute", device.AudioEndpointVolume.Mute.ToString()));
// _containers.Add(container);
// device.Dispose();
//}

//using var defaultDevice = _deviceEnumerator?.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
//_volumeSensor.Value = (float)Math.Round((defaultDevice?.AudioEndpointVolume.MasterVolumeLevelScalar ?? 0) * 100);
}
}
}
2 changes: 1 addition & 1 deletion InfoPanel.Extras/WeatherPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class WeatherPlugin : BasePlugin
private readonly PluginSensor _rain = new("rain", "Rain", 0, "mm/h");
private readonly PluginSensor _snow = new("snow", "Snow", 0, "mm/h");

public WeatherPlugin() : base("Weather Plugin")
public WeatherPlugin() : base("weather-plugin","Weather Info - OpenWeatherMap")
{
}

Expand Down
35 changes: 1 addition & 34 deletions InfoPanel.Plugins.Loader/PluginLoader.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

namespace InfoPanel.Plugins.Loader
{
public class PluginLoader
{
public void test(string folder)
{
//var plugins= Directory.GetFiles(folder, "InfoPanel.*.dll");
//IEnumerable<IPlugin> commands = plugins.SelectMany(pluginPath =>
//{
// Assembly pluginAssembly = LoadPlugin(pluginPath);
// return CreateCommands(pluginAssembly);
//}).ToList();

//foreach (var command in commands)
//{
// Trace.WriteLine(command);
// var panelDatas = command.GetData();
// foreach(var panelData in panelDatas)
// {
// Trace.WriteLine(panelData.CollectionName);
// foreach(var item in panelData.EntryList)
// {
// Trace.WriteLine($"{item.Name}: {item.Value} {item.Unit}");
// }
// }
//}
}

public IEnumerable<IPlugin> InitializePlugin(string pluginPath)
{
Assembly pluginAssembly = LoadPlugin(pluginPath);
Expand Down Expand Up @@ -72,7 +41,5 @@ static IEnumerable<IPlugin> CreateCommands(Assembly assembly)
$"Available types: {availableTypes}");
}
}


}
}
5 changes: 5 additions & 0 deletions InfoPanel.Plugins.Loader/PluginWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ private void DisposeResources()
_task?.Dispose();
_cts = null;
_task = null;

try
{
Plugin.Close();
}catch { }
}
}
}
9 changes: 0 additions & 9 deletions InfoPanel/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ protected override async void OnStartup(StartupEventArgs e)
Exit += App_Exit;

await StartPanels();


testPlugin();
}

private void OnSessionEnding(object sender, SessionEndingEventArgs e)
Expand Down Expand Up @@ -335,11 +332,5 @@ private void DisplayWindow_Closed(object? sender, EventArgs e)
DisplayWindows.Remove(displayWindow.Profile.Guid);
}
}

public void testPlugin()
{
var pluginLoader = new PluginLoader();
pluginLoader.test("plugins");
}
}
}
50 changes: 35 additions & 15 deletions InfoPanel/InfoPanel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@
<UseWindowsForms>False</UseWindowsForms>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<ApplicationManifest>Resources\app.manifest</ApplicationManifest>
<ExtrasOutputDir>..\InfoPanel.Extras\bin\$(Platform)\$(Configuration)\$(TargetFramework)</ExtrasOutputDir>
<PluginOutputDir>bin\$(Platform)\$(Configuration)\$(TargetFramework)\plugins</PluginOutputDir>
</PropertyGroup>

<Target Name="BuildExtras" BeforeTargets="Build">
<MSBuild Projects="..\InfoPanel.Extras\InfoPanel.Extras.csproj" Targets="Build" />
</Target>

<Target Name="CopyExtrasDll" AfterTargets="Build">
<MakeDir Directories="$(PluginOutputDir)\InfoPanel.Extras" />
<ItemGroup>
<FilesToCopy Include="$(ExtrasOutputDir)\**\*.*" />
</ItemGroup>
<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="$(PluginOutputDir)\InfoPanel.Extras" SkipUnchangedFiles="true" />
</Target>

<Target Name="CleanPluginsDirectory" BeforeTargets="Clean">
<RemoveDir Directories="$(PluginOutputDir)" />
</Target>

<Target Name="Sign" AfterTargets="Publish">
<!--<Exec WorkingDirectory="$(PublishDir)" Command="&quot;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\signtool.exe&quot; sign /a /t http://timestamp.sectigo.com /fd SHA256 /d &quot;InfoPanel&quot; /v InfoPanel.exe" />-->
</Target>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DebugType>full</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DebugType>none</DebugType>
</PropertyGroup>

<ItemGroup>
Expand All @@ -24,28 +54,16 @@
<HintPath>Lib\d2dwinform.dll</HintPath>
</Reference>
<Reference Include="LibreHardwareMonitorLib">
<HintPath>Lib\LibreHardwareMonitorLib.dll</HintPath>
<HintPath>Lib\LibreHardwareMonitorLib.dll</HintPath>
</Reference>
<Reference Include="TuringSmartScreenLib">
<HintPath>Lib\TuringSmartScreenLib.dll</HintPath>
<HintPath>Lib\TuringSmartScreenLib.dll</HintPath>
</Reference>
<Reference Include="TuringSmartScreenLib.Helpers.GDI">
<HintPath>Lib\TuringSmartScreenLib.Helpers.GDI.dll</HintPath>
<HintPath>Lib\TuringSmartScreenLib.Helpers.GDI.dll</HintPath>
</Reference>
</ItemGroup>

<Target Name="Sign" AfterTargets="Publish">
<!--<Exec WorkingDirectory="$(PublishDir)" Command="&quot;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\signtool.exe&quot; sign /a /t http://timestamp.sectigo.com /fd SHA256 /d &quot;InfoPanel&quot; /v InfoPanel.exe" />-->
</Target>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<DebugType>full</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<DebugType>full</DebugType>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Images\**" />
<EmbeddedResource Remove="Images\**" />
Expand Down Expand Up @@ -97,6 +115,7 @@
<None Remove="Resources\Images\Libre\voltage.png" />
<None Remove="Resources\Images\libre_icon.ico" />
<None Remove="Resources\Images\libre_icon.png" />
<None Remove="Resources\Images\logo.ico" />
<None Remove="Resources\Images\logo.png" />
<None Remove="Resources\Images\no_image.png" />
</ItemGroup>
Expand Down Expand Up @@ -143,6 +162,7 @@
<Resource Include="Resources\Images\Libre\voltage.png" />
<Resource Include="Resources\Images\libre_icon.ico" />
<Resource Include="Resources\Images\libre_icon.png" />
<Resource Include="Resources\Images\logo.ico" />
<Resource Include="Resources\Images\logo.png" />
<Resource Include="Resources\Images\no_image.png" />
<Content Include="index.html">
Expand Down
Loading

0 comments on commit 25d6156

Please sign in to comment.