diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 86f9262..9b3c90a 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -13,8 +13,9 @@ "windows": [ { "title": "Factorio Achievements Fixer", - "width": 800, - "height": 600 + "width": 450, + "height": 650, + "resizable": false } ], "security": { diff --git a/src/App.tsx b/src/App.tsx index d79cc4f..b193454 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,52 +1,10 @@ -import { invoke } from "@tauri-apps/api/core"; import "./App.css"; - -import DragAndDrop from "./components/DragAndDrop"; -import { useEffect, useState } from "preact/hooks"; -import { FolderIcon } from "@heroicons/react/20/solid"; - -type SaveFile = { - name: string; - path: string; - size: string; -}; +import SaveSelector from "./views/SaveSelector"; function App() { - const [saveFiles, setSaveFiles] = useState([]); - - useEffect(() => { - // On startup, find all save files and list them for easy selection - invoke("find_save_files").then((files) => { - setSaveFiles(files); - }); - }, []); - return ( -
- {}} /> -
- {saveFiles.map((file) => { - return ( -
-
- -
-

- - {file.name} - - {" "} - ({file.size}) -

-
-
-
- ); - })} -
+
+
); } diff --git a/src/components/DragAndDrop.tsx b/src/components/DragAndDrop.tsx index 1df1e26..c27faef 100644 --- a/src/components/DragAndDrop.tsx +++ b/src/components/DragAndDrop.tsx @@ -1,26 +1,39 @@ import { useEffect, useState } from "preact/hooks"; +import { exists } from "@tauri-apps/plugin-fs"; import { listen } from "@tauri-apps/api/event"; import { open } from "@tauri-apps/plugin-dialog"; import { FolderArrowDownIcon } from "@heroicons/react/24/outline"; import { cn } from "../utils"; import { invoke } from "@tauri-apps/api/core"; import Monoblock from "./Monoblock"; +import { DragDropEvent } from "@tauri-apps/api/webview"; interface DragAndDropProps { className?: string; onFile: (path: string) => void; } +type HoverState = "off" | "valid" | "invalid"; + export default function DragAndDrop({ className, onFile }: DragAndDropProps) { - const [isHovering, setIsHovering] = useState(false); + const [isHovering, setIsHovering] = useState("off"); + + async function isValid(paths: string[]): Promise { + console.log({ paths }); + return paths.length === 1 && paths[0].endsWith(".zip") && exists(paths[0]); + } useEffect(() => { - const unlistenEnter = listen("tauri://drag-enter", () => { - setIsHovering(true); - }).then((fn) => fn); + const unlistenEnter = listen( + "tauri://drag-enter", + async (event) => { + if (await isValid(event.payload.paths)) setIsHovering("valid"); + else setIsHovering("invalid"); + } + ).then((fn) => fn); const unlistenLeave = listen("tauri://drag-leave", () => { - setIsHovering(false); + setIsHovering("off"); }).then((fn) => fn); return () => { @@ -57,7 +70,16 @@ export default function DragAndDrop({ className, onFile }: DragAndDropProps) { onClick={onClick} className={cn(className, "flex items-center justify-center w-full")} > -