Skip to content

Commit

Permalink
debug clipboard (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
web3nomad committed May 4, 2024
1 parent 0ac8318 commit c5f1a52
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 6 deletions.
144 changes: 141 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions apps/api-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ priority-queue = "2.0.0"
async-trait = { workspace = true }
downloader = { workspace = true }
reqwest = { workspace = true }


arboard = "3.4.0"
# 处理 enum
strum = "0.26"
strum_macros = "0.26"
Expand Down
2 changes: 2 additions & 0 deletions apps/api-server/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod assets;
mod video;
mod libraries;
mod audio;
mod utils;

use rspc::Router;
use crate::CtxWithLibrary;
Expand All @@ -24,6 +25,7 @@ where
.merge("video.", video::get_routes::<TCtx>())
.merge("audio.", audio::get_routes::<TCtx>())
.merge("libraries.", libraries::get_routes::<TCtx>())
.merge("utils.", utils::get_routes::<TCtx>())
.query("version", |t| {
t(|_ctx, _input: ()| env!("CARGO_PKG_VERSION"))
})
Expand Down
18 changes: 18 additions & 0 deletions apps/api-server/src/routes/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use arboard::Clipboard;
use rspc::{Router, RouterBuilder};
use crate::CtxWithLibrary;

pub fn get_routes<TCtx>() -> RouterBuilder<TCtx>
where
TCtx: CtxWithLibrary + Clone + Send + Sync + 'static,
{
Router::<TCtx>::new()
.query("read_clipboard", |t| {
t(|_ctx, _input: ()| {
let mut clipboard = Clipboard::new().unwrap();
let text = clipboard.get_text().unwrap();
println!("Clipboard text was: {}", text);
Ok(text)
})
})
}
16 changes: 15 additions & 1 deletion apps/web/src/app/explorer/_components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useExplorerContext } from '@/Explorer/hooks'
import PageNav from '@/components/PageNav'
import UploadButton from '@/components/UploadButton'
import Viewport from '@/components/Viewport'
import { rspc } from '@/lib/rspc'
import { rspc, client } from '@/lib/rspc'
import { useUploadQueueStore } from '@/store/uploadQueue'
import Icon from '@gendam/ui/icons'
import classNames from 'classnames'
Expand Down Expand Up @@ -68,6 +68,20 @@ export default function Header() {
}
}, [handleSelectFiles])

useEffect(() => {
// listen to paste event
if (typeof window !== 'undefined') {
const handlePaste = async (e: ClipboardEvent) => {
const text = await client.query(['utils.read_clipboard'])
console.log(text)
}
window.addEventListener('paste', handlePaste)
return () => {
window.removeEventListener('paste', handlePaste)
}
}
}, [])

return (
<>
<Viewport.Toolbar className="relative">
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/lib/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type Procedures = {
{ key: "libraries.models.list", input: never, result: Result[] } |
{ key: "libraries.status", input: never, result: LibraryStatusResult } |
{ key: "users.get", input: never, result: Auth | null } |
{ key: "utils.read_clipboard", input: never, result: string } |
{ key: "version", input: never, result: string } |
{ key: "video.search.all", input: SearchRequestPayload, result: SearchResultPayload[] } |
{ key: "video.tasks.list", input: TaskListRequestPayload, result: VideoWithTasksPageResult },
Expand Down

0 comments on commit c5f1a52

Please sign in to comment.