Skip to content

Commit

Permalink
v1.2.15
Browse files Browse the repository at this point in the history
1. Keyboard shortcut supported. Press Enter to trigger synchronization; 2. Fix: TypeError: undefined is not an object(evaluating 'e[0].getType')
  • Loading branch information
llaoj committed May 15, 2024
1 parent d48ea2b commit 9845968
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ GCopy values your data privacy, it does not persistently store your data; it is
Steps:

1. Open the website [https://gcopy.rutron.net](https://gcopy.rutron.net) on two devices, A and B, using a browser and log in with the same email.
2. On device A, copy (e.g., `Ctrl+C`) and then click the button on the right side of the page.
3. Switch to device B, click the button again, and the data will be synchronized. Now, go ahead and paste (`Ctrl+V`)!
2. On device A, copy (e.g., `Ctrl+C`) and then press the button on the right side of the page.
3. Switch to device B, press the button again, and the data will be synchronized. Now, go ahead and paste (`Ctrl+V`)!

## Background

Expand Down
4 changes: 2 additions & 2 deletions docs/zh-CN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ GCopy重视您的数据隐私, 不持久化存储您的数据, 它们都在内
步骤:

1. 在两台设备A&B上使用浏览器打开网站[https://gcopy.rutron.net](https://gcopy.rutron.net), 使用相同的邮箱登录.
2. 在设备A上拷贝(比如`Ctrl+C`)之后点击页面右侧的按钮.
3. 切换到设备B再次点击该按钮, 数据完成同步. 去粘贴(`Ctrl+V`)吧!
2. 在设备A上拷贝(比如`Ctrl+C`)之后按下页面右侧的按钮.
3. 切换到设备B再次按下该按钮, 数据完成同步. 去粘贴(`Ctrl+V`)吧!

## 背景

Expand Down
20 changes: 19 additions & 1 deletion frontend/components/sync-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CursorArrowRippleIcon } from "@heroicons/react/24/solid";
import { useTranslations } from "next-intl";
import { useRef, useState } from "react";
import { useShortcut } from "@/lib/shortcut";

export default function SyncButton({
syncFunc,
Expand All @@ -17,6 +18,13 @@ export default function SyncButton({
setClicked(false);
};

useShortcut({
key: "Enter",
onKeyPressed: () => {
buttonRef.current?.click();
},
});

return (
<>
<button
Expand All @@ -26,7 +34,17 @@ export default function SyncButton({
onClick={onClick}
>
<CursorArrowRippleIcon className="h-6 w-6" />
{t("click2sync")}
&#47;
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 -960 960 960"
stroke="currentColor"
fill="currentColor"
className="h-6 w-6"
>
<path d="M360-240 120-480l240-240 56 56-144 144h488v-160h80v240H272l144 144-56 56Z" />
</svg>
{t("syncButtonText")}
</button>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function clipboardRead() {
let imagePngIndex = null;
let textPlainIndex = null;
let textHtmlIndex = null;
if (items) {
if (items && items.length > 0) {
for (let i = 0; i < items.length; i++) {
if (items[i].types.includes("image/png")) {
imagePngIndex = i;
Expand Down
20 changes: 20 additions & 0 deletions frontend/lib/shortcut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect } from "react";

export function useShortcut({
key,
onKeyPressed,
}: {
key: string;
onKeyPressed: () => void;
}) {
useEffect(() => {
function keyDownHandler(e: globalThis.KeyboardEvent) {
if (e.key === key) {
e.preventDefault();
onKeyPressed();
}
}
document.addEventListener("keydown", keyDownHandler);
return () => document.removeEventListener("keydown", keyDownHandler);
}, []);
}
4 changes: 2 additions & 2 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
},
"SyncClipboard": {
"title": "Sync the clipboard",
"subTitle": "Click-click and the clipboard synced between devices.",
"click2sync": "Click to sync clipboard",
"subTitle": "Press the button and the clipboard synced between devices.",
"syncButtonText": "Sync clipboard",
"text": "TEXT",
"screenshot": "SCREENSHOT",
"file": "FILE",
Expand Down
4 changes: 2 additions & 2 deletions frontend/messages/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
},
"SyncClipboard": {
"title": "同步剪切板",
"subTitle": "Click-click剪切板就能在不同设备间同步.",
"click2sync": "点击同步剪切板",
"subTitle": "按下按钮剪切板就能在不同设备间同步.",
"syncButtonText": "同步剪切板",
"text": "文字",
"screenshot": "截图",
"file": "文件",
Expand Down
4 changes: 2 additions & 2 deletions frontend/package-lock.json

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

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gcopy",
"version": "1.2.14",
"version": "1.2.15",
"private": true,
"scripts": {
"dev": "next dev -p 3375 --experimental-https",
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.2.14
v1.2.15

0 comments on commit 9845968

Please sign in to comment.