From f24b99fcbd64cb5ec71692e0c970ffba8f6b0b6f Mon Sep 17 00:00:00 2001 From: heartacker Date: Thu, 31 Jul 2025 19:00:03 +0800 Subject: [PATCH] feat: support launch a debug sourcegit --- src/Models/IpcChannel.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Models/IpcChannel.cs b/src/Models/IpcChannel.cs index 001c65a65..773a220f5 100644 --- a/src/Models/IpcChannel.cs +++ b/src/Models/IpcChannel.cs @@ -8,6 +8,14 @@ namespace SourceGit.Models { public class IpcChannel : IDisposable { + +#if DEBUG + private readonly string PROC_LOCK = "process.debug.lock"; + private readonly string IPC_NAME = "SourceGitIPCChannel.Debug"; +#else + private readonly string PROC_LOCK = "process.lock"; + private readonly string IPC_NAME = "SourceGitIPCChannel"; +#endif public bool IsFirstInstance { get; } public event Action MessageReceived; @@ -16,10 +24,11 @@ public IpcChannel() { try { - _singletonLock = File.Open(Path.Combine(Native.OS.DataDir, "process.lock"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); + _singletonLock = File.Open(Path.Combine(Native.OS.DataDir, PROC_LOCK), + FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); IsFirstInstance = true; _server = new NamedPipeServerStream( - "SourceGitIPCChannel" + Environment.UserName, + IPC_NAME + Environment.UserName, PipeDirection.In, -1, PipeTransmissionMode.Byte, @@ -37,7 +46,7 @@ public void SendToFirstInstance(string cmd) { try { - using (var client = new NamedPipeClientStream(".", "SourceGitIPCChannel" + Environment.UserName, PipeDirection.Out, PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly)) + using (var client = new NamedPipeClientStream(".", IPC_NAME + Environment.UserName, PipeDirection.Out, PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly)) { client.Connect(1000); if (!client.IsConnected) @@ -93,8 +102,8 @@ private async void StartServer() } } - private FileStream _singletonLock = null; - private NamedPipeServerStream _server = null; - private CancellationTokenSource _cancellationTokenSource = null; + private readonly FileStream _singletonLock = null; + private readonly NamedPipeServerStream _server = null; + private readonly CancellationTokenSource _cancellationTokenSource = null; } }