Skip to content

desktop: Make clipboard support optional #15535

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

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions desktop/src/backends/ui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::preferences::GlobalPreferences;
use anyhow::{Context, Error};
use anyhow::Error;
use arboard::Clipboard;
use chrono::{DateTime, Utc};
use fontdb::Family;
Expand Down Expand Up @@ -117,7 +117,7 @@ impl FileDialogResult for DesktopFileDialogResult {
pub struct DesktopUiBackend {
window: Rc<Window>,
cursor_visible: bool,
clipboard: Clipboard,
clipboard: Option<Clipboard>,
preferences: GlobalPreferences,
preferred_cursor: MouseCursor,
open_url_mode: OpenURLMode,
Expand All @@ -136,7 +136,9 @@ impl DesktopUiBackend {
Ok(Self {
window,
cursor_visible: true,
clipboard: Clipboard::new().context("Couldn't get platform clipboard")?,
clipboard: Clipboard::new()
.inspect_err(|err| tracing::error!("Failed to initialize clipboard: {err}"))
.ok(),
preferences,
preferred_cursor: MouseCursor::Arrow,
open_url_mode,
Expand Down Expand Up @@ -175,12 +177,18 @@ impl UiBackend for DesktopUiBackend {
}

fn clipboard_content(&mut self) -> String {
self.clipboard.get_text().unwrap_or_default()
if let Some(ref mut clipboard) = self.clipboard {
clipboard.get_text().unwrap_or_default()
} else {
"".to_string()
}
}

fn set_clipboard_content(&mut self, content: String) {
if let Err(e) = self.clipboard.set_text(content) {
error!("Couldn't set clipboard contents: {:?}", e);
if let Some(ref mut clipboard) = self.clipboard {
if let Err(e) = clipboard.set_text(content) {
error!("Couldn't set clipboard contents: {:?}", e);
}
}
}

Expand Down