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

@@ -3,7 +3,7 @@
<Product Id="*" <Product Id="*"
Name="NFC Actions" Name="NFC Actions"
Language="1033" Language="1033"
Version="1.0.0.0" Version="1.0.2.0"
Manufacturer="Dangerous Things" Manufacturer="Dangerous Things"
UpgradeCode="A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D"> UpgradeCode="A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D">

BIN
NfcActions-Setup-v1.0.2.msi Normal file

Binary file not shown.

View File

@@ -1,7 +1,9 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Media;
using NfcActions.Services; using NfcActions.Services;
using NfcActions.ViewModels; using NfcActions.ViewModels;
using Application = System.Windows.Application; using Application = System.Windows.Application;
@@ -13,6 +15,7 @@ namespace NfcActions;
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
private static Mutex? _instanceMutex;
private NotifyIcon? _notifyIcon; private NotifyIcon? _notifyIcon;
private Icon? _customIcon; private Icon? _customIcon;
private MainWindow? _mainWindow; private MainWindow? _mainWindow;
@@ -24,6 +27,29 @@ public partial class App : Application
private void Application_Startup(object sender, StartupEventArgs e) 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 // Initialize services
_logService = new LogService(); _logService = new LogService();
_cardReaderService = new CardReaderService(_logService); _cardReaderService = new CardReaderService(_logService);
@@ -107,5 +133,7 @@ public partial class App : Application
_notifyIcon?.Dispose(); _notifyIcon?.Dispose();
_customIcon?.Dispose(); _customIcon?.Dispose();
_cardReaderService?.Dispose(); _cardReaderService?.Dispose();
_instanceMutex?.ReleaseMutex();
_instanceMutex?.Dispose();
} }
} }

View File

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