diff --git a/src/components/LicenseValidationComponent.tsx b/src/components/LicenseValidationComponent.tsx index bb23186..9646d1b 100644 --- a/src/components/LicenseValidationComponent.tsx +++ b/src/components/LicenseValidationComponent.tsx @@ -3,26 +3,51 @@ import Database from "@tauri-apps/plugin-sql"; import toast from "react-hot-toast"; import { fetch as tauriFetch } from "@tauri-apps/plugin-http"; import { useLicenseKey } from "../hooks/useLicenseKey"; +import { useTrigger } from "../contexts/TriggerReRender"; const LicenseValidationComponent: React.FC = () => { const [licenseKey, setLicenseKey] = useState(""); + const [isDataLoaded, setIsDataLoaded] = useState(false); // Track loading status const { licenseData, refreshLicenseData } = useLicenseKey(); + const { triggerUpdate } = useTrigger(); + + // Function to check if a date is today + const isNotToday = (dateString: string): boolean => { + const today = new Date(); + const inputDate = new Date(dateString); + return ( + inputDate.getFullYear() !== today.getFullYear() || + inputDate.getMonth() !== today.getMonth() || + inputDate.getDate() !== today.getDate() + ); + }; useEffect(() => { const validateLicense = async () => { - await refreshLicenseData(); - if (licenseData) { - setLicenseKey(licenseData.license_key); - await handleLicenseValidation( - licenseData.last_validated, - licenseData.status, - licenseData.license_key - ); - } + console.log("Running License Validator"); + await refreshLicenseData(); // Ensure data is refreshed + setIsDataLoaded(true); // Mark data as loaded }; validateLicense(); }, []); + useEffect(() => { + console.log(isNotToday("2024-11-27"), "is not Today"); + if ( + isDataLoaded && + licenseData && + isNotToday(licenseData.last_validated) // Add the new condition + ) { + console.log(licenseData); + setLicenseKey(licenseData.license_key); + handleLicenseValidation( + licenseData.last_validated, + licenseData.status, + licenseData.license_key + ); + } + }, [isDataLoaded]); // Re-run when data loads + // Function to handle license validation and activation status const handleLicenseValidation = async ( lastValidated: string, @@ -76,6 +101,7 @@ const LicenseValidationComponent: React.FC = () => { if (diffInDays > 7) { // If more than 7 days, update status to what was received in the response await updateLicenseStatus("disabled"); + triggerUpdate(); } else { // If less than 7 days, update status await updateLicenseStatus(data.license_key.status); diff --git a/src/components/window/UsageTime.tsx b/src/components/window/UsageTime.tsx index 2e63fea..ab73696 100644 --- a/src/components/window/UsageTime.tsx +++ b/src/components/window/UsageTime.tsx @@ -6,14 +6,16 @@ import { Button } from "../ui/button"; import UsageTimeChart from "../UsageChart"; const UsageTime = () => { - const { canAccessPremiumFeatures } = usePremiumFeatures(); + const { canAccessPremiumFeatures, isPaidUser, isTrialOn } = + usePremiumFeatures(); + console.log(canAccessPremiumFeatures, isPaidUser, isTrialOn); return (
{/* Glassmorphism Effect Overlay */} {!canAccessPremiumFeatures && ( -
+

Your support will help the developer to make this project better & add more features. diff --git a/src/main.tsx b/src/main.tsx index 1f2b4f3..5bb5c1f 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -16,9 +16,9 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( - +