Skip to content

Commit 253e735

Browse files
authored
fix(matchers): ensure both desc/name match when provided (#15)
## What does this PR do? Simple bugfix + test for this scenario, occurred while testing a new TUI. ## Related issues <!-- Closes #234 -->
2 parents 4131705 + 4ca806f commit 253e735

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

internal/matchers/matcher.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ func (m *Matcher) scoreProfile(cfg *config.RawConfig, conditions *config.Profile
6969

7070
for _, condition := range conditions.RequiredMonitors {
7171
for _, connectedMonitor := range connectedMonitors {
72+
// if both are defined but there is a mismatch on either then skip
73+
if condition.Name != nil && condition.Description != nil &&
74+
(*condition.Name != connectedMonitor.Name ||
75+
*condition.Description != connectedMonitor.Description) {
76+
continue
77+
}
7278
if condition.Name != nil && *condition.Name == connectedMonitor.Name {
7379
profileScore += *cfg.Scoring.NameMatch
7480
}

internal/matchers/matcher_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,29 @@ func TestMatcher_Match(t *testing.T) {
255255
expectedProfile: "",
256256
description: "Should return no match when no profile matches and no fallback is configured",
257257
},
258+
{
259+
name: "both_name_and_description_must_match_same_monitor",
260+
config: createTestConfig(t, map[string]*config.Profile{
261+
"strict_match": {
262+
Name: "strict_match",
263+
Conditions: &config.ProfileCondition{
264+
RequiredMonitors: []*config.RequiredMonitor{
265+
{
266+
Name: utils.StringPtr("eDP-1"),
267+
Description: utils.StringPtr("External Monitor"),
268+
},
269+
},
270+
},
271+
},
272+
}).Get(),
273+
connectedMonitors: []*hypr.MonitorSpec{
274+
{Name: "eDP-1", ID: utils.IntPtr(0), Description: "Built-in Display"},
275+
{Name: "DP-1", ID: utils.IntPtr(1), Description: "External Monitor"},
276+
},
277+
powerState: power.ACPowerState,
278+
expectedProfile: "",
279+
description: "Profile should not match when name comes from one monitor and description from another",
280+
},
258281
}
259282

260283
for _, tt := range tests {

0 commit comments

Comments
 (0)