mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-25 19:01:38 +01:00
Add .oxfmtignore to skip generated bindings and wasm-pack output. Add npm format script, update DEVELOPMENT.md for Vite+ toolchain, and format all non-generated files with oxfmt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import type { GetHttpAuthenticationSummaryResponse } from "@yaakapp-internal/plugins";
|
|
import { atom, useAtomValue } from "jotai";
|
|
import { useState } from "react";
|
|
import { jotaiStore } from "../lib/jotai";
|
|
import { invokeCmd } from "../lib/tauri";
|
|
import { showErrorToast } from "../lib/toast";
|
|
import { usePluginsKey } from "./usePlugins";
|
|
|
|
const httpAuthenticationSummariesAtom = atom<GetHttpAuthenticationSummaryResponse[]>([]);
|
|
const orderedHttpAuthenticationAtom = atom((get) =>
|
|
get(httpAuthenticationSummariesAtom)?.sort((a, b) => a.name.localeCompare(b.name)),
|
|
);
|
|
|
|
export function useHttpAuthenticationSummaries() {
|
|
return useAtomValue(orderedHttpAuthenticationAtom);
|
|
}
|
|
|
|
export function useSubscribeHttpAuthentication() {
|
|
const [numResults, setNumResults] = useState<number>(0);
|
|
const pluginsKey = usePluginsKey();
|
|
|
|
useQuery({
|
|
queryKey: ["http_authentication_summaries", pluginsKey],
|
|
// Fetch periodically until functions are returned
|
|
// NOTE: visibilitychange (refetchOnWindowFocus) does not work on Windows, so we'll rely on this logic
|
|
// to refetch things until that's working again
|
|
// TODO: Update plugin system to wait for plugins to initialize before sending the first event to them
|
|
refetchInterval: numResults > 0 ? Number.POSITIVE_INFINITY : 1000,
|
|
refetchOnMount: true,
|
|
placeholderData: (prev) => prev, // Keep previous data on refetch
|
|
queryFn: async () => {
|
|
try {
|
|
const result = await invokeCmd<GetHttpAuthenticationSummaryResponse[]>(
|
|
"cmd_get_http_authentication_summaries",
|
|
);
|
|
setNumResults(result.length);
|
|
jotaiStore.set(httpAuthenticationSummariesAtom, result);
|
|
return result;
|
|
} catch (err) {
|
|
showErrorToast({
|
|
id: "http-authentication-error",
|
|
title: "HTTP Authentication Error",
|
|
message: err,
|
|
});
|
|
}
|
|
},
|
|
});
|
|
}
|