public async Task <bool> WaitMutex(bool force, IntPtr wParam, IntPtr lParam) { bool exist = !WaitMutexInternal(force); if (exist) { string[] originalArgs = Environment.GetCommandLineArgs(); string[] args = new string[originalArgs.Length - 1]; if (args.Length > 0) { args = originalArgs.Skip(1).ToArray(); } if (args.Length > 0) { await SendMessageStringUtf8("SendArgs", string.Join(" || ", args)) .ConfigureAwait(true); } else { _ = WindowNative.PostMessage((IntPtr)WindowNative.HwndBroadcast, SingleInstanceMessage, wParam, lParam); } } else { InstanceBus = new TinyMessageBus($"Bus_{UniqueName}"); InstanceBus.MessageReceived += InstanceBus_MessageReceived; } return(!exist); }
private void InstanceBus_MessageReceived(object sender, TinyMessageReceivedEventArgs e) { var message = UnwrapMessage(e.Message); if (!message.HasValue) { return; } LogManager.Debug.Info($"Receive message - name = {message.Value.Name}, " + $"type = {message.Value.ContentType}, restoreWindow = {message.Value.RestoreWindow}"); if (message.Value.ContentType == IpcBusContentType.StringUtf8) { LogManager.Debug.Info($"Receive message content - {message.Value.GetStringUtf8()}"); } if (message.Value.Name == "SendArgs") { var args = message.Value.GetStringUtf8().Split(" || "); var wrapper = App.UnwrapArgs(args); foreach (var argEntry in wrapper.Enumerate()) { switch (argEntry.Key) { case "startupUri": var startupUri = (string)argEntry.Value; if (!string.IsNullOrEmpty(startupUri)) { ProtocolManager.ParseUri(startupUri); } break; case "createHashFiles": var createHashFilesString = (string)argEntry.Value; bool createHashFiles; try { createHashFiles = string.IsNullOrWhiteSpace(createHashFilesString) || createHashFilesString.ToBoolean(); } catch (Exception) { createHashFiles = false; } if (createHashFiles) { App.CreateHashFiles(); } break; default: break; } } } else { return; } if (message.Value.RestoreWindow) { _ = WindowNative.PostMessage((IntPtr)WindowNative.HwndBroadcast, SingleInstanceMessage, IntPtr.Zero, IntPtr.Zero); } }