Files
nfc-actions/NfcActions/Services/ActionService.cs
Amal Graafstra 5b6a7f0fa5 Initial commit: NFC Actions Windows tray application
Implement PC/SC-based NFC card reader monitoring application with WPF UI. Features include:
- System tray integration with single-click to open main window
- Dynamic reader detection and management with enable/disable per reader
- NDEF payload extraction supporting Type 2 and Type 4 tags
- Auto-detection of block sizes (4-byte vs 16-byte) for different reader types
- Configurable actions: copy to clipboard, launch URLs, keyboard input simulation
- URI record type detection - only launches browser for actual URI records
- Real-time activity logging with color-coded levels (Debug, Info, Warning, Error)
- File-based debug logging for troubleshooting
- Settings persistence between sessions
- Dangerous Things branding with custom icons and clickable logo

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 22:56:11 -08:00

70 lines
1.7 KiB
C#

using System;
using System.Diagnostics;
using System.Windows;
using WindowsInput;
using WindowsInput.Native;
namespace NfcActions.Services;
public class ActionService
{
private readonly InputSimulator _inputSimulator = new();
public void CopyToClipboard(string text)
{
try
{
Clipboard.SetText(text);
}
catch (Exception)
{
// Failed to set clipboard
}
}
public void LaunchUrl(string text)
{
try
{
// Check if the text looks like a URL
if (Uri.TryCreate(text, UriKind.Absolute, out var uri) &&
(uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
{
Process.Start(new ProcessStartInfo
{
FileName = text,
UseShellExecute = true
});
}
else if (text.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
text.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
Process.Start(new ProcessStartInfo
{
FileName = text,
UseShellExecute = true
});
}
}
catch (Exception)
{
// Failed to launch URL
}
}
public void TypeText(string text)
{
try
{
// Give a small delay to allow user to position cursor if needed
System.Threading.Thread.Sleep(100);
_inputSimulator.Keyboard.TextEntry(text);
}
catch (Exception)
{
// Failed to simulate keyboard input
}
}
}