Skip to content
Closed
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
17 changes: 14 additions & 3 deletions src/android/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,32 @@ use gpui_wgpu::GpuContext;

// ── stub: clipboard ───────────────────────────────────────────────────────────

/// Android clipboard (thin wrapper over `ClipboardManager` via JNI).
/// Android clipboard.
///
/// A real implementation would call into Java via `jni-rs`; for now we use
/// an in-process string store so the rest of the platform compiles.
/// With the `clipboard` feature this goes through the system `ClipboardManager`
/// (`dev.gpui.mobile.GpuiClipboard`), so text copied in GPUI can be pasted in other
/// apps and vice versa. Without the feature, or when the JNI call fails (the host did
/// not package `GpuiClipboard.java`), it falls back to an in-process string store.
#[derive(Default)]
pub struct AndroidClipboard {
contents: Option<String>,
}

impl AndroidClipboard {
pub fn read(&self) -> Option<String> {
#[cfg(feature = "clipboard")]
match crate::packages::clipboard::get_text() {
Ok(text) => return text,
Err(err) => log::warn!("system clipboard read failed, using local copy: {err}"),
}
self.contents.clone()
}

pub fn write(&mut self, text: String) {
#[cfg(feature = "clipboard")]
if let Err(err) = crate::packages::clipboard::set_text(&text) {
log::warn!("system clipboard write failed, keeping local copy: {err}");
}
self.contents = Some(text);
}

Expand Down