diff --git a/CursorLang/Services/SingleInstanceGate.cs b/CursorLang/Services/SingleInstanceGate.cs index bded8a0..09d29c1 100644 --- a/CursorLang/Services/SingleInstanceGate.cs +++ b/CursorLang/Services/SingleInstanceGate.cs @@ -20,13 +20,31 @@ public sealed class SingleInstanceGate : IDisposable private const string ActivationEventName = "CursorLang.ActivationRequest"; private readonly Dispatcher _dispatcher = Dispatcher.CurrentDispatcher; + private readonly string _mutexName; + private readonly string _activationEventName; private Mutex? _mutex; private EventWaitHandle? _activationRequest; private RegisteredWaitHandle? _activationWait; private bool _isOwner; - /// Другой запуск просит показать окно. + public SingleInstanceGate() + : this(string.Empty) + { + } + + /// + /// Adds a distinguishing part to the kernel object names. Needed by the tests: + /// otherwise they would share the single-instance slot with the running + /// application and get in its way. + /// + internal SingleInstanceGate(string nameSuffix) + { + _mutexName = MutexName + nameSuffix; + _activationEventName = ActivationEventName + nameSuffix; + } + + /// Another launch asks for the window to be shown. public event EventHandler? ActivationRequested; /// @@ -35,7 +53,7 @@ public sealed class SingleInstanceGate : IDisposable /// public bool TryAcquire() { - _mutex = new Mutex(initiallyOwned: false, MutexName); + _mutex = new Mutex(initiallyOwned: false, _mutexName); try {