cablehead / stacks

an experimental "tool for thought"
https://stacks.cross.stream
MIT License
95 stars 5 forks source link

feat: ability to paste directly from Stacks #47

Open cablehead opened 9 months ago

cablehead commented 9 months ago

Stacks will need to request System Settings -> Privacy & Security -> Accessibility access on macOS.

We'll also need the platform specific code to perform the actual paste.

This should be configurable in settings as either the default when you hit enter, or as a hot key combo for users who want to keep the default of copy to clipboard on enter.

arn4v commented 9 months ago

Spent some time exploring how to implement this. TL;DR: There are two ways:

Interop with Swift is likely more robust solution than simulating keyboard events, so I explored that further.

Implementation sketch:

cablehead commented 9 months ago

This is great, thank you @arn4v!

Interoping with Swift does look more robust. It'd also open up additional improvements:

1/ Currently Stacks spawns a tiny Swift CLI binary as a subprocess. The CLI monitors the system clipboard and writes updates to stdout: https://github.com/cablehead/workspace/tree/x-macos-pasteboard -- we could pull this directly into the Stacks' binary / process

2/ Stacks' makes a bunch of platform calls to configure its window as a spotlight-like window: https://github.com/cablehead/stacks/blob/main/src-tauri/src/spotlight.rs -- it'd be nicer if this was in native Swift.

Change Enter press logic to check if "Paste on Enter" is enabled, Normally it copies first and then closes the window

Yep, this is right:

I'm asking in the extism discord if there's anything in their ecosystem for Swift. It'd be interesting to bridge Rust and Swift using wasm. Otherwise swift-rs looks great.

cablehead commented 9 months ago

Just capturing that it currently looks best to integrate with swift-rs directly.