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>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
|
import type { ModelPayload } from "@yaakapp-internal/models";
|
|
import { atom, useAtomValue } from "jotai";
|
|
import { generateId } from "../lib/generateId";
|
|
import { jotaiStore } from "../lib/jotai";
|
|
|
|
const requestUpdateKeyAtom = atom<Record<string, string>>({});
|
|
|
|
getCurrentWebviewWindow()
|
|
.listen<ModelPayload>("model_write", ({ payload }) => {
|
|
if (payload.change.type !== "upsert") return;
|
|
|
|
if (
|
|
(payload.model.model === "http_request" ||
|
|
payload.model.model === "grpc_request" ||
|
|
payload.model.model === "websocket_request") &&
|
|
((payload.updateSource.type === "window" &&
|
|
payload.updateSource.label !== getCurrentWebviewWindow().label) ||
|
|
payload.updateSource.type !== "window")
|
|
) {
|
|
wasUpdatedExternally(payload.model.id);
|
|
}
|
|
})
|
|
.catch(console.error);
|
|
|
|
export function wasUpdatedExternally(changedRequestId: string) {
|
|
jotaiStore.set(requestUpdateKeyAtom, (m) => ({ ...m, [changedRequestId]: generateId() }));
|
|
}
|
|
|
|
export function useRequestUpdateKey(requestId: string | null) {
|
|
const keys = useAtomValue(requestUpdateKeyAtom);
|
|
const key = keys[requestId ?? "n/a"];
|
|
return `${requestId}::${key ?? "default"}`;
|
|
}
|