feat: add Android/Termux support by gating arboard dependency (#2895)
## Summary This PR enables Codex to build and run on Android/Termux environments by conditionally gating the arboard clipboard dependency for Android targets. ## Key Changes - **Android Compatibility**: Gate arboard dependency for Android targets where clipboard access may be restricted - **Build Fixes**: Add missing tempfile::Builder import for image clipboard operations - **Code Cleanup**: Remove unnecessary parentheses to resolve formatting warnings ## Technical Details ### Clipboard Dependency Gating - Uses conditional compilation to exclude arboard on Android targets - Maintains full clipboard functionality on other platforms - Prevents build failures on Android/Termux where system clipboard access is limited ### Import Fixes - Adds missing tempfile::Builder import that was causing compilation errors - Ensures image clipboard operations work correctly when clipboard is available ## Platform Support - ✅ **Linux/macOS/Windows**: Full clipboard functionality maintained - ✅ **Android/Termux**: Builds successfully without clipboard dependency - ✅ **Other Unix platforms**: Unchanged behavior ## Testing - ✅ Builds successfully on Android/Termux - ✅ Maintains clipboard functionality on supported platforms - ✅ No regression in existing functionality This addresses the Android/Termux compatibility issues while keeping clipboard functionality intact for platforms that support it.
This commit is contained in:
@@ -47,6 +47,7 @@ pub struct PastedImageInfo {
|
||||
}
|
||||
|
||||
/// Capture image from system clipboard, encode to PNG, and return bytes + info.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub fn paste_image_as_png() -> Result<(Vec<u8>, PastedImageInfo), PasteImageError> {
|
||||
tracing::debug!("attempting clipboard image read");
|
||||
let mut cb = arboard::Clipboard::new()
|
||||
@@ -70,10 +71,7 @@ pub fn paste_image_as_png() -> Result<(Vec<u8>, PastedImageInfo), PasteImageErro
|
||||
.map_err(|e| PasteImageError::EncodeFailed(e.to_string()))?;
|
||||
}
|
||||
|
||||
tracing::debug!(
|
||||
"clipboard image encoded to PNG ({len} bytes)",
|
||||
len = png.len()
|
||||
);
|
||||
tracing::debug!("clipboard image encoded to PNG ({}) bytes", png.len());
|
||||
Ok((
|
||||
png,
|
||||
PastedImageInfo {
|
||||
@@ -84,7 +82,16 @@ pub fn paste_image_as_png() -> Result<(Vec<u8>, PastedImageInfo), PasteImageErro
|
||||
))
|
||||
}
|
||||
|
||||
/// Android/Termux does not support arboard; return a clear error.
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn paste_image_as_png() -> Result<(Vec<u8>, PastedImageInfo), PasteImageError> {
|
||||
Err(PasteImageError::ClipboardUnavailable(
|
||||
"clipboard image paste is unsupported on Android".into(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Convenience: write to a temp file and return its path + info.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub fn paste_image_to_temp_png() -> Result<(PathBuf, PastedImageInfo), PasteImageError> {
|
||||
let (png, info) = paste_image_as_png()?;
|
||||
// Create a unique temporary file with a .png suffix to avoid collisions.
|
||||
@@ -101,6 +108,14 @@ pub fn paste_image_to_temp_png() -> Result<(PathBuf, PastedImageInfo), PasteImag
|
||||
Ok((path, info))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn paste_image_to_temp_png() -> Result<(PathBuf, PastedImageInfo), PasteImageError> {
|
||||
// Keep error consistent with paste_image_as_png.
|
||||
Err(PasteImageError::ClipboardUnavailable(
|
||||
"clipboard image paste is unsupported on Android".into(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Normalize pasted text that may represent a filesystem path.
|
||||
///
|
||||
/// Supports:
|
||||
|
||||
Reference in New Issue
Block a user