Skip to content

Commit a188224

Browse files
committed
Update sample plugin with new infra
1 parent 03c85a8 commit a188224

2 files changed

Lines changed: 12 additions & 29 deletions

File tree

SamplePlugin/PluginAction.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
using Newtonsoft.Json.Linq;
55
using SkiaSharp;
66
using System;
7-
using System.Collections.Generic;
8-
using System.Drawing;
97
using System.IO;
10-
using System.Linq;
11-
using System.Text;
128
using System.Threading.Tasks;
139

1410
namespace SamplePlugin
@@ -110,31 +106,21 @@ public override void Dispose()
110106
public async override void KeyPressed(KeyPayload payload)
111107
{
112108
Logger.Instance.LogMessage(TracingLevel.INFO, "Key Pressed");
113-
TitleParameters tp = new TitleParameters(new FontFamily("Arial"), FontStyle.Bold, 20, Color.White, true, TitleVerticalAlignment.Middle);
114-
using (Image image = Tools.GenerateGenericKeyImage(out Graphics graphics))
109+
using (SKBitmap image = SkiaTools.GenerateGenericKeyImage(out SKCanvas canvas))
115110
{
116-
graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, image.Width, image.Height);
117-
graphics.AddTextPath(tp, image.Height, image.Width, "Test");
118-
graphics.Dispose();
119-
111+
canvas.Clear(SKColors.DarkBlue);
112+
using var font = SkiaTools.CreateFont("Arial", 18, SKFontStyle.Bold);
113+
using var paint = new SKPaint { Color = SKColors.White, IsAntialias = true };
114+
float x = canvas.GetTextCenter("Pressed!", image.Width, font);
115+
canvas.DrawTextLine("Pressed!", font, paint, new SKPoint(x, image.Height / 2f - 10));
116+
canvas.Dispose();
120117
await Connection.SetImageAsync(image);
121118
}
122119
}
123120

124-
public async override void KeyReleased(KeyPayload payload)
121+
public async override void KeyReleased(KeyPayload payload)
125122
{
126-
// Cross-platform approach using SkiaSharp (works on Windows, macOS, Linux)
127-
using (SKBitmap image = SkiaTools.GenerateGenericKeyImage(out SKCanvas canvas))
128-
{
129-
canvas.Clear(SKColors.White);
130-
using (var font = SkiaTools.CreateFont("Arial", 20, SKFontStyle.Bold))
131-
using (var paint = new SKPaint { Color = SKColors.Black, IsAntialias = true })
132-
{
133-
canvas.DrawText("Cross-Platform", 10, 50, font, paint);
134-
}
135-
canvas.Dispose();
136-
await Connection.SetImageAsync(image);
137-
}
123+
await Connection.SetDefaultImageAsync();
138124
}
139125

140126
public override void OnTick() { }
@@ -156,4 +142,4 @@ private Task SaveSettings()
156142

157143
#endregion
158144
}
159-
}
145+
}

SamplePlugin/SamplePlugin.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net48</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
66
<AssemblyName>com.test.sdtools</AssemblyName>
77
<Platforms>AnyCPU;x64</Platforms>
8-
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
9-
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
108
</PropertyGroup>
119
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
1210
<OutputPath>bin\Release\com.test.sdtools.sdPlugin\</OutputPath>
@@ -21,7 +19,6 @@
2119
<OutputPath>bin\Debug\com.test.sdtools.sdPlugin\</OutputPath>
2220
</PropertyGroup>
2321
<ItemGroup>
24-
<None Include="App.config" />
2522
<None Include="manifest.json">
2623
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2724
</None>
@@ -89,4 +86,4 @@
8986
<ItemGroup>
9087
<Folder Include="Properties\" />
9188
</ItemGroup>
92-
</Project>
89+
</Project>

0 commit comments

Comments
 (0)