Skip to content

Commit

Permalink
✨ Click message to open extract dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Dec 10, 2023
1 parent a4ab7ec commit eac8814
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { invoke } from "@tauri-apps/api/tauri";
import { appWindow } from "@tauri-apps/api/window";
import "./App.css";

function App() {
const [name, setName] = useState("");
const [processing, setProcessing] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);

const extract = (path: string) => {
setProcessing(true);
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
invoke("extract", { path })
.then(() => {
setProcessing(false);
})
.catch((err) => {
window.alert(err);
setProcessing(false);
});
};

useEffect(() => {
const unlisten = appWindow.onFileDropEvent((e) => {
if (e.payload.type !== "drop") {
return;
}
for (const path of e.payload.paths) {
setProcessing(true);
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
invoke("extract", { path })
.then(() => {
setProcessing(false);
})
.catch((err) => {
window.alert(err);
setProcessing(false);
});
extract(path);
}
});
return () => {
Expand Down Expand Up @@ -52,7 +57,16 @@ function App() {
{!processing && (
<div className="row">
<h1>
<b>Drop here to extract PNA file.</b>
<label htmlFor="extract_file">
<b>Drop here to extract PNA file.</b>
</label>
<input
ref={inputRef}
id="extract_file"
className="hidden"
type="file"
accept=".pna"
/>
</h1>
</div>
)}
Expand Down
4 changes: 4 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ button {
margin-right: 5px;
}

.hidden {
display: none;
}

@media (prefers-color-scheme: dark) {
:root {
color: #f6f6f6;
Expand Down

0 comments on commit eac8814

Please sign in to comment.