import { Button, CONTROL_TOOLTIP_DELAY, Dropdown, type DropdownItem, Icon, IconButton, Tooltip, } from "@yaakapp-internal/ui"; import { useAtomValue } from "jotai"; import { useMemo, useState } from "react"; import { useLocalStorage } from "react-use"; import { canTrustHere, useDecrypt, useTrustCertificate, useTrusting } from "../hooks/useDecrypt"; import { useDecryptList } from "../hooks/useDecryptList"; import { useRpcQuery } from "../hooks/useRpcQuery"; import { everythingEdit, listEdit, setDecrypted } from "../lib/decrypt"; import { chooseOptions, connectionCount, stripState } from "../lib/httpsStrip"; import { sidebarFlowsAtom } from "../lib/store"; import { AppIcon } from "./AppIcon"; import { SETTINGS_TAB_PROXY, useOpenSettings } from "./Settings"; const STRIP = "flex items-center gap-2.5 h-[2.2rem] mx-2 mb-1 pl-3 pr-1.5 rounded-md bg-surface-highlight/45 border border-border-subtle text-sm text-text-subtle min-w-0"; /** * Above the list while nothing is decrypted: says once that HTTPS is encrypted, and offers * Decrypt Everything, or Choose for apps and sites one at a time. Goes once anything is on * the list, or when dismissed; comes back, with Trust, while the list decrypts something the * certificate isn't trusted for. */ export function HttpsStrip() { const list = useDecryptList(); const flows = useAtomValue(sidebarFlowsAtom); const caStatus = useRpcQuery("ca_status", {}); const [dismissed, setDismissed] = useLocalStorage("https_strip_dismissed", false); // Kept while Choose is open, so checking a row there leaves the menu where it is. const [choosing, setChoosing] = useState(false); const { apply } = useDecrypt(); const trusting = useTrusting(); const trust = useTrustCertificate(); const openSettings = useOpenSettings(); const encrypted = useMemo(() => flows.filter((f) => f.tunnelled).length, [flows]); const state = stripState({ list, encrypted, dismissed: dismissed ?? false, trusted: caStatus.data?.trusted ?? null, canTrust: canTrustHere(), }); const options = useMemo(() => chooseOptions(flows, list), [flows, list]); if (state === "hidden" && !choosing) return null; if (state === "broken") { return (