Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions apps/desktop/src/components/license.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useEffect, useRef } from "react";

import { useLicense } from "@/hooks/use-license";
import { useMutation, useQuery } from "@tanstack/react-query";
import { commands as connectorCommands } from "@hypr/plugin-connector";

const REFRESH_INTERVAL = 30 * 60 * 1000;
const INITIAL_DELAY = 5000;
Expand All @@ -10,6 +12,33 @@ export function LicenseRefreshProvider({ children }: { children: React.ReactNode
const { getLicenseStatus, refreshLicense, getLicense } = useLicense();
const lastRefreshAttempt = useRef<number>(0);

const hyprCloudEnabled = useQuery({
queryKey: ["hypr-cloud-enabled"],
queryFn: () => connectorCommands.getHyprcloudEnabled(),
});

const setHyprCloudEnabledMutation = useMutation({
mutationFn: (enabled: boolean) => connectorCommands.setHyprcloudEnabled(enabled),
onSuccess: () => {
hyprCloudEnabled.refetch();
},
});

const setCustomLLMEnabledMutation = useMutation({
mutationFn: (enabled: boolean) => connectorCommands.setCustomLlmEnabled(enabled),
});

// Auto-disable HyprCloud when license expires
useEffect(() => {
const isPro = !!getLicense.data?.valid;

if (!isPro && hyprCloudEnabled.data) {
setHyprCloudEnabledMutation.mutate(false);
setCustomLLMEnabledMutation.mutate(false);

}
}, [getLicense.data?.valid, hyprCloudEnabled.data, setHyprCloudEnabledMutation, setCustomLLMEnabledMutation]);

useEffect(() => {
if (getLicense.isLoading) {
return;
Expand Down