mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 03:41:11 +01:00
Add transport-agnostic RPC layer for proxy app
Introduces yaak-rpc (shared RPC infrastructure) and yaak-proxy-lib (proxy app logic decoupled from any frontend). A single Tauri command dispatches all RPC calls through a typed router, with TypeScript types auto-generated via ts-rs and a generic rpc() function for type-safe calls from the frontend. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,15 @@
|
||||
import "./main.css";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { type } from "@tauri-apps/plugin-os";
|
||||
import { Button, HeaderSize } from "@yaakapp-internal/ui";
|
||||
import classNames from "classnames";
|
||||
import { StrictMode } from "react";
|
||||
import { useState } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { rpc } from "./rpc";
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
type ProxyStartResult = {
|
||||
port: number;
|
||||
alreadyRunning: boolean;
|
||||
};
|
||||
|
||||
function App() {
|
||||
const [status, setStatus] = useState("Idle");
|
||||
const [port, setPort] = useState<number | null>(null);
|
||||
@@ -25,9 +20,7 @@ function App() {
|
||||
setBusy(true);
|
||||
setStatus("Starting...");
|
||||
try {
|
||||
const result = await invoke<ProxyStartResult>("proxy_start", {
|
||||
port: 9090,
|
||||
});
|
||||
const result = await rpc("proxy_start", { port: 9090 });
|
||||
setPort(result.port);
|
||||
setStatus(result.alreadyRunning ? "Already running" : "Running");
|
||||
} catch (err) {
|
||||
@@ -41,7 +34,7 @@ function App() {
|
||||
setBusy(true);
|
||||
setStatus("Stopping...");
|
||||
try {
|
||||
const stopped = await invoke<boolean>("proxy_stop");
|
||||
const stopped = await rpc("proxy_stop", {});
|
||||
setPort(null);
|
||||
setStatus(stopped ? "Stopped" : "Not running");
|
||||
} catch (err) {
|
||||
|
||||
12
apps/yaak-proxy/rpc.ts
Normal file
12
apps/yaak-proxy/rpc.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type { RpcSchema } from "../../crates-proxy/yaak-proxy-lib/bindings/gen_rpc";
|
||||
|
||||
type Req<K extends keyof RpcSchema> = RpcSchema[K][0];
|
||||
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 invoke("rpc", { cmd, payload }) as Promise<Res<K>>;
|
||||
}
|
||||
Reference in New Issue
Block a user