Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to paste directly from Stacks #47

Open
cablehead opened this issue Feb 12, 2024 · 3 comments
Open

feat: ability to paste directly from Stacks #47

cablehead opened this issue Feb 12, 2024 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@cablehead
Copy link
Owner

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.

@cablehead cablehead added the help wanted Extra attention is needed label Feb 12, 2024
@arn4v
Copy link

arn4v commented Feb 13, 2024

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

  • Simulate cmd+v keypress using a crate like enigo or rdev
  • Create a Swift module and then interop with it using swift-rs

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

Implementation sketch:

  • Setup swift-rs (Create new Xcode module, integrate swift-rs into the Swift module, and install swift-rs rust crate)
  • Expose 3 functions from Swift
    • Getter isAccessibilityGranted
    • showGrantAccessibilityAlert
    • pasteIntoFrontmostApp
  • Implement settings UI for "Paste on Enter"
    • When you try to enable "Paste on Enter", invoke exposed Swift getter isAccessibilityGranted & then invoke showGrantAccessibilityAlert if required
  • Change Enter press logic to check if "Paste on Enter" is enabled
    • Normally it copies first and then closes the window (correct me if I'm wrong @cablehead)
    • If enabled, instead of copying, close the window first and then invoke pasteIntoFrontmostApp in the background to paste when focus is restored on the app where Stacks was opened from.

@cablehead
Copy link
Owner Author

cablehead commented Feb 13, 2024

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
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants