Dustin Westaby - 2024-08-14

I tested below and is working well :) When I launch my kitty client from Serial Port Notifier, the window title is renamed with the COM# and Custom Port Name defined in Serial Port Notifier.

Code Changes:

Launcher.vb: Public Class Launcher

  Public Sub Launch(serialPort As String, Optional customPortName As String = "")
    Try
      Process.Start(Executable, GetCommandLine(serialPort, customPortName))
    Catch ex As Exception
      MessageBox.Show(String.Format("Failed to start launcher: {0}", ex.Message), "Launcher", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
  End Sub

  Public Function GetCommandLine(serialPort As String, customPortName As String) As String
    Return CommandLine.Replace("%1", serialPort) _
                      .Replace("%2", GetPortNumber(serialPort).ToString()) _
                      .Replace("%3", If(String.IsNullOrEmpty(customPortName), serialPort, customPortName))
  End Function

  Public Overrides Function ToString() As String
    Dim CommandLine As String = GetCommandLine("COM15", "")
    Return String.Format("{0} ({1}{2})", Label, Path.GetFileName(Executable), IIf(CommandLine = "", "", " " + CommandLine))
  End Function

LauncherDialog.Designer.vb

    Me.Label8.Text = "Command Line Options:" & vbCrLf &
                         "%1 - COM port name (e.g. COM15)" & vbCrLf &
                         "%2 - COM port number (e.g. 15)" & vbCrLf &
                         "%3 - COM port renamed label (e.g. USB TTL)"

LauncherDialog.vb: UpdatePreview()

        lblPreview.Text = String.Format("Preview: {0} {1}", Path.GetFileName(launcher.Executable), launcher.GetCommandLine("COM15", "COM15"))

Main.vb: BuildMenu()

        If SerialPorts.Count > 0 Then
          For i As Integer = SerialPorts.Count - 1 To 0 Step -1
            Dim portName As String = SerialPorts(i)
            Dim customPortName As String = If(CustomPortNames.ContainsKey(portName), CustomPortNames(portName), portName)
            Dim port = New ToolStripMenuItem(GetCustomPortNames(portName))
            .Add(port)
            ' Now add the launchers
            If ProgramLaunchers.Count > 0 Then
              For Each l In ProgramLaunchers
                port.DropDownItems.Add(l.Label, Nothing, New EventHandler(Sub()
                                                                            l.Launch(portName, customPortName)
                                                                          End Sub))