Skip to main content

app_matches

Function app_matches 

Source
pub fn app_matches(reported: &str, target: &str) -> bool
Expand description

Whether something the platform named is the application a binding meant.

Here rather than in each addon, because ParamKind::App is declared here and an addon author has no way to guess how to compare one. The value stored in a binding is whatever Nobble’s foreground watcher reports — exe:spotify.exe — and what the addon is comparing it against comes from somewhere else entirely, in whatever form that API uses.

So the comparison is on the stem: exe:spotify.exe and Spotify.exe both reduce to spotify. The Windows media session reports Spotify.exe for a desktop install and SpotifyAB.SpotifyMusic_…!Spotify for the Store build, and matching either exactly would work on one machine and not the next.

An empty target matches nothing, which is the opposite of what an unconstrained match would do. Naming a target means “this one”, and a blank field that matched everything would turn a typo into a key that controls whatever happens to be loudest.

assert!(app_matches("Spotify.exe", "exe:spotify.exe"));
assert!(app_matches("SpotifyAB.SpotifyMusic_zpdnekdrzrea0!Spotify", "exe:spotify.exe"));
assert!(!app_matches("chrome.exe", "exe:spotify.exe"));
assert!(!app_matches("Spotify.exe", ""));