DEV Community

Cover image for Clipboard Monitor + Gemini in a Tauri App — Building a Smarter Dev Tool
hiyoyo
hiyoyo

Posted on

Clipboard Monitor + Gemini in a Tauri App — Building a Smarter Dev Tool

All tests run on an 8-year-old MacBook Air.
All results from shipping 7 Mac apps as a solo developer. No sponsored opinion.
HiyokoHelper monitors the clipboard and optionally sends content to Gemini for analysis. It sounds simple. The implementation has specific gotchas.
Here's what I learned.

Clipboard monitoring in Tauri
There's no built-in file-watcher equivalent for the clipboard. You poll.
rustuse tauri_plugin_clipboard_manager::ClipboardExt;
use std::time::Duration;
use tokio::time::interval;

async fn watch_clipboard(handle: AppHandle) {
let mut last = String::new();
let mut ticker = interval(Duration::from_millis(500));

loop {
    ticker.tick().await;
    if let Ok(current) = handle.clipboard().read_text() {
        if current != last && !current.is_empty() {
            last = current.clone();
            handle.emit("clipboard-changed", current).ok();
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

}
500ms polling is fast enough to feel responsive. Lower than 200ms and you're burning CPU for no user benefit.

What to do with clipboard content
For HiyokoHelper, clipboard content goes to Gemini for command explanation and danger detection. The flow:

Clipboard changes
Frontend receives clipboard-changed event
User clicks "Analyze" (or auto-analyze is on)
Content sent to Gemini with a structured prompt
Response shown in the UI

Auto-analyze on every clipboard change is too aggressive. Users copy passwords, personal data, sensitive content. Analyze on demand, not automatically.

The dangerous content problem
Terminal error messages and shell commands are the primary use case. But users also copy:

Passwords
API keys
Personal information
Code with secrets in it

Before sending to Gemini: strip obvious secrets. API keys (long alphanumeric strings), password manager output, anything that looks like a credential.
rustfn looks_like_secret(text: &str) -> bool {
// Long random strings
let has_long_random = text.split_whitespace()
.any(|w| w.len() > 30 && w.chars().all(|c| c.is_alphanumeric()));

// Common secret patterns
let has_secret_pattern = text.contains("sk-") 
    || text.contains("AIza")
    || text.contains("ghp_");

has_long_random || has_secret_pattern
Enter fullscreen mode Exit fullscreen mode

}
Not perfect. Good enough to avoid the most obvious cases.

The history cache
Store clipboard history in SQLite with timestamps. Let users browse, search, and pin items.
Don't store everything forever. Cap at 100 items. Auto-delete items older than 7 days. Clipboard history that grows unbounded is a privacy and storage problem.

The verdict
Clipboard monitoring is polling. Gemini integration needs explicit user action, not auto-send. History needs a retention policy.
The useful part — AI analysis of terminal errors and commands — is genuinely useful once you get the UX right.

If this was useful, a ❤️ helps more than you'd think — thanks!
Hiyoko PDF Vault → https://hiyokoko.gumroad.com/l/HiyokoPDFVault
X → @hiyoyok

Top comments (0)