-
-
Notifications
You must be signed in to change notification settings - Fork 368
fix(core): apply application selectors to Actions Ring layouts #643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AprilNEA
wants to merge
1
commit into
master
Choose a base branch
from
fix/app-selector-ring-parity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+174
−28
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| //! Resolving a foreground-application identifier against per-app config keys. | ||
| //! | ||
| //! Per-app overlays are keyed by whatever the platform reports as the frontmost | ||
| //! application: a bundle identifier on macOS, a `WM_CLASS` or xdg app id on | ||
| //! Linux, and a lower-cased executable path on Windows. A Windows path is not | ||
| //! stable — Store and self-updating applications live under a versioned | ||
| //! directory that changes from under the config — so `exe:<filename>.exe` is | ||
| //! accepted as a fallback selector for the same overlay maps. | ||
| //! | ||
| //! Every map keyed by that identifier resolves through [`overlay_for`], so a | ||
| //! selector means the same thing wherever it is written: button overlays and | ||
| //! Actions Ring layouts cannot disagree about which application is in front. | ||
|
|
||
| use std::collections::BTreeMap; | ||
| use std::path::Path; | ||
|
|
||
| /// Resolve the most specific overlay for a foreground identifier. | ||
| /// | ||
| /// An exact key always wins, so a per-path overlay still beats the | ||
| /// executable-name fallback when a config carries both. | ||
| pub(crate) fn overlay_for<'a, T>(overlays: &'a BTreeMap<String, T>, app: &str) -> Option<&'a T> { | ||
| if let Some(exact) = overlays.get(app) { | ||
| return Some(exact); | ||
| } | ||
|
|
||
| overlays.get(&executable_selector(app)?) | ||
| } | ||
|
|
||
| /// The `exe:<filename>` selector a Windows-style identifier falls back to, or | ||
| /// `None` for an identifier that does not name an executable — macOS bundle ids | ||
| /// and Linux application classes must never acquire one by accident. | ||
| fn executable_selector(app: &str) -> Option<String> { | ||
| // `rsplit` always yields, so this is the trailing path component, or the | ||
| // whole identifier when it carries no separator. Both separators are | ||
| // recognized so a Windows config stays inspectable on any platform. | ||
| let executable_name = app.rsplit(['\\', '/']).next().unwrap_or(app); | ||
| if executable_name.is_empty() | ||
| || !Path::new(executable_name) | ||
| .extension() | ||
| .is_some_and(|extension| extension.eq_ignore_ascii_case("exe")) | ||
| { | ||
| return None; | ||
| } | ||
| Some(format!("exe:{}", executable_name.to_ascii_lowercase())) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| fn overlays(keys: &[&str]) -> BTreeMap<String, &'static str> { | ||
| keys.iter() | ||
| .map(|key| ((*key).to_string(), "overlay")) | ||
| .collect() | ||
| } | ||
|
|
||
| #[test] | ||
| fn exact_key_wins_over_the_executable_fallback() { | ||
| let mut map = BTreeMap::new(); | ||
| map.insert( | ||
| r"c:\program files\windowsapps\sharex_16.0_x64\sharex.exe".to_string(), | ||
| "exact", | ||
| ); | ||
| map.insert("exe:sharex.exe".to_string(), "fallback"); | ||
| assert_eq!( | ||
| overlay_for( | ||
| &map, | ||
| r"c:\program files\windowsapps\sharex_16.0_x64\sharex.exe" | ||
| ), | ||
| Some(&"exact") | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_versioned_path_falls_back_to_the_executable_name() { | ||
| let map = overlays(&["exe:sharex.exe"]); | ||
| // The install directory carries the version, so only the basename is | ||
| // stable across updates. | ||
| for path in [ | ||
| r"c:\program files\windowsapps\sharex_16.0_x64\sharex.exe", | ||
| r"c:\program files\windowsapps\sharex_17.1_x64\sharex.exe", | ||
| "/c/program files/sharex/sharex.exe", | ||
| "sharex.exe", | ||
| ] { | ||
| assert_eq!(overlay_for(&map, path), Some(&"overlay"), "{path}"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn identifiers_that_name_no_executable_never_fall_back() { | ||
| let map = overlays(&["exe:code.exe", "exe:.exe"]); | ||
| // macOS bundle ids and Linux classes must not be reinterpreted as paths, | ||
| // and a path with no executable name has nothing stable to match on. | ||
| for app in [ | ||
| "com.microsoft.VSCode", | ||
| "Firefox", | ||
| "org.mozilla.firefox", | ||
| r"c:\program files\microsoft vs code\code.exe.bak", | ||
| r"c:\program files\microsoft vs code\", | ||
| "", | ||
| ] { | ||
| assert_eq!(overlay_for(&map, app), None, "{app}"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_bundle_id_ending_in_exe_still_resolves_by_its_own_key() { | ||
| // Contrived, but it must not be swallowed by the fallback: the exact | ||
| // key is what the platform reported. | ||
| let mut map = BTreeMap::new(); | ||
| map.insert("com.example.exe".to_string(), "exact"); | ||
| assert_eq!(overlay_for(&map, "com.example.exe"), Some(&"exact")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.exeidentifiers collideIf a macOS bundle ID or Linux application ID ends in
.exe, has no exact ring entry, and shares its name with anexe:entry,overlay_fortreats it as a Windows executable selector and applies an unrelated Actions Ring layout.Knowledge Base Used: openlogi-core