import { invoke } from "@tauri-apps/api/core"; import { openUrl } from "@tauri-apps/plugin-opener"; import type { LicenseCheckStatus } from "@yaakapp-internal/license"; import { useEffect, useState } from "react"; import { appInfo } from "../lib/appInfo"; import { DismissibleBanner } from "./core/DismissibleBanner"; export function CommercialUseBanner({ children, source, title, }: { children: string; source: string; title: string; }) { const [visible, setVisible] = useState(false); useEffect(() => { let canceled = false; shouldShowCommercialUsePrompt() .then((shouldShow) => { if (!canceled) setVisible(shouldShow); }) .catch(console.error); return () => { canceled = true; }; }, [source]); if (!visible) return null; return (
{ openCommercialUsePricing(source).catch(console.error); }, }, ]} >

{title}

{children}

); } async function shouldShowCommercialUsePrompt(): Promise { // Open-source builds omit the Rust license plugin, so never show commercial-use prompts there. if (appInfo.featureLicense !== true) { return false; } try { const license = await invoke("plugin:yaak-license|check"); return license.status !== "active" && license.status !== "trialing"; } catch (err) { console.log("Failed to check license before commercial-use prompt", err); return true; } } async function openCommercialUsePricing(source: string): Promise { await openUrl(`https://yaak.app/pricing?s=${source}&ref=app.yaak.desktop`).catch(console.error); }