Skip to content
Merged
Show file tree
Hide file tree
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
116 changes: 116 additions & 0 deletions .github/workflows/build-viewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Build Interactive Viewer

on:
push:
branches: [main]
tags: ['v*']
pull_request:
branches: [main]

jobs:
build-linux:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.92.0

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libgtk-3-dev \
libxcb-render0-dev \
libxcb-shape0-dev \
libxcb-xfixes0-dev \
libxkbcommon-dev \
libvulkan-dev \
mesa-vulkan-drivers \
xvfb \
libxkbcommon-x11-0

- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Build viewer
run: cargo build --release -p custom_callback

- name: Run tests
run: cargo test -p custom_callback

- name: Package binary
run: |
cd target/release
strip custom_callback_viewer
tar -czf dimos-viewer-${{ github.ref_name }}-linux-x64.tar.gz custom_callback_viewer

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dimos-viewer-linux-x64
path: target/release/dimos-viewer-*.tar.gz

build-macos:
runs-on: macos-14
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.92.0

- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Build viewer
run: cargo build --release -p custom_callback

- name: Run tests
run: cargo test -p custom_callback

- name: Package binary
run: |
cd target/release
strip custom_callback_viewer
tar -czf dimos-viewer-${{ github.ref_name }}-macos-arm64.tar.gz custom_callback_viewer

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dimos-viewer-macos-arm64
path: target/release/dimos-viewer-*.tar.gz

release:
needs: [build-linux, build-macos]
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: release/

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: release/dimos-viewer-*.tar.gz
generate_release_notes: true
76 changes: 76 additions & 0 deletions examples/rust/custom_callback/src/interaction/handle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use tokio::sync::mpsc;
use super::protocol::ViewerEvent;

/// Handle for sending interaction events from the viewer to the application.
///
/// Cheap to clone and thread-safe.
#[derive(Clone)]
pub struct InteractionHandle {
tx: mpsc::UnboundedSender<ViewerEvent>,
}

impl InteractionHandle {
/// Create a new handle from a channel sender.
pub fn new(tx: mpsc::UnboundedSender<ViewerEvent>) -> Self {
Self { tx }
}

/// Send a click event to the application.
pub fn send_click(
&self,
position: [f32; 3],
entity_path: Option<String>,
view_id: String,
is_2d: bool,
) {
let event = ViewerEvent::Click {
position,
entity_path,
view_id,
timestamp_ms: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as u64,
is_2d,
};

if let Err(e) = self.tx.send(event) {
eprintln!("Failed to send click event: {}", e);
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_handle_send_click() {
let (tx, mut rx) = mpsc::unbounded_channel();
let handle = InteractionHandle::new(tx);

handle.send_click(
[1.0, 2.0, 3.0],
Some("world/robot".to_string()),
"view_123".to_string(),
false,
);

let event = rx.try_recv().unwrap();
match event {
ViewerEvent::Click { position, entity_path, view_id, is_2d, .. } => {
assert_eq!(position, [1.0, 2.0, 3.0]);
assert_eq!(entity_path, Some("world/robot".to_string()));
assert_eq!(view_id, "view_123");
assert!(!is_2d);
}
}
}

#[test]
fn test_handle_is_cloneable() {
let (tx, _rx) = mpsc::unbounded_channel();
let handle1 = InteractionHandle::new(tx);
let _handle2 = handle1.clone();
}
}
Loading
Loading