import { useState, useEffect, useRef } from "react"; import { checkBox } from "../public/checkbox"; import { useTheme } from "next-themes"; const Home = () => { const { theme, setTheme } = useTheme(); const programRef = useRef(null); const iconRef = useRef(null); const [loadedProgram, setLoadedProgram] = useState(false); const [loadedIcon, setLoadedIcon] = useState(false); const [customExec, setCustomExec] = useState(false); const [terminal, setTerminal] = useState(false); const [error, setError] = useState(false); const [darkMode, setDarkMode] = useState(false); const [version, setVersion] = useState(""); const [input, setInput] = useState({ name: "", comment: "", exec: "", icon: "", terminal: false, }); console.log(darkMode); // Fetch app version useEffect(() => { setVersion(navigator.userAgent.match(/DeskCut\/([\d\.]+\d+)/)[1]); }, []); // Fetching update useEffect(async () => { const updateJson = await fetch( "https://nayamamarshe.github.io/api/deskcut.json", { method: "GET", } ).then((res) => res.json()); if (updateJson) { if ( updateJson.version > navigator.userAgent.match(/DeskCut\/([\d\.]+\d+)/)[1] ) { const confirmText = "Update available! Download now?"; if (confirm(confirmText) == true) { window.open( "https://github.com/NayamAmarshe/DeskCut/releases/", "_blank" ); } } } }, []); const handleSubmit = (e) => { e.preventDefault(); const { name, exec, icon } = input; const isValid = Object.values({ name, exec, icon }).every(Boolean); if (!isValid) { alert("Please enter the values correctly"); } else { window.electron.message(input); alert("Shortcut Successfully Created!"); } }; return (
{/* Heading */}

DeskCut

Shortcut Creator

{/* Text Inputs */} setInput({ ...input, name: e.target.value.replace(/[^A-Z0-9]+/gi, " "), }) } /> setInput({ ...input, comment: e.target.value })} /> {/* Terminal Checkbox */} {/* Custom Exec Checkbox */} {/* Choose File Buttons */}
{/* Custom Exec Input */} {customExec ? ( setInput({ ...input, exec: e.target.value })} /> ) : ( )} {/* Icon Button */} {customExec ? ( setInput({ ...input, icon: e.target.value })} /> ) : ( )}
{/* File Picker */} { e.stopPropagation(); e.preventDefault(); console.log(programRef.current); setInput({ ...input, exec: programRef?.current?.files[0]?.path }); if (programRef?.current?.files[0]?.path) { setLoadedProgram(true); } else { setLoadedProgram(false); } }} /> { e.stopPropagation(); e.preventDefault(); console.log(iconRef.current); setInput({ ...input, icon: iconRef?.current?.files[0]?.path }); if (iconRef?.current?.files[0]?.path) { setLoadedIcon(true); } else { setLoadedIcon(false); } }} /> {/* Submit Button */}

v{version}

); }; export default Home;