mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-30 06:02:00 +02:00
Merge main into proxy branch (formatting and docs)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import type { ActionInvocation } from '@yaakapp-internal/proxy-lib';
|
||||
import { Button, type ButtonProps } from '@yaakapp-internal/ui';
|
||||
import { useCallback } from 'react';
|
||||
import { useRpcMutation } from '../hooks/useRpcMutation';
|
||||
import { useActionMetadata } from '../hooks/useActionMetadata';
|
||||
import type { ActionInvocation } from "@yaakapp-internal/proxy-lib";
|
||||
import { Button, type ButtonProps } from "@yaakapp-internal/ui";
|
||||
import { useCallback } from "react";
|
||||
import { useRpcMutation } from "../hooks/useRpcMutation";
|
||||
import { useActionMetadata } from "../hooks/useActionMetadata";
|
||||
|
||||
type ActionButtonProps = Omit<ButtonProps, 'onClick' | 'children'> & {
|
||||
type ActionButtonProps = Omit<ButtonProps, "onClick" | "children"> & {
|
||||
action: ActionInvocation;
|
||||
/** Override the label from metadata */
|
||||
children?: React.ReactNode;
|
||||
@@ -12,7 +12,7 @@ type ActionButtonProps = Omit<ButtonProps, 'onClick' | 'children'> & {
|
||||
|
||||
export function ActionButton({ action, children, ...props }: ActionButtonProps) {
|
||||
const meta = useActionMetadata(action);
|
||||
const { mutate, isPending } = useRpcMutation('execute_action');
|
||||
const { mutate, isPending } = useRpcMutation("execute_action");
|
||||
|
||||
const onClick = useCallback(() => {
|
||||
mutate(action);
|
||||
@@ -25,7 +25,7 @@ export function ActionButton({ action, children, ...props }: ActionButtonProps)
|
||||
isLoading={isPending}
|
||||
onClick={onClick}
|
||||
>
|
||||
{children ?? meta?.label ?? '…'}
|
||||
{children ?? meta?.label ?? "…"}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import type { ActionInvocation } from '@yaakapp-internal/proxy-lib';
|
||||
import { IconButton, type IconButtonProps } from '@yaakapp-internal/ui';
|
||||
import { useCallback } from 'react';
|
||||
import { useRpcMutation } from '../hooks/useRpcMutation';
|
||||
import { useActionMetadata } from '../hooks/useActionMetadata';
|
||||
import type { ActionInvocation } from "@yaakapp-internal/proxy-lib";
|
||||
import { IconButton, type IconButtonProps } from "@yaakapp-internal/ui";
|
||||
import { useCallback } from "react";
|
||||
import { useRpcMutation } from "../hooks/useRpcMutation";
|
||||
import { useActionMetadata } from "../hooks/useActionMetadata";
|
||||
|
||||
type ActionIconButtonProps = Omit<IconButtonProps, 'onClick' | 'title'> & {
|
||||
type ActionIconButtonProps = Omit<IconButtonProps, "onClick" | "title"> & {
|
||||
action: ActionInvocation;
|
||||
title?: string;
|
||||
};
|
||||
|
||||
export function ActionIconButton({ action, ...props }: ActionIconButtonProps) {
|
||||
const meta = useActionMetadata(action);
|
||||
const { mutate, isPending } = useRpcMutation('execute_action');
|
||||
const { mutate, isPending } = useRpcMutation("execute_action");
|
||||
|
||||
const onClick = useCallback(() => {
|
||||
mutate(action);
|
||||
@@ -20,7 +20,7 @@ export function ActionIconButton({ action, ...props }: ActionIconButtonProps) {
|
||||
return (
|
||||
<IconButton
|
||||
{...props}
|
||||
title={props.title ?? meta?.label ?? '…'}
|
||||
title={props.title ?? meta?.label ?? "…"}
|
||||
disabled={props.disabled || isPending}
|
||||
isLoading={isPending}
|
||||
onClick={onClick}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { HttpExchange, ProxyHeader } from '@yaakapp-internal/proxy-lib';
|
||||
import type { HttpExchange, ProxyHeader } from "@yaakapp-internal/proxy-lib";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
TableHeaderCell,
|
||||
TableRow,
|
||||
TruncatedWideTableCell,
|
||||
} from '@yaakapp-internal/ui';
|
||||
import classNames from 'classnames';
|
||||
} from "@yaakapp-internal/ui";
|
||||
import classNames from "classnames";
|
||||
|
||||
interface Props {
|
||||
exchanges: HttpExchange[];
|
||||
@@ -59,19 +59,19 @@ function StatusBadge({ status, error }: { status: number | null; error: string |
|
||||
|
||||
const color =
|
||||
status >= 500
|
||||
? 'text-danger'
|
||||
? "text-danger"
|
||||
: status >= 400
|
||||
? 'text-warning'
|
||||
? "text-warning"
|
||||
: status >= 300
|
||||
? 'text-notice'
|
||||
: 'text-success';
|
||||
? "text-notice"
|
||||
: "text-success";
|
||||
|
||||
return <span className={classNames('text-xs font-mono', color)}>{status}</span>;
|
||||
return <span className={classNames("text-xs font-mono", color)}>{status}</span>;
|
||||
}
|
||||
|
||||
function getContentType(headers: ProxyHeader[]): string {
|
||||
const ct = headers.find((h) => h.name.toLowerCase() === 'content-type')?.value;
|
||||
if (ct == null) return '—';
|
||||
const ct = headers.find((h) => h.name.toLowerCase() === "content-type")?.value;
|
||||
if (ct == null) return "—";
|
||||
// Strip parameters (e.g. "; charset=utf-8")
|
||||
return ct.split(';')[0]?.trim() ?? ct;
|
||||
return ct.split(";")[0]?.trim() ?? ct;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
import { HeaderSize, IconButton, SidebarLayout, SplitLayout } from '@yaakapp-internal/ui';
|
||||
import classNames from 'classnames';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useState } from 'react';
|
||||
import { useLocalStorage } from 'react-use';
|
||||
import { useRpcQueryWithEvent } from '../hooks/useRpcQueryWithEvent';
|
||||
import { getOsType } from '../lib/tauri';
|
||||
import { ActionIconButton } from './ActionIconButton';
|
||||
import { ExchangesTable } from './ExchangesTable';
|
||||
import { filteredExchangesAtom, Sidebar } from './Sidebar';
|
||||
import { HeaderSize, IconButton, SidebarLayout, SplitLayout } from "@yaakapp-internal/ui";
|
||||
import classNames from "classnames";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { useState } from "react";
|
||||
import { useLocalStorage } from "react-use";
|
||||
import { useRpcQueryWithEvent } from "../hooks/useRpcQueryWithEvent";
|
||||
import { getOsType } from "../lib/tauri";
|
||||
import { ActionIconButton } from "./ActionIconButton";
|
||||
import { ExchangesTable } from "./ExchangesTable";
|
||||
import { filteredExchangesAtom, Sidebar } from "./Sidebar";
|
||||
|
||||
export function ProxyLayout() {
|
||||
const os = getOsType();
|
||||
const exchanges = useAtomValue(filteredExchangesAtom);
|
||||
const [sidebarWidth, setSidebarWidth] = useLocalStorage('sidebar_width', 250);
|
||||
const [sidebarHidden, setSidebarHidden] = useLocalStorage('sidebar_hidden', false);
|
||||
const [sidebarWidth, setSidebarWidth] = useLocalStorage("sidebar_width", 250);
|
||||
const [sidebarHidden, setSidebarHidden] = useLocalStorage("sidebar_hidden", false);
|
||||
const [floatingSidebarHidden, setFloatingSidebarHidden] = useLocalStorage(
|
||||
'floating_sidebar_hidden',
|
||||
"floating_sidebar_hidden",
|
||||
true,
|
||||
);
|
||||
const [floating, setFloating] = useState(false);
|
||||
const { data: proxyState } = useRpcQueryWithEvent('get_proxy_state', {}, 'proxy_state_changed');
|
||||
const isRunning = proxyState?.state === 'running';
|
||||
const { data: proxyState } = useRpcQueryWithEvent("get_proxy_state", {}, "proxy_state_changed");
|
||||
const isRunning = proxyState?.state === "running";
|
||||
const isHidden = floating ? (floatingSidebarHidden ?? true) : (sidebarHidden ?? false);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
'h-full w-full grid grid-rows-[auto_1fr]',
|
||||
os === 'linux' && 'border border-border-subtle',
|
||||
"h-full w-full grid grid-rows-[auto_1fr]",
|
||||
os === "linux" && "border border-border-subtle",
|
||||
)}
|
||||
>
|
||||
<HeaderSize
|
||||
@@ -44,7 +44,7 @@ export function ProxyLayout() {
|
||||
<IconButton
|
||||
size="sm"
|
||||
title="Toggle sidebar"
|
||||
icon={isHidden ? 'left_panel_hidden' : 'left_panel_visible'}
|
||||
icon={isHidden ? "left_panel_hidden" : "left_panel_visible"}
|
||||
iconColor="secondary"
|
||||
onClick={() => {
|
||||
if (floating) {
|
||||
@@ -66,7 +66,7 @@ export function ProxyLayout() {
|
||||
<>
|
||||
<span className="text-2xs text-success">Running :9090</span>
|
||||
<ActionIconButton
|
||||
action={{ scope: 'global', action: 'proxy_stop' }}
|
||||
action={{ scope: "global", action: "proxy_stop" }}
|
||||
icon="circle_stop"
|
||||
iconColor="secondary"
|
||||
size="sm"
|
||||
@@ -74,7 +74,7 @@ export function ProxyLayout() {
|
||||
</>
|
||||
) : (
|
||||
<ActionIconButton
|
||||
action={{ scope: 'global', action: 'proxy_start' }}
|
||||
action={{ scope: "global", action: "proxy_start" }}
|
||||
icon="circle_play"
|
||||
iconColor="secondary"
|
||||
size="sm"
|
||||
@@ -95,9 +95,9 @@ export function ProxyLayout() {
|
||||
floating ? (
|
||||
<div
|
||||
className={classNames(
|
||||
'x-theme-sidebar',
|
||||
'h-full bg-surface border-r border-border-subtle',
|
||||
'grid grid-rows-[auto_1fr]',
|
||||
"x-theme-sidebar",
|
||||
"h-full bg-surface border-r border-border-subtle",
|
||||
"grid grid-rows-[auto_1fr]",
|
||||
)}
|
||||
>
|
||||
<HeaderSize
|
||||
@@ -132,7 +132,10 @@ export function ProxyLayout() {
|
||||
<ExchangesTable exchanges={exchanges} style={style} className="overflow-auto" />
|
||||
)}
|
||||
secondSlot={({ style }) => (
|
||||
<div style={style} className="p-3 text-text-subtlest text-sm border-t border-border-subtle">
|
||||
<div
|
||||
style={style}
|
||||
className="p-3 text-text-subtlest text-sm border-t border-border-subtle"
|
||||
>
|
||||
Select a request to view details
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { HttpExchange } from '@yaakapp-internal/proxy-lib';
|
||||
import type { TreeNode } from '@yaakapp-internal/ui';
|
||||
import { selectedIdsFamily, Tree } from '@yaakapp-internal/ui';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { atomFamily } from 'jotai/utils';
|
||||
import { useCallback } from 'react';
|
||||
import { httpExchangesAtom } from '../lib/store';
|
||||
import type { HttpExchange } from "@yaakapp-internal/proxy-lib";
|
||||
import type { TreeNode } from "@yaakapp-internal/ui";
|
||||
import { selectedIdsFamily, Tree } from "@yaakapp-internal/ui";
|
||||
import { atom, useAtomValue } from "jotai";
|
||||
import { atomFamily } from "jotai/utils";
|
||||
import { useCallback } from "react";
|
||||
import { httpExchangesAtom } from "../lib/store";
|
||||
|
||||
/** A node in the sidebar tree — either a domain or a path segment. */
|
||||
export type SidebarItem = {
|
||||
@@ -15,7 +15,7 @@ export type SidebarItem = {
|
||||
|
||||
const collapsedAtom = atomFamily((_treeId: string) => atom<Record<string, boolean>>({}));
|
||||
|
||||
export const SIDEBAR_TREE_ID = 'proxy-sidebar';
|
||||
export const SIDEBAR_TREE_ID = "proxy-sidebar";
|
||||
|
||||
const sidebarTreeAtom = atom<TreeNode<SidebarItem>>((get) => {
|
||||
const exchanges = get(httpExchangesAtom);
|
||||
@@ -29,7 +29,7 @@ export const filteredExchangesAtom = atom((get) => {
|
||||
const selectedIds = get(selectedIdsFamily(SIDEBAR_TREE_ID));
|
||||
|
||||
// Nothing selected or root selected → show all
|
||||
if (selectedIds.length === 0 || selectedIds.includes('root')) {
|
||||
if (selectedIds.length === 0 || selectedIds.includes("root")) {
|
||||
return exchanges;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ function collectNodes(node: TreeNode<SidebarItem>, map: Map<string, SidebarItem>
|
||||
* /orders
|
||||
*/
|
||||
function buildTree(exchanges: HttpExchange[]): TreeNode<SidebarItem> {
|
||||
const root: SidebarItem = { id: 'root', label: 'All Traffic', exchangeIds: [] };
|
||||
const root: SidebarItem = { id: "root", label: "All Traffic", exchangeIds: [] };
|
||||
const rootNode: TreeNode<SidebarItem> = {
|
||||
item: root,
|
||||
parent: null,
|
||||
@@ -98,7 +98,7 @@ function buildTree(exchanges: HttpExchange[]): TreeNode<SidebarItem> {
|
||||
try {
|
||||
const url = new URL(ex.url);
|
||||
hostname = url.host;
|
||||
segments = url.pathname.split('/').filter(Boolean);
|
||||
segments = url.pathname.split("/").filter(Boolean);
|
||||
} catch {
|
||||
hostname = ex.url;
|
||||
segments = [];
|
||||
@@ -125,7 +125,7 @@ function buildTree(exchanges: HttpExchange[]): TreeNode<SidebarItem> {
|
||||
let child = current.children.get(seg);
|
||||
if (!child) {
|
||||
child = {
|
||||
id: `path:${hostname}/${pathSoFar.join('/')}`,
|
||||
id: `path:${hostname}/${pathSoFar.join("/")}`,
|
||||
label: `/${seg}`,
|
||||
exchangeIds: [],
|
||||
children: new Map(),
|
||||
@@ -166,7 +166,7 @@ function buildTree(exchanges: HttpExchange[]): TreeNode<SidebarItem> {
|
||||
// Add a "Domains" folder between root and domain nodes
|
||||
const allExchangeIds = exchanges.map((ex) => ex.id);
|
||||
const domainsFolder: TreeNode<SidebarItem> = {
|
||||
item: { id: 'domains', label: 'Domains', exchangeIds: allExchangeIds },
|
||||
item: { id: "domains", label: "Domains", exchangeIds: allExchangeIds },
|
||||
parent: rootNode,
|
||||
depth: 1,
|
||||
children: [],
|
||||
@@ -197,7 +197,10 @@ export function Sidebar() {
|
||||
const tree = useAtomValue(sidebarTreeAtom);
|
||||
const treeId = SIDEBAR_TREE_ID;
|
||||
|
||||
const getItemKey = useCallback((item: SidebarItem) => `${item.id}:${item.exchangeIds.length}`, []);
|
||||
const getItemKey = useCallback(
|
||||
(item: SidebarItem) => `${item.id}:${item.exchangeIds.length}`,
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<aside className="x-theme-sidebar bg-surface h-full w-full min-w-0 overflow-y-auto border-r border-border-subtle">
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// Hardcode font size for now. In the future, this could be configurable.
|
||||
document.documentElement.style.fontSize = '15px';
|
||||
document.documentElement.style.fontSize = "15px";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ActionInvocation, ActionMetadata } from '@yaakapp-internal/proxy-lib';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { rpc } from '../lib/rpc';
|
||||
import type { ActionInvocation, ActionMetadata } from "@yaakapp-internal/proxy-lib";
|
||||
import { useEffect, useState } from "react";
|
||||
import { rpc } from "../lib/rpc";
|
||||
|
||||
/** Look up metadata for a specific action invocation. */
|
||||
export function useActionMetadata(action: ActionInvocation): ActionMetadata | null {
|
||||
@@ -23,7 +23,7 @@ let cachedActions: [ActionInvocation, ActionMetadata][] | null = null;
|
||||
/** Fetch and cache all action metadata. */
|
||||
async function getActions(): Promise<[ActionInvocation, ActionMetadata][]> {
|
||||
if (!cachedActions) {
|
||||
const { actions } = await rpc('list_actions', {});
|
||||
const { actions } = await rpc("list_actions", {});
|
||||
cachedActions = actions;
|
||||
}
|
||||
return cachedActions;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { RpcEventSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import { useEffect } from 'react';
|
||||
import { listen } from '../lib/rpc';
|
||||
import type { RpcEventSchema } from "@yaakapp-internal/proxy-lib";
|
||||
import { useEffect } from "react";
|
||||
import { listen } from "../lib/rpc";
|
||||
|
||||
/**
|
||||
* Subscribe to an RPC event. Cleans up automatically on unmount.
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { type UseMutationOptions, useMutation } from '@tanstack/react-query';
|
||||
import type { RpcSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import { minPromiseMillis } from '@yaakapp-internal/ui';
|
||||
import type { Req, Res } from '../lib/rpc';
|
||||
import { rpc } from '../lib/rpc';
|
||||
import { type UseMutationOptions, useMutation } from "@tanstack/react-query";
|
||||
import type { RpcSchema } from "@yaakapp-internal/proxy-lib";
|
||||
import { minPromiseMillis } from "@yaakapp-internal/ui";
|
||||
import type { Req, Res } from "../lib/rpc";
|
||||
import { rpc } from "../lib/rpc";
|
||||
|
||||
/**
|
||||
* React Query mutation wrapper for RPC commands.
|
||||
*/
|
||||
export function useRpcMutation<K extends keyof RpcSchema>(
|
||||
cmd: K,
|
||||
opts?: Omit<UseMutationOptions<Res<K>, Error, Req<K>>, 'mutationFn'>,
|
||||
opts?: Omit<UseMutationOptions<Res<K>, Error, Req<K>>, "mutationFn">,
|
||||
) {
|
||||
return useMutation<Res<K>, Error, Req<K>>({
|
||||
mutationFn: (payload) => minPromiseMillis(rpc(cmd, payload)),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { type UseQueryOptions, useQuery } from '@tanstack/react-query';
|
||||
import type { RpcSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import type { Req, Res } from '../lib/rpc';
|
||||
import { rpc } from '../lib/rpc';
|
||||
import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
|
||||
import type { RpcSchema } from "@yaakapp-internal/proxy-lib";
|
||||
import type { Req, Res } from "../lib/rpc";
|
||||
import { rpc } from "../lib/rpc";
|
||||
|
||||
/**
|
||||
* React Query wrapper for RPC commands.
|
||||
@@ -10,7 +10,7 @@ import { rpc } from '../lib/rpc';
|
||||
export function useRpcQuery<K extends keyof RpcSchema>(
|
||||
cmd: K,
|
||||
payload: Req<K>,
|
||||
opts?: Omit<UseQueryOptions<Res<K>>, 'queryKey' | 'queryFn'>,
|
||||
opts?: Omit<UseQueryOptions<Res<K>>, "queryKey" | "queryFn">,
|
||||
) {
|
||||
return useQuery<Res<K>>({
|
||||
queryKey: [cmd, payload],
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { type UseQueryOptions, useQueryClient } from '@tanstack/react-query';
|
||||
import type { RpcEventSchema, RpcSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import type { Req, Res } from '../lib/rpc';
|
||||
import { useRpcEvent } from './useRpcEvent';
|
||||
import { useRpcQuery } from './useRpcQuery';
|
||||
import { type UseQueryOptions, useQueryClient } from "@tanstack/react-query";
|
||||
import type { RpcEventSchema, RpcSchema } from "@yaakapp-internal/proxy-lib";
|
||||
import type { Req, Res } from "../lib/rpc";
|
||||
import { useRpcEvent } from "./useRpcEvent";
|
||||
import { useRpcQuery } from "./useRpcQuery";
|
||||
|
||||
/**
|
||||
* Combines useRpcQuery with an event listener that invalidates the query
|
||||
@@ -11,7 +11,7 @@ import { useRpcQuery } from './useRpcQuery';
|
||||
export function useRpcQueryWithEvent<
|
||||
K extends keyof RpcSchema,
|
||||
E extends keyof RpcEventSchema & string,
|
||||
>(cmd: K, payload: Req<K>, event: E, opts?: Omit<UseQueryOptions<Res<K>>, 'queryKey' | 'queryFn'>) {
|
||||
>(cmd: K, payload: Req<K>, event: E, opts?: Omit<UseQueryOptions<Res<K>>, "queryKey" | "queryFn">) {
|
||||
const queryClient = useQueryClient();
|
||||
const query = useRpcQuery(cmd, payload, opts);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ActionInvocation, ActionMetadata } from '@yaakapp-internal/proxy-lib';
|
||||
import { rpc } from './rpc';
|
||||
import type { ActionInvocation, ActionMetadata } from "@yaakapp-internal/proxy-lib";
|
||||
import { rpc } from "./rpc";
|
||||
|
||||
type ActionBinding = {
|
||||
invocation: ActionInvocation;
|
||||
@@ -8,21 +8,21 @@ type ActionBinding = {
|
||||
};
|
||||
|
||||
/** Parse a hotkey string like "Ctrl+Shift+P" into its parts. */
|
||||
function parseHotkey(hotkey: string): ActionBinding['keys'] {
|
||||
const parts = hotkey.split('+').map((p) => p.trim().toLowerCase());
|
||||
function parseHotkey(hotkey: string): ActionBinding["keys"] {
|
||||
const parts = hotkey.split("+").map((p) => p.trim().toLowerCase());
|
||||
return {
|
||||
ctrl: parts.includes('ctrl') || parts.includes('control'),
|
||||
shift: parts.includes('shift'),
|
||||
alt: parts.includes('alt'),
|
||||
meta: parts.includes('meta') || parts.includes('cmd') || parts.includes('command'),
|
||||
ctrl: parts.includes("ctrl") || parts.includes("control"),
|
||||
shift: parts.includes("shift"),
|
||||
alt: parts.includes("alt"),
|
||||
meta: parts.includes("meta") || parts.includes("cmd") || parts.includes("command"),
|
||||
key:
|
||||
parts.filter(
|
||||
(p) => !['ctrl', 'control', 'shift', 'alt', 'meta', 'cmd', 'command'].includes(p),
|
||||
)[0] ?? '',
|
||||
(p) => !["ctrl", "control", "shift", "alt", "meta", "cmd", "command"].includes(p),
|
||||
)[0] ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
function matchesEvent(binding: ActionBinding['keys'], e: KeyboardEvent): boolean {
|
||||
function matchesEvent(binding: ActionBinding["keys"], e: KeyboardEvent): boolean {
|
||||
return (
|
||||
e.ctrlKey === binding.ctrl &&
|
||||
e.shiftKey === binding.shift &&
|
||||
@@ -34,7 +34,7 @@ function matchesEvent(binding: ActionBinding['keys'], e: KeyboardEvent): boolean
|
||||
|
||||
/** Fetch all actions from Rust and register a global keydown listener. */
|
||||
export async function initHotkeys(): Promise<() => void> {
|
||||
const { actions } = await rpc('list_actions', {});
|
||||
const { actions } = await rpc("list_actions", {});
|
||||
|
||||
const bindings: ActionBinding[] = actions
|
||||
.filter(
|
||||
@@ -51,12 +51,12 @@ export async function initHotkeys(): Promise<() => void> {
|
||||
for (const binding of bindings) {
|
||||
if (matchesEvent(binding.keys, e)) {
|
||||
e.preventDefault();
|
||||
rpc('execute_action', binding.invocation);
|
||||
rpc("execute_action", binding.invocation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('keydown', onKeyDown);
|
||||
return () => window.removeEventListener('keydown', onKeyDown);
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { RpcEventSchema, RpcSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import { command, subscribe } from './tauri';
|
||||
import type { RpcEventSchema, RpcSchema } from "@yaakapp-internal/proxy-lib";
|
||||
import { command, subscribe } from "./tauri";
|
||||
|
||||
export type Req<K extends keyof RpcSchema> = RpcSchema[K][0];
|
||||
export type Res<K extends keyof RpcSchema> = RpcSchema[K][1];
|
||||
|
||||
export async function rpc<K extends keyof RpcSchema>(cmd: K, payload: Req<K>): Promise<Res<K>> {
|
||||
return command<Res<K>>('rpc', { cmd, payload });
|
||||
return command<Res<K>>("rpc", { cmd, payload });
|
||||
}
|
||||
|
||||
/** Subscribe to a backend event. Returns an unsubscribe function. */
|
||||
|
||||
@@ -8,8 +8,4 @@ type ProxyModels = {
|
||||
export const { dataAtom, applyChange, replaceAll, listAtom, orderedListAtom } =
|
||||
createModelStore<ProxyModels>(["http_exchange"]);
|
||||
|
||||
export const httpExchangesAtom = orderedListAtom(
|
||||
"http_exchange",
|
||||
"createdAt",
|
||||
"desc",
|
||||
);
|
||||
export const httpExchangesAtom = orderedListAtom("http_exchange", "createdAt", "desc");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { listen as tauriListen } from '@tauri-apps/api/event';
|
||||
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||
import { type as tauriOsType } from '@tauri-apps/plugin-os';
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen as tauriListen } from "@tauri-apps/api/event";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { type as tauriOsType } from "@tauri-apps/plugin-os";
|
||||
|
||||
/** Call a Tauri command. */
|
||||
export function command<T>(cmd: string, args?: Record<string, unknown>): Promise<T> {
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { createStore, Provider } from 'jotai';
|
||||
import { LazyMotion, MotionConfig } from 'motion/react';
|
||||
import { StrictMode } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { ProxyLayout } from './components/ProxyLayout';
|
||||
import { listen, rpc } from './lib/rpc';
|
||||
import { initHotkeys } from './lib/hotkeys';
|
||||
import { applyChange, dataAtom, replaceAll } from './lib/store';
|
||||
import './main.css';
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { createStore, Provider } from "jotai";
|
||||
import { LazyMotion, MotionConfig } from "motion/react";
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { ProxyLayout } from "./components/ProxyLayout";
|
||||
import { listen, rpc } from "./lib/rpc";
|
||||
import { initHotkeys } from "./lib/hotkeys";
|
||||
import { applyChange, dataAtom, replaceAll } from "./lib/store";
|
||||
import "./main.css";
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
const jotaiStore = createStore();
|
||||
|
||||
// Load initial models from the database
|
||||
rpc('list_models', {}).then((res) => {
|
||||
jotaiStore.set(dataAtom, (prev) => replaceAll(prev, 'http_exchange', res.httpExchanges));
|
||||
rpc("list_models", {}).then((res) => {
|
||||
jotaiStore.set(dataAtom, (prev) => replaceAll(prev, "http_exchange", res.httpExchanges));
|
||||
});
|
||||
|
||||
// Register hotkeys from action metadata
|
||||
initHotkeys();
|
||||
|
||||
// Subscribe to model change events from the backend
|
||||
listen('model_write', (payload) => {
|
||||
listen("model_write", (payload) => {
|
||||
jotaiStore.set(dataAtom, (prev) =>
|
||||
applyChange(prev, 'http_exchange', payload.model, payload.change),
|
||||
applyChange(prev, "http_exchange", payload.model, payload.change),
|
||||
);
|
||||
});
|
||||
|
||||
const motionFeatures = () => import('framer-motion').then((mod) => mod.domAnimation);
|
||||
const motionFeatures = () => import("framer-motion").then((mod) => mod.domAnimation);
|
||||
|
||||
createRoot(document.getElementById('root') as HTMLElement).render(
|
||||
createRoot(document.getElementById("root") as HTMLElement).render(
|
||||
<StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<Provider store={jotaiStore}>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@yaakapp/yaak-proxy",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev --force",
|
||||
@@ -12,9 +12,9 @@
|
||||
"@tanstack/react-query": "^5.90.5",
|
||||
"@tauri-apps/api": "^2.9.1",
|
||||
"@tauri-apps/plugin-os": "^2.3.2",
|
||||
"@yaakapp-internal/theme": "^1.0.0",
|
||||
"@yaakapp-internal/model-store": "^1.0.0",
|
||||
"@yaakapp-internal/proxy-lib": "^1.0.0",
|
||||
"@yaakapp-internal/theme": "^1.0.0",
|
||||
"@yaakapp-internal/ui": "^1.0.0",
|
||||
"classnames": "^2.5.1",
|
||||
"jotai": "^2.18.0",
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
"@yaakapp-internal/theme": ["../../packages/theme/src/index.ts"],
|
||||
"@yaakapp-internal/theme/*": ["../../packages/theme/src/*"],
|
||||
"@yaakapp-internal/ui": ["../../packages/ui/src/index.ts"],
|
||||
"@yaakapp-internal/ui/*": ["../../packages/ui/src/*"],
|
||||
},
|
||||
"@yaakapp-internal/ui/*": ["../../packages/ui/src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["."],
|
||||
"exclude": ["vite.config.ts"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user