Add single-instance enforcement and DirectWrite crash workaround

- Implement mutex-based single instance check
- Show message if app is already running
- Force software rendering to prevent DirectWrite font initialization crash
- Update version to 1.0.2

Fixes:
- Multiple instances could run simultaneously
- DirectWrite crash on certain Windows configurations

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-07 08:25:36 -08:00
parent f3323420a8
commit cff9bc4876
4 changed files with 32 additions and 4 deletions

View File

@@ -1,7 +1,9 @@
using System;
using System.Drawing;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using NfcActions.Services;
using NfcActions.ViewModels;
using Application = System.Windows.Application;
@@ -13,6 +15,7 @@ namespace NfcActions;
/// </summary>
public partial class App : Application
{
private static Mutex? _instanceMutex;
private NotifyIcon? _notifyIcon;
private Icon? _customIcon;
private MainWindow? _mainWindow;
@@ -24,6 +27,29 @@ public partial class App : Application
private void Application_Startup(object sender, StartupEventArgs e)
{
// Ensure only one instance runs at a time
bool createdNew;
_instanceMutex = new Mutex(true, "NfcActions_SingleInstance_Mutex", out createdNew);
if (!createdNew)
{
System.Windows.MessageBox.Show("NFC Actions is already running. Check the system tray.",
"NFC Actions",
MessageBoxButton.OK,
MessageBoxImage.Information);
Shutdown();
return;
}
// Workaround for DirectWrite crash - force software rendering
try
{
RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
}
catch
{
// Ignore if this fails
}
// Initialize services
_logService = new LogService();
_cardReaderService = new CardReaderService(_logService);
@@ -107,5 +133,7 @@ public partial class App : Application
_notifyIcon?.Dispose();
_customIcon?.Dispose();
_cardReaderService?.Dispose();
_instanceMutex?.ReleaseMutex();
_instanceMutex?.Dispose();
}
}

View File

@@ -7,9 +7,9 @@
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Resources\icon.ico</ApplicationIcon>
<Version>1.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Version>1.0.2</Version>
<AssemblyVersion>1.0.2.0</AssemblyVersion>
<FileVersion>1.0.2.0</FileVersion>
<Company>Dangerous Things</Company>
<Product>NFC Actions</Product>
<Description>NFC card reader monitoring and action automation</Description>