Skip to content

Commit 94352fa

Browse files
committed
Auto only when hotkey is pressed
1 parent 4c5de55 commit 94352fa

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

src/components/Main.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const Main = () => {
9595
};
9696

9797
ipcRenderer.on('hotkey-pressed', () => {
98-
history.push('/auto');
98+
history.push('/auto', { auto: true });
9999
});
100100

101101
useEffect(() => {

src/components/auto/Auto.tsx

+39-10
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,45 @@ const detectRouteData = (value: string) => {
1313

1414
// Json
1515
try {
16-
JSON.parse(value);
17-
return { route: '/json-formatter', state: { input1: value } };
16+
if (typeof JSON.parse(value) === 'object') {
17+
return { route: '/json-formatter', state: { input1: value } };
18+
}
1819
} catch (e) {
1920
// ignore
2021
}
2122

2223
return {};
2324
};
2425

26+
interface LocationState {
27+
auto: boolean;
28+
}
29+
2530
const Auto = () => {
2631
const [value, setValue] = useState('');
2732
const [hotkey, setHotkey] = useState('');
2833
const history = useHistory();
29-
const location = useLocation();
34+
const location = useLocation<LocationState>();
3035

3136
useEffect(() => {
32-
setValue(clipboard.readText());
37+
if (location.state && location.state.auto) {
38+
setValue(clipboard.readText());
39+
}
3340
}, [location]);
3441

3542
useEffect(() => {
43+
let isMounted = true;
3644
ipcRenderer
3745
.invoke('get-store', { key: 'hotkey' })
3846
.then((v: string) => {
39-
setHotkey(v);
47+
if (isMounted) setHotkey(v);
4048
return null;
4149
})
4250
.catch(() => {});
51+
52+
return () => {
53+
isMounted = false;
54+
};
4355
});
4456

4557
useEffect(() => {
@@ -70,12 +82,29 @@ const Auto = () => {
7082
)}
7183
</section>
7284
<div className="flex items-center justify-between w-full my-1">
73-
<span>No tools was detected for this content:</span>
74-
<button type="button" className="w-16 btn" onClick={() => setValue('')}>
75-
Clear
76-
</button>
85+
<section className="flex items-center space-x-2">
86+
<button
87+
type="button"
88+
className="btn"
89+
onClick={() => setValue(clipboard.readText())}
90+
>
91+
Clipboard
92+
</button>
93+
<button
94+
type="button"
95+
className="w-16 btn"
96+
onClick={() => setValue('')}
97+
>
98+
Clear
99+
</button>
100+
</section>
101+
{value ? <span>No tools was detected for this content</span> : <span />}
77102
</div>
78-
<textarea className="flex w-full p-2 h-1/3" value={value} readOnly />
103+
<textarea
104+
className="flex w-full p-2 h-1/3"
105+
value={value}
106+
onChange={(e) => setValue(e.target.value)}
107+
/>
79108
</div>
80109
);
81110
};

src/components/qrcode/QrCodeGenerator.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ const QRCodeGenerator = () => {
1010

1111
useDebouncedEffect(
1212
() => {
13+
let isMounted = true;
1314
ipcRenderer
1415
.invoke('generate-qrcode', { content })
15-
.then((qr) => setQrCode(qr))
16+
.then((qr) => isMounted && setQrCode(qr))
1617
.catch(() => {});
18+
return () => {
19+
isMounted = false;
20+
};
1721
},
1822
[content],
1923
500

src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "plainbelt",
33
"productName": "plainbelt",
4-
"version": "0.0.7",
4+
"version": "0.0.8",
55
"description": "A toolbelt for all your plain text",
66
"main": "./main.prod.js",
77
"author": {

0 commit comments

Comments
 (0)