Skip to content

Commit

Permalink
add reader config item (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
wizzomafizzo authored Jul 2, 2024
1 parent 9f9e4e8 commit 6fe8eca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pkg/config/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions pkg/daemon/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6fe8eca

Please sign in to comment.