mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-11 17:32:11 +00:00
Document & deduplicate global shortcut code
This commit is contained in:
parent
aaa8096f4a
commit
078a183797
@ -20,7 +20,7 @@ use ashpd::desktop::{CreateSessionOptions, ResponseError};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
use ashpd::desktop::global_shortcuts::{
|
||||
BindShortcutsOptions, GlobalShortcuts, ListShortcutsOptions, NewShortcut,
|
||||
BindShortcutsOptions, GlobalShortcuts, ListShortcutsOptions, NewShortcut, Shortcut as AshpdShortcut,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@ -510,6 +510,18 @@ struct PortalShortcutInfo {
|
||||
effective_display_name: String,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
/// Normalizes shortcuts returned by `ashpd` for backend-independent processing.
|
||||
fn normalize_portal_shortcuts(shortcuts: &[AshpdShortcut]) -> Vec<PortalShortcutInfo> {
|
||||
shortcuts
|
||||
.iter()
|
||||
.map(|shortcut| PortalShortcutInfo {
|
||||
id: shortcut.id().to_string(),
|
||||
effective_display_name: shortcut.trigger_description().to_string(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Abstracts portal listing and binding operations for deterministic lifecycle tests.
|
||||
trait PortalAdapter {
|
||||
/// Lists shortcuts restored into the current portal session.
|
||||
@ -576,14 +588,7 @@ impl PortalAdapter for AshpdPortalAdapter<'_> {
|
||||
.and_then(|request| request.response())
|
||||
.map_err(PortalFailure::from_error)?;
|
||||
|
||||
Ok(response
|
||||
.shortcuts()
|
||||
.iter()
|
||||
.map(|shortcut| PortalShortcutInfo {
|
||||
id: shortcut.id().to_string(),
|
||||
effective_display_name: shortcut.trigger_description().to_string(),
|
||||
})
|
||||
.collect())
|
||||
Ok(normalize_portal_shortcuts(response.shortcuts()))
|
||||
}
|
||||
|
||||
/// Binds one shortcut through the XDG portal and normalizes its response.
|
||||
@ -601,14 +606,7 @@ impl PortalAdapter for AshpdPortalAdapter<'_> {
|
||||
.and_then(|request| request.response())
|
||||
.map_err(PortalFailure::from_error)?;
|
||||
|
||||
Ok(response
|
||||
.shortcuts()
|
||||
.iter()
|
||||
.map(|shortcut| PortalShortcutInfo {
|
||||
id: shortcut.id().to_string(),
|
||||
effective_display_name: shortcut.trigger_description().to_string(),
|
||||
})
|
||||
.collect())
|
||||
Ok(normalize_portal_shortcuts(response.shortcuts()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user