mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-07-07 13:37:55 +02:00
feat: add licensing handling
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
export interface TrialStatusActive {
|
||||
type: "Active";
|
||||
remaining_seconds: number;
|
||||
days_remaining: number;
|
||||
hours_remaining: number;
|
||||
minutes_remaining: number;
|
||||
}
|
||||
|
||||
export interface TrialStatusExpired {
|
||||
type: "Expired";
|
||||
}
|
||||
|
||||
export type TrialStatus = TrialStatusActive | TrialStatusExpired;
|
||||
|
||||
interface UseCommercialTrialReturn {
|
||||
trialStatus: TrialStatus | null;
|
||||
hasAcknowledged: boolean;
|
||||
isLoading: boolean;
|
||||
checkTrialStatus: () => Promise<void>;
|
||||
}
|
||||
|
||||
export function useCommercialTrial(): UseCommercialTrialReturn {
|
||||
const [trialStatus, setTrialStatus] = useState<TrialStatus | null>(null);
|
||||
const [hasAcknowledged, setHasAcknowledged] = useState(true);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const checkTrialStatus = useCallback(async () => {
|
||||
try {
|
||||
const [status, acknowledged] = await Promise.all([
|
||||
invoke<TrialStatus>("get_commercial_trial_status"),
|
||||
invoke<boolean>("has_acknowledged_trial_expiration"),
|
||||
]);
|
||||
setTrialStatus(status);
|
||||
setHasAcknowledged(acknowledged);
|
||||
} catch (error) {
|
||||
console.error("Failed to check trial status:", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
checkTrialStatus();
|
||||
|
||||
// Check trial status every minute to update the countdown
|
||||
const interval = setInterval(checkTrialStatus, 60000);
|
||||
return () => clearInterval(interval);
|
||||
}, [checkTrialStatus]);
|
||||
|
||||
return {
|
||||
trialStatus,
|
||||
hasAcknowledged,
|
||||
isLoading,
|
||||
checkTrialStatus,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
interface UseWayfernTermsReturn {
|
||||
termsAccepted: boolean | null;
|
||||
isLoading: boolean;
|
||||
checkTerms: () => Promise<void>;
|
||||
}
|
||||
|
||||
export function useWayfernTerms(): UseWayfernTermsReturn {
|
||||
const [termsAccepted, setTermsAccepted] = useState<boolean | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const checkTerms = useCallback(async () => {
|
||||
try {
|
||||
const accepted = await invoke<boolean>("check_wayfern_terms_accepted");
|
||||
setTermsAccepted(accepted);
|
||||
} catch (error) {
|
||||
console.error("Failed to check terms acceptance:", error);
|
||||
setTermsAccepted(false);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
checkTerms();
|
||||
}, [checkTerms]);
|
||||
|
||||
return {
|
||||
termsAccepted,
|
||||
isLoading,
|
||||
checkTerms,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user