This commit is contained in:
Alexander Mohr 2025-05-26 17:36:12 +02:00
parent ceecc490a6
commit f1aceb18eb
2 changed files with 14 additions and 17 deletions

View file

@ -249,11 +249,11 @@ fn key_sync() -> KeyBinding {
} }
/// copies totp to clipboard /// copies totp to clipboard
fn key_totp() -> KeyBinding { fn key_totp_to_clipboard() -> KeyBinding {
KeyBinding { KeyBinding {
key: Key::T, key: Key::T,
modifiers: vec![Modifier::Alt].into_iter().collect(), modifiers: vec![Modifier::Alt].into_iter().collect(),
label: "<b>Alt+t</b> Totp".to_string(), label: "<b>Alt+t</b> Copy Totp".to_string(),
visible: true, visible: true,
} }
} }
@ -284,7 +284,7 @@ fn show(config: Config, provider: PasswordProvider) -> Result<(), String> {
key_type_totp(), key_type_totp(),
key_type_totp_and_enter(), key_type_totp_and_enter(),
key_sync(), key_sync(),
key_totp(), key_totp_to_clipboard(),
key_lock(), key_lock(),
], ],
hint: Some(CustomKeyHint { hint: Some(CustomKeyHint {
@ -317,7 +317,7 @@ fn show(config: Config, provider: PasswordProvider) -> Result<(), String> {
rbw("lock", None)?; rbw("lock", None)?;
} else if key == key_sync() { } else if key == key_sync() {
rbw("sync", None)?; rbw("sync", None)?;
} else if key == key_totp() { } else if key == key_totp_to_clipboard() {
rbw_get_totp(id, true)?; rbw_get_totp(id, true)?;
} }

View file

@ -4,14 +4,12 @@ use crate::gui::{ItemProvider, MenuItem};
use crate::{Error, gui}; use crate::{Error, gui};
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct EmojiProvider<T: Clone> { pub(crate) struct EmojiProvider {
elements: Vec<MenuItem<T>>, elements: Vec<MenuItem<String>>,
#[allow(dead_code)] // needed for the detection of mode in 'auto'
menu_item_data: T,
} }
impl<T: Clone> EmojiProvider<T> { impl EmojiProvider {
pub(crate) fn new(data: T, sort_order: &SortOrder, hide_label: bool) -> Self { pub(crate) fn new(sort_order: &SortOrder, hide_label: bool) -> Self {
let emoji = emoji::search::search_annotation_all(""); let emoji = emoji::search::search_annotation_all("");
let mut menus = emoji let mut menus = emoji
.into_iter() .into_iter()
@ -30,7 +28,7 @@ impl<T: Clone> EmojiProvider<T> {
vec![], vec![],
None, None,
0.0, 0.0,
Some(data.clone()), Some(e.glyph.to_string()),
) )
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -38,17 +36,16 @@ impl<T: Clone> EmojiProvider<T> {
Self { Self {
elements: menus, elements: menus,
menu_item_data: data.clone(),
} }
} }
} }
impl<T: Clone> ItemProvider<T> for EmojiProvider<T> { impl ItemProvider<String> for EmojiProvider {
fn get_elements(&mut self, _: Option<&str>) -> (bool, Vec<MenuItem<T>>) { fn get_elements(&mut self, _: Option<&str>) -> (bool, Vec<MenuItem<String>>) {
(false, self.elements.clone()) (false, self.elements.clone())
} }
fn get_sub_elements(&mut self, _: &MenuItem<T>) -> (bool, Option<Vec<MenuItem<T>>>) { fn get_sub_elements(&mut self, _: &MenuItem<String>) -> (bool, Option<Vec<MenuItem<String>>>) {
(false, None) (false, None)
} }
} }
@ -58,9 +55,9 @@ impl<T: Clone> ItemProvider<T> for EmojiProvider<T> {
/// ///
/// Forwards errors from the gui. See `gui::show` for details. /// Forwards errors from the gui. See `gui::show` for details.
pub fn show(config: &Config) -> Result<(), Error> { pub fn show(config: &Config) -> Result<(), Error> {
let provider = EmojiProvider::new(0, &config.sort_order(), config.emoji_hide_label()); let provider = EmojiProvider::new( &config.sort_order(), config.emoji_hide_label());
let selection_result = gui::show(config.clone(), provider, true, None, None)?; let selection_result = gui::show(config.clone(), provider, true, None, None)?;
match selection_result.menu.action { match selection_result.menu.data {
None => Err(Error::MissingAction), None => Err(Error::MissingAction),
Some(action) => copy_to_clipboard(action, None), Some(action) => copy_to_clipboard(action, None),
} }