From 6fe8eca3269ac076ae0e200b3b3a141358319507 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Tue, 2 Jul 2024 21:16:35 +0800 Subject: [PATCH] add reader config item (#76) --- pkg/config/user.go | 19 ++++++++++++++++--- pkg/daemon/reader.go | 7 +++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pkg/config/user.go b/pkg/config/user.go index 29c93f8b..58537349 100644 --- a/pkg/config/user.go +++ b/pkg/config/user.go @@ -34,11 +34,12 @@ const UserConfigEnv = "TAPTO_CONFIG" const UserAppPathEnv = "TAPTO_APP_PATH" type TapToConfig struct { - ConnectionString string `ini:"connection_string"` - AllowCommands bool `ini:"allow_commands"` + ConnectionString string `ini:"connection_string"` // DEPRECATED + Reader []string `ini:"reader,omitempty,allowshadow"` + AllowCommands bool `ini:"allow_commands"` // TODO: rename to allow_shell DisableSounds bool `ini:"disable_sounds"` ProbeDevice bool `ini:"probe_device"` - ExitGame bool `ini:"exit_game"` + ExitGame bool `ini:"exit_game"` // TODO: rename to insert_mode ExitGameBlocklist []string `ini:"exit_game_blocklist"` ExitGameDelay int8 `ini:"exit_game_delay"` Debug bool `ini:"debug"` @@ -69,6 +70,18 @@ func (c *UserConfig) SetConnectionString(connectionString string) { c.TapTo.ConnectionString = connectionString } +func (c *UserConfig) GetReader() []string { + c.mu.RLock() + defer c.mu.RUnlock() + return c.TapTo.Reader +} + +func (c *UserConfig) SetReader(reader []string) { + c.mu.Lock() + defer c.mu.Unlock() + c.TapTo.Reader = reader +} + func (c *UserConfig) GetAllowCommands() bool { c.mu.RLock() defer c.mu.RUnlock() diff --git a/pkg/daemon/reader.go b/pkg/daemon/reader.go index 5bc50473..f019703b 100644 --- a/pkg/daemon/reader.go +++ b/pkg/daemon/reader.go @@ -59,6 +59,13 @@ func connectReaders( toConnect = append(toConnect, userDevice) } + for _, device := range cfg.GetReader() { + if !utils.Contains(rs, device) && !utils.Contains(toConnect, device) { + log.Debug().Msgf("config device not connected, adding: %s", device) + toConnect = append(toConnect, device) + } + } + for _, device := range toConnect { if _, ok := st.GetReader(device); !ok { ps := strings.SplitN(device, ":", 2)