-
-
Notifications
You must be signed in to change notification settings - Fork 74
feat: add client-based clipboard sync (HTTP-safe fallback without HTTPS) #318
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
342cfca
dcb1686
d5fd9a1
070fe2d
544bd76
3368723
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,18 @@ import { KEY_MAP } from "./KeyMap" | |
| import { moveRelative } from "./ydotool" | ||
| import os from "node:os" | ||
|
|
||
| type ServerToClientMessage = { | ||
| type: "clipboard-text" | ||
| text: string | ||
| } | ||
|
|
||
| export interface InputMessage { | ||
| type: | ||
| | "move" | ||
| | "paste" | ||
| | "copy" | ||
| | "clipboard-push" | ||
| | "clipboard-pull" | ||
| | "click" | ||
| | "scroll" | ||
| | "key" | ||
|
|
@@ -34,7 +41,10 @@ export class InputHandler { | |
| private throttleMs: number | ||
| private modifier: Key | ||
|
|
||
| constructor(throttleMs = 8) { | ||
| constructor( | ||
| private sendToClient: (msg: ServerToClientMessage) => void, | ||
| throttleMs = 8, | ||
| ) { | ||
| mouse.config.mouseSpeed = 1000 | ||
| this.modifier = os.platform() === "darwin" ? Key.LeftSuper : Key.LeftControl | ||
| this.throttleMs = throttleMs | ||
|
|
@@ -196,6 +206,40 @@ export class InputHandler { | |
| break | ||
| } | ||
|
|
||
| case "clipboard-push": { | ||
| if (msg.text) { | ||
| // TEMP: fallback using typing instead of real clipboard | ||
| try{ | ||
| await keyboard.type(msg.text) | ||
| }catch(err) { | ||
| console.error("Clipboard push failed:", err) | ||
| } | ||
| } | ||
| break | ||
|
Comment on lines
+209
to
+218
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🧰 Tools🪛 GitHub Actions: CI[error] 210-216: Biome formatting detected mismatch: File content differs from formatting output. Run the formatter and re-run the CI checks. 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| case "clipboard-pull": { | ||
| // simulate Ctrl+C to get current clipboard | ||
| try { | ||
| await keyboard.pressKey(this.modifier, Key.C) | ||
| } finally { | ||
| await Promise.allSettled([ | ||
| keyboard.releaseKey(Key.C), | ||
| keyboard.releaseKey(this.modifier), | ||
| ]) | ||
| } | ||
|
|
||
| // small delay to allow clipboard update | ||
| await new Promise((r) => setTimeout(r, 100)) | ||
|
|
||
| // ❗ send back to client (IMPORTANT) | ||
| this.sendToClient({ | ||
| type: "clipboard-text", | ||
| text: "CLIPBOARD_DATA_UNAVAILABLE", | ||
| }) | ||
| break | ||
| } | ||
|
|
||
| case "scroll": { | ||
| const MAX_SCROLL = 100 | ||
| const promises: Promise<unknown>[] = [] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.