Skip to content

Commit

Permalink
make clipboard support optional
Browse files Browse the repository at this point in the history
not all platforms (android for instance) support this
  • Loading branch information
doy committed Dec 28, 2024
1 parent fd03616 commit 5814122
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ block-padding = "0.3.3"
cbc = { version = "0.1.2", features = ["alloc", "std"] }
clap_complete = "4.5.40"
clap = { version = "4.5.23", features = ["wrap_help", "derive"] }
cli-clipboard = "0.4.0"
daemonize = "0.5.0"
# TODO: directories 5.0.1 uses MPL code, which isn't license-compatible
# we should switch to something else at some point
Expand Down Expand Up @@ -69,6 +68,12 @@ urlencoding = "2.1.3"
uuid = { version = "1.11.0", features = ["v4"] }
zeroize = "1.8.1"

cli-clipboard = { version = "0.4.0", optional = true }

[features]
default = ["clipboard"]
clipboard = ["cli-clipboard"]

[lints.clippy]
cargo = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
Expand Down
18 changes: 17 additions & 1 deletion src/bin/rbw-agent/actions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Context as _;
use cli_clipboard::ClipboardProvider as _;

pub async fn register(
sock: &mut crate::sock::Sock,
Expand Down Expand Up @@ -591,11 +590,14 @@ pub async fn encrypt(
Ok(())
}

#[cfg(feature = "clipboard")]
pub async fn clipboard_store(
sock: &mut crate::sock::Sock,
state: std::sync::Arc<tokio::sync::Mutex<crate::agent::State>>,
text: &str,
) -> anyhow::Result<()> {
use cli_clipboard::ClipboardProvider as _;

state
.lock()
.await
Expand All @@ -610,6 +612,20 @@ pub async fn clipboard_store(
Ok(())
}

#[cfg(not(feature = "clipboard"))]
pub async fn clipboard_store(
sock: &mut crate::sock::Sock,
_state: std::sync::Arc<tokio::sync::Mutex<crate::agent::State>>,
_text: &str,
) -> anyhow::Result<()> {
sock.send(&rbw::protocol::Response::Error {
error: "clipboard not supported".to_string(),
})
.await?;

Ok(())
}

pub async fn version(sock: &mut crate::sock::Sock) -> anyhow::Result<()> {
sock.send(&rbw::protocol::Response::Version {
version: rbw::protocol::version(),
Expand Down
9 changes: 6 additions & 3 deletions src/bin/rbw-agent/agent.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use anyhow::Context as _;
use cli_clipboard::ClipboardProvider as _;
use futures_util::StreamExt as _;

#[cfg(feature = "clipboard")]
use cli_clipboard::ClipboardProvider as _;

pub struct State {
pub priv_key: Option<rbw::locked::Keys>,
pub org_keys:
Expand All @@ -11,6 +13,7 @@ pub struct State {
pub sync_timeout: crate::timeout::Timeout,
pub sync_timeout_duration: std::time::Duration,
pub notifications_handler: crate::notifications::Handler,
#[cfg(feature = "clipboard")]
pub clipboard: cli_clipboard::ClipboardContext,
}

Expand Down Expand Up @@ -59,7 +62,6 @@ impl Agent {
sync_timeout.set(sync_timeout_duration);
}
let notifications_handler = crate::notifications::Handler::new();
let clipboard = cli_clipboard::ClipboardContext::new().unwrap();
Ok(Self {
timer_r,
sync_timer_r,
Expand All @@ -71,7 +73,8 @@ impl Agent {
sync_timeout,
sync_timeout_duration,
notifications_handler,
clipboard,
#[cfg(feature = "clipboard")]
clipboard: cli_clipboard::ClipboardContext::new().unwrap(),
})),
})
}
Expand Down
10 changes: 10 additions & 0 deletions src/bin/rbw/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum Opt {
full: bool,
#[structopt(long, help = "Display output as JSON")]
raw: bool,
#[cfg(feature = "clipboard")]
#[structopt(long, help = "Copy result to clipboard")]
clipboard: bool,
#[structopt(short, long, help = "Ignore case")]
Expand All @@ -94,6 +95,7 @@ enum Opt {
user: Option<String>,
#[arg(long, help = "Folder name to search in")]
folder: Option<String>,
#[cfg(feature = "clipboard")]
#[structopt(long, help = "Copy result to clipboard")]
clipboard: bool,
#[arg(short, long, help = "Ignore case")]
Expand Down Expand Up @@ -334,6 +336,7 @@ fn main() {
field,
full,
raw,
#[cfg(feature = "clipboard")]
clipboard,
ignorecase,
} => commands::get(
Expand All @@ -343,7 +346,10 @@ fn main() {
field.as_deref(),
*full,
*raw,
#[cfg(feature = "clipboard")]
*clipboard,
#[cfg(not(feature = "clipboard"))]
false,
*ignorecase,
),
Opt::Search { term, folder } => {
Expand All @@ -353,13 +359,17 @@ fn main() {
needle,
user,
folder,
#[cfg(feature = "clipboard")]
clipboard,
ignorecase,
} => commands::code(
needle,
user.as_deref(),
folder.as_deref(),
#[cfg(feature = "clipboard")]
*clipboard,
#[cfg(not(feature = "clipboard"))]
false,
*ignorecase,
),
Opt::Add {
Expand Down

0 comments on commit 5814122

Please sign in to comment.