Skip to content

Commit

Permalink
feat: add tcp_port config entry
Browse files Browse the repository at this point in the history
  • Loading branch information
rszyma committed Feb 20, 2024
1 parent 280d952 commit d9cfb13
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ qwerty = "qwerty.ico"
include_executables_from_system_path = false # default: true
include_configs_from_default_locations = false # default: true
launch_on_start = true # default: true
tcp_port = 5829 # default: 5829
```

Notes:
Expand Down
12 changes: 7 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ type SysTrayApp struct {
layerIcons LayerIcons
selectedConfig int
selectedExec int
cfgChangeCh chan int
exeChangeCh chan int
tcpPort int

cfgChangeCh chan int
exeChangeCh chan int

// Menu items

Expand All @@ -40,8 +42,8 @@ type SysTrayApp struct {
mQuit *systray.MenuItem
}

func NewSystrayApp(menuTemplate *MenuTemplate, layerIcons LayerIcons) *SysTrayApp {
t := &SysTrayApp{menuTemplate: menuTemplate, layerIcons: layerIcons, selectedConfig: -1, selectedExec: -1}
func NewSystrayApp(menuTemplate *MenuTemplate, layerIcons LayerIcons, tcpPort int) *SysTrayApp {
t := &SysTrayApp{menuTemplate: menuTemplate, layerIcons: layerIcons, selectedConfig: -1, selectedExec: -1, tcpPort: tcpPort}

systray.SetIcon(icons.Default)
systray.SetTitle("kanata-tray")
Expand Down Expand Up @@ -141,7 +143,7 @@ func (t *SysTrayApp) runWithSelectedOptions(runner *runner.KanataRunner) {

execPath := t.menuTemplate.Executables[t.selectedExec].Value
configPath := t.menuTemplate.Configurations[t.selectedConfig].Value
err := runner.Run(execPath, configPath)
err := runner.Run(execPath, configPath, t.tcpPort)
if err != nil {
fmt.Printf("runner.Run failed with: %v\n", err)
t.runnerStatus = statusCrashed
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type GeneralConfigOptions struct {
IncludeExecutablesFromSystemPath bool `toml:"include_executables_from_system_path"`
IncludeConfigsFromDefaultLocations bool `toml:"include_configs_from_default_locations"`
LaunchOnStart bool `toml:"launch_on_start"`
TcpPort int `toml:"tcp_port"`
}

func ReadConfigOrCreateIfNotExist(configFilePath string) (*Config, error) {
Expand Down Expand Up @@ -68,4 +69,5 @@ executables = [
include_executables_from_system_path = true
include_configs_from_default_locations = true
launch_on_start = true
tcp_port = 5829
`
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ just:
just -l

run:
CGO_ENABLED=1 GO111MODULE=on go run . -ldflags "-H=windowsgui"
CGO_ENABLED=1 GO111MODULE=on go run .

build_release_linux version="latest":
GOOS=linux CGO_ENABLED=1 GO111MODULE=on go build -ldflags "-s -w -X 'main.buildVersion={{version}}' -X 'main.buildHash=$(git rev-parse HEAD)' -X 'main.buildDate=$(date -u)'" -trimpath -o dist/kanata-tray
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func mainImpl() error {
runner := runner.NewKanataRunner()

onReady := func() {
app := app.NewSystrayApp(&menuTemplate, layerIcons)
app := app.NewSystrayApp(&menuTemplate, layerIcons, cfg.General.TcpPort)
go app.StartProcessingLoop(&runner, cfg.General.LaunchOnStart, configFolder)
}

Expand Down
4 changes: 1 addition & 3 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ func (r *KanataRunner) CleanupLogs() error {
return nil
}

func (r *KanataRunner) Run(kanataExecutablePath string, kanataConfigPath string) error {
func (r *KanataRunner) Run(kanataExecutablePath string, kanataConfigPath string, tcpPort int) error {
err := r.Stop()
if err != nil {
return fmt.Errorf("failed to stop the previous process: %v", err)
}

const tcpPort = 5829 // arbitrary number, really

cmd := exec.CommandContext(r.ctx, kanataExecutablePath, "-c", kanataConfigPath, "--port", fmt.Sprint(tcpPort))
cmd.SysProcAttr = os_specific.ProcessAttr

Expand Down

0 comments on commit d9cfb13

Please sign in to comment.