mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-08 17:35:18 +00:00
add clipboard monitor
This commit is contained in:
1 parent
79031b3b32
commit
29a4d14893
7 files changed
+409
-15
No files matched your search
@@ -13,6 +13,7 @@
|
||||
"@emotion/react": "^11.14.0",
|
||||
"@supabase/supabase-js": "^2.98.0",
|
||||
"@tauri-apps/api": "^2",
|
||||
"@tauri-apps/plugin-clipboard-manager": "^2.3.2",
|
||||
"@tauri-apps/plugin-fs": "~2.4.5",
|
||||
"@tauri-apps/plugin-http": "~2.5.7",
|
||||
"@tauri-apps/plugin-opener": "^2",
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
Switch,
|
||||
} from "@chakra-ui/react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { readText } from "@tauri-apps/plugin-clipboard-manager";
|
||||
|
||||
import Glossary from "../components/Glossary";
|
||||
|
||||
@@ -45,6 +46,27 @@ function SearchPage() {
|
||||
|
||||
const lang = "ja-JP";
|
||||
|
||||
const [isMonitorClipboard, set_isMonitorclipboard] = useState(false);
|
||||
const [, set_clipboardText] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
if (!isMonitorClipboard) return;
|
||||
|
||||
const intervalId = setInterval(async () => {
|
||||
const newText = await readText();
|
||||
|
||||
set_clipboardText((clipboardText) => {
|
||||
if (clipboardText !== newText) {
|
||||
setQ(newText + " ");
|
||||
return newText;
|
||||
}
|
||||
return clipboardText;
|
||||
});
|
||||
}, 500);
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}, [isMonitorClipboard]);
|
||||
|
||||
useEffect(() => {
|
||||
trySearch();
|
||||
}, [q]);
|
||||
@@ -234,7 +256,7 @@ function SearchPage() {
|
||||
</InputGroup>
|
||||
{/* <Button type="submit">Search</Button> */}
|
||||
</Group>
|
||||
<div style={{ marginTop: "0.5em" }}>
|
||||
<div style={{ marginTop: "0.5em", display: "flex", gap: "1em" }}>
|
||||
<Switch.Root
|
||||
checked={isAutoKana}
|
||||
onCheckedChange={(d) => set_isAutoKana(d.checked)}
|
||||
@@ -243,6 +265,14 @@ function SearchPage() {
|
||||
<Switch.Control />
|
||||
<Switch.Label>Auto-convert Kana</Switch.Label>
|
||||
</Switch.Root>
|
||||
<Switch.Root
|
||||
checked={isMonitorClipboard}
|
||||
onCheckedChange={(d) => set_isMonitorclipboard(d.checked)}
|
||||
>
|
||||
<Switch.HiddenInput />
|
||||
<Switch.Control />
|
||||
<Switch.Label>Monitor clipboard</Switch.Label>
|
||||
</Switch.Root>
|
||||
</div>
|
||||
</form>
|
||||
<Box
|
||||
|
||||
Reference in new issue
Block a user