mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-25 12:54:09 +02:00
Add a typed platform package to decouple the frontend from Tauri (#539)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0068be9ffc
commit
2383f06e71
@@ -1,17 +1,17 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
|
||||
export function enableEncryption(workspaceId: string) {
|
||||
return invoke<void>("cmd_enable_encryption", { workspaceId });
|
||||
return platform.rpc<void>("cmd_enable_encryption", { workspaceId });
|
||||
}
|
||||
|
||||
export function revealWorkspaceKey(workspaceId: string) {
|
||||
return invoke<string>("cmd_reveal_workspace_key", { workspaceId });
|
||||
return platform.rpc<string>("cmd_reveal_workspace_key", { workspaceId });
|
||||
}
|
||||
|
||||
export function setWorkspaceKey(args: { workspaceId: string; key: string }) {
|
||||
return invoke<void>("cmd_set_workspace_key", args);
|
||||
return platform.rpc<void>("cmd_set_workspace_key", args);
|
||||
}
|
||||
|
||||
export function disableEncryption(workspaceId: string) {
|
||||
return invoke<void>("cmd_disable_encryption", { workspaceId });
|
||||
return platform.rpc<void>("cmd_disable_encryption", { workspaceId });
|
||||
}
|
||||
|
||||
+44
-46
@@ -1,6 +1,5 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Channel, invoke } from "@tauri-apps/api/core";
|
||||
import { emit } from "@tauri-apps/api/event";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
import { createFastMutation } from "@yaakapp/yaak-client/hooks/useFastMutation";
|
||||
import { queryClient } from "@yaakapp/yaak-client/lib/queryClient";
|
||||
import { useMemo } from "react";
|
||||
@@ -59,18 +58,17 @@ export function invalidateGitWorktreeStatus(dir?: string) {
|
||||
export function useGitWorktreeStatus(dir: string, refreshKey?: string) {
|
||||
return useQuery<GitWorktreeStatus, string>({
|
||||
queryKey: gitWorktreeStatusQueryKey(dir, refreshKey),
|
||||
queryFn: () => invoke("cmd_git_worktree_status", { dir }),
|
||||
queryFn: () => platform.rpc("cmd_git_worktree_status", { dir }),
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
}
|
||||
|
||||
export function watchGitWorktreeStatus(dir: string, callback: (status: GitWorktreeStatus) => void) {
|
||||
const channel = new Channel<GitWorktreeStatus>();
|
||||
channel.onmessage = callback;
|
||||
const unlistenPromise = invoke<GitWatchResult>("cmd_git_watch_worktree_status", {
|
||||
dir,
|
||||
channel,
|
||||
});
|
||||
const unlistenPromise = platform.rpcStream<GitWatchResult, GitWorktreeStatus>(
|
||||
"cmd_git_watch_worktree_status",
|
||||
{ dir },
|
||||
callback,
|
||||
);
|
||||
|
||||
void unlistenPromise
|
||||
.then(({ unlistenEvent }) => {
|
||||
@@ -89,7 +87,7 @@ export function watchGitWorktreeStatus(dir: string, callback: (status: GitWorktr
|
||||
function useGitFetchAll(dir: string, refreshKey?: string) {
|
||||
return useQuery<void, string>({
|
||||
queryKey: ["git", "fetch_all", dir, refreshKey],
|
||||
queryFn: () => invoke("cmd_git_fetch_all", { dir }),
|
||||
queryFn: () => platform.rpc("cmd_git_fetch_all", { dir }),
|
||||
refetchInterval: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
@@ -98,7 +96,7 @@ function useGitBranchInfoQuery(dir: string, refreshKey?: string, fetchAllUpdated
|
||||
return useQuery<GitBranchInfo, string>({
|
||||
refetchOnMount: true,
|
||||
queryKey: ["git", "branch_info", dir, refreshKey, fetchAllUpdatedAt],
|
||||
queryFn: () => invoke("cmd_git_branch_info", { dir }),
|
||||
queryFn: () => platform.rpc("cmd_git_branch_info", { dir }),
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
}
|
||||
@@ -113,8 +111,8 @@ export function useGitLog(dir: string, refreshKey?: string, relaPath?: string) {
|
||||
queryKey: ["git", "log", dir, refreshKey, relaPath],
|
||||
queryFn: () =>
|
||||
relaPath == null
|
||||
? invoke("cmd_git_log", { dir })
|
||||
: invoke("cmd_git_log_for_file", { dir, relaPath }),
|
||||
? platform.rpc("cmd_git_log", { dir })
|
||||
: platform.rpc("cmd_git_log_for_file", { dir, relaPath }),
|
||||
placeholderData: (prev) => prev,
|
||||
});
|
||||
}
|
||||
@@ -129,7 +127,7 @@ export function useGitFileDiffForCommit(
|
||||
queryKey: ["git", "file_diff_for_commit", dir, relaPath, commitOid],
|
||||
queryFn: () => {
|
||||
if (commitOid == null) throw new Error("Missing commit oid");
|
||||
return invoke("cmd_git_file_diff_for_commit", { dir, relaPath, commitOid });
|
||||
return platform.rpc("cmd_git_file_diff_for_commit", { dir, relaPath, commitOid });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -149,7 +147,7 @@ export function useGit(dir: string, callbacks: GitCallbacks, refreshKey?: string
|
||||
status: useQuery<GitStatusSummary, string>({
|
||||
refetchOnMount: true,
|
||||
queryKey: ["git", "status", dir, refreshKey, fetchAll.dataUpdatedAt],
|
||||
queryFn: () => invoke("cmd_git_status", { dir }),
|
||||
queryFn: () => platform.rpc("cmd_git_status", { dir }),
|
||||
placeholderData: (prev) => prev,
|
||||
}),
|
||||
},
|
||||
@@ -169,21 +167,21 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
if (remote == null) throw new Error("No remote found");
|
||||
}
|
||||
|
||||
const result = await invoke<PushResult>("cmd_git_push", { dir });
|
||||
const result = await platform.rpc<PushResult>("cmd_git_push", { dir });
|
||||
if (result.type !== "needs_credentials") return result;
|
||||
|
||||
// Needs credentials, prompt for them
|
||||
const creds = await callbacks.promptCredentials(result);
|
||||
if (creds == null) throw new Error("Canceled");
|
||||
|
||||
await invoke("cmd_git_add_credential", {
|
||||
await platform.rpc("cmd_git_add_credential", {
|
||||
remoteUrl: result.url,
|
||||
username: creds.username,
|
||||
password: creds.password,
|
||||
});
|
||||
|
||||
// Push again
|
||||
return invoke<PushResult>("cmd_git_push", { dir });
|
||||
return platform.rpc<PushResult>("cmd_git_push", { dir });
|
||||
};
|
||||
|
||||
const handleError = (err: unknown) => {
|
||||
@@ -198,32 +196,32 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
return {
|
||||
init: createFastMutation<void, string, void>({
|
||||
mutationKey: ["git", "init"],
|
||||
mutationFn: () => invoke("cmd_git_initialize", { dir }),
|
||||
mutationFn: () => platform.rpc("cmd_git_initialize", { dir }),
|
||||
onSuccess,
|
||||
}),
|
||||
add: createFastMutation<void, string, { relaPaths: string[] }>({
|
||||
mutationKey: ["git", "add", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_add", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_add", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
addRemote: createFastMutation<GitRemote, string, GitRemote>({
|
||||
mutationKey: ["git", "add-remote"],
|
||||
mutationFn: (args) => invoke("cmd_git_add_remote", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_add_remote", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
rmRemote: createFastMutation<void, string, { name: string }>({
|
||||
mutationKey: ["git", "rm-remote", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_rm_remote", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_rm_remote", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
createBranch: createFastMutation<void, string, { branch: string; base?: string }>({
|
||||
mutationKey: ["git", "branch", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_branch", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
mergeBranch: createFastMutation<void, string, { branch: string }>({
|
||||
mutationKey: ["git", "merge", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_merge_branch", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_merge_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
deleteBranch: createFastMutation<
|
||||
@@ -232,33 +230,33 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
{ branch: string; force?: boolean }
|
||||
>({
|
||||
mutationKey: ["git", "delete-branch", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_delete_branch", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_delete_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
deleteRemoteBranch: createFastMutation<void, string, { branch: string }>({
|
||||
mutationKey: ["git", "delete-remote-branch", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_delete_remote_branch", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_delete_remote_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
renameBranch: createFastMutation<void, string, { oldName: string; newName: string }>({
|
||||
mutationKey: ["git", "rename-branch", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_rename_branch", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_rename_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
checkout: createFastMutation<string, string, { branch: string; force: boolean }>({
|
||||
mutationKey: ["git", "checkout", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_checkout", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_checkout", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
commit: createFastMutation<void, string, { message: string }>({
|
||||
mutationKey: ["git", "commit", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_commit", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_commit", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
commitAndPush: createFastMutation<PushResult, string, { message: string }>({
|
||||
mutationKey: ["git", "commit_push", dir],
|
||||
mutationFn: async (args) => {
|
||||
await invoke("cmd_git_commit", { dir, ...args });
|
||||
await platform.rpc("cmd_git_commit", { dir, ...args });
|
||||
return push();
|
||||
},
|
||||
onSuccess,
|
||||
@@ -272,20 +270,20 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
pull: createFastMutation<PullResult, string, void>({
|
||||
mutationKey: ["git", "pull", dir],
|
||||
async mutationFn() {
|
||||
const result = await invoke<PullResult>("cmd_git_pull", { dir });
|
||||
const result = await platform.rpc<PullResult>("cmd_git_pull", { dir });
|
||||
|
||||
if (result.type === "needs_credentials") {
|
||||
const creds = await callbacks.promptCredentials(result);
|
||||
if (creds == null) throw new Error("Canceled");
|
||||
|
||||
await invoke("cmd_git_add_credential", {
|
||||
await platform.rpc("cmd_git_add_credential", {
|
||||
remoteUrl: result.url,
|
||||
username: creds.username,
|
||||
password: creds.password,
|
||||
});
|
||||
|
||||
// Pull again after credentials
|
||||
return invoke<PullResult>("cmd_git_pull", { dir });
|
||||
return platform.rpc<PullResult>("cmd_git_pull", { dir });
|
||||
}
|
||||
|
||||
if (result.type === "uncommitted_changes") {
|
||||
@@ -294,8 +292,8 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
.then(async (strategy) => {
|
||||
if (strategy === "cancel") return;
|
||||
|
||||
await invoke("cmd_git_reset_changes", { dir });
|
||||
return invoke<PullResult>("cmd_git_pull", { dir });
|
||||
await platform.rpc("cmd_git_reset_changes", { dir });
|
||||
return platform.rpc<PullResult>("cmd_git_pull", { dir });
|
||||
})
|
||||
.then(async () => {
|
||||
await onSuccess();
|
||||
@@ -310,14 +308,14 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
if (strategy === "cancel") return;
|
||||
|
||||
if (strategy === "force_reset") {
|
||||
return invoke<PullResult>("cmd_git_pull_force_reset", {
|
||||
return platform.rpc<PullResult>("cmd_git_pull_force_reset", {
|
||||
dir,
|
||||
remote: result.remote,
|
||||
branch: result.branch,
|
||||
});
|
||||
}
|
||||
|
||||
return invoke<PullResult>("cmd_git_pull_merge", {
|
||||
return platform.rpc<PullResult>("cmd_git_pull_merge", {
|
||||
dir,
|
||||
remote: result.remote,
|
||||
branch: result.branch,
|
||||
@@ -335,17 +333,17 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
}),
|
||||
unstage: createFastMutation<void, string, { relaPaths: string[] }>({
|
||||
mutationKey: ["git", "unstage", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_unstage", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_unstage", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
resetChanges: createFastMutation<void, string, void>({
|
||||
mutationKey: ["git", "reset-changes", dir],
|
||||
mutationFn: () => invoke("cmd_git_reset_changes", { dir }),
|
||||
mutationFn: () => platform.rpc("cmd_git_reset_changes", { dir }),
|
||||
onSuccess,
|
||||
}),
|
||||
restore: createFastMutation<void, string, { relaPaths: string[] }>({
|
||||
mutationKey: ["git", "restore", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_restore_files", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_restore_files", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
restoreFileFromCommit: createFastMutation<
|
||||
@@ -354,18 +352,18 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
{ commitOid: string; relaPath: string }
|
||||
>({
|
||||
mutationKey: ["git", "restore-file-from-commit", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_restore_file_from_commit", { dir, ...args }),
|
||||
mutationFn: (args) => platform.rpc("cmd_git_restore_file_from_commit", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
} as const;
|
||||
};
|
||||
|
||||
async function getRemotes(dir: string) {
|
||||
return invoke<GitRemote[]>("cmd_git_remotes", { dir });
|
||||
return platform.rpc<GitRemote[]>("cmd_git_remotes", { dir });
|
||||
}
|
||||
|
||||
function unlistenGitWatcher(unlistenEvent: string) {
|
||||
void emit(unlistenEvent).then(() => {
|
||||
void platform.emit(unlistenEvent).then(() => {
|
||||
removeGitWatchKey(unlistenEvent);
|
||||
});
|
||||
}
|
||||
@@ -404,7 +402,7 @@ export async function gitClone(
|
||||
error: string | null;
|
||||
}) => Promise<GitCredentials | null>,
|
||||
): Promise<CloneResult> {
|
||||
const result = await invoke<CloneResult>("cmd_git_clone", { url, dir });
|
||||
const result = await platform.rpc<CloneResult>("cmd_git_clone", { url, dir });
|
||||
if (result.type !== "needs_credentials") return result;
|
||||
|
||||
// Prompt for credentials
|
||||
@@ -415,11 +413,11 @@ export async function gitClone(
|
||||
if (creds == null) return { type: "cancelled" };
|
||||
|
||||
// Store credentials and retry
|
||||
await invoke("cmd_git_add_credential", {
|
||||
await platform.rpc("cmd_git_add_credential", {
|
||||
remoteUrl: result.url,
|
||||
username: creds.username,
|
||||
password: creds.password,
|
||||
});
|
||||
|
||||
return invoke<CloneResult>("cmd_git_clone", { url, dir });
|
||||
return platform.rpc<CloneResult>("cmd_git_clone", { url, dir });
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
import { debounce } from "@yaakapp-internal/lib";
|
||||
import { AnyModel, ModelPayload } from "../bindings/gen_models";
|
||||
import { modelStoreDataAtom } from "./atoms";
|
||||
@@ -16,37 +15,35 @@ export function initModelStore(store: JotaiStore) {
|
||||
// Don't lose debounced patches if the window closes while one is pending
|
||||
window.addEventListener("beforeunload", flushAllPendingPatches);
|
||||
|
||||
getCurrentWebviewWindow()
|
||||
.listen<ModelPayload[]>("model_writes", ({ payload: payloads }) => {
|
||||
mustStore().set(modelStoreDataAtom, (prev: ModelStoreData) => {
|
||||
// Apply the entire batch in one update, cloning each touched bucket only
|
||||
// once. Bulk writes (imports, sync, CLI) can carry hundreds of models.
|
||||
const next = { ...prev };
|
||||
const clonedBuckets = new Set<AnyModel["model"]>();
|
||||
let changed = false;
|
||||
platform.listen<ModelPayload[]>("model_writes", (payloads) => {
|
||||
mustStore().set(modelStoreDataAtom, (prev: ModelStoreData) => {
|
||||
// Apply the entire batch in one update, cloning each touched bucket only
|
||||
// once. Bulk writes (imports, sync, CLI) can carry hundreds of models.
|
||||
const next = { ...prev };
|
||||
const clonedBuckets = new Set<AnyModel["model"]>();
|
||||
let changed = false;
|
||||
|
||||
for (const payload of payloads) {
|
||||
if (shouldIgnoreModel(payload)) continue;
|
||||
if (isUnsafeObjectKey(payload.model.model)) continue;
|
||||
if (isUnsafeObjectKey(payload.model.id)) continue;
|
||||
for (const payload of payloads) {
|
||||
if (shouldIgnoreModel(payload)) continue;
|
||||
if (isUnsafeObjectKey(payload.model.model)) continue;
|
||||
if (isUnsafeObjectKey(payload.model.id)) continue;
|
||||
|
||||
if (payload.change.type === "upsert") {
|
||||
const modelType = payload.model.model;
|
||||
if (!clonedBuckets.has(modelType)) {
|
||||
next[modelType] = { ...next[modelType] } as never;
|
||||
clonedBuckets.add(modelType);
|
||||
}
|
||||
(next[modelType] as Record<string, AnyModel>)[payload.model.id] = payload.model;
|
||||
changed = true;
|
||||
} else {
|
||||
changed = applyModelDelete(next, clonedBuckets, payload.model) || changed;
|
||||
if (payload.change.type === "upsert") {
|
||||
const modelType = payload.model.model;
|
||||
if (!clonedBuckets.has(modelType)) {
|
||||
next[modelType] = { ...next[modelType] } as never;
|
||||
clonedBuckets.add(modelType);
|
||||
}
|
||||
(next[modelType] as Record<string, AnyModel>)[payload.model.id] = payload.model;
|
||||
changed = true;
|
||||
} else {
|
||||
changed = applyModelDelete(next, clonedBuckets, payload.model) || changed;
|
||||
}
|
||||
}
|
||||
|
||||
return changed ? next : prev;
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
return changed ? next : prev;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,7 +208,7 @@ let _activeWorkspaceId: string | null = null;
|
||||
|
||||
export async function changeModelStoreWorkspace(workspaceId: string | null) {
|
||||
console.log("Syncing models with new workspace", workspaceId);
|
||||
const workspaceModelsStr = await invoke<string>("models_workspace_models", {
|
||||
const workspaceModelsStr = await platform.rpc<string>("models_workspace_models", {
|
||||
workspaceId, // NOTE: if no workspace id provided, it will just fetch global models
|
||||
});
|
||||
const workspaceModels = JSON.parse(workspaceModelsStr) as AnyModel[];
|
||||
@@ -288,7 +285,7 @@ export async function patchModel<M extends AnyModel["model"], T extends ExtractM
|
||||
export async function updateModel<M extends AnyModel["model"], T extends ExtractModel<AnyModel, M>>(
|
||||
model: T,
|
||||
): Promise<string> {
|
||||
return trackModelWrite(invoke<string>("models_upsert", { model }));
|
||||
return trackModelWrite(platform.rpc<string>("models_upsert", { model }));
|
||||
}
|
||||
|
||||
export async function deleteModelById<
|
||||
@@ -305,7 +302,7 @@ export async function deleteModel<M extends AnyModel["model"], T extends Extract
|
||||
if (model == null) {
|
||||
throw new Error("Failed to delete null model");
|
||||
}
|
||||
await trackModelWrite(invoke<string>("models_delete", { model }));
|
||||
await trackModelWrite(platform.rpc<string>("models_delete", { model }));
|
||||
|
||||
// Apply the delete locally right away so callers can rely on the store once the
|
||||
// promise resolves. The backend echo arrives async, so anything that reads the
|
||||
@@ -331,20 +328,20 @@ export async function duplicateModel<
|
||||
await flushAllModelWrites();
|
||||
|
||||
return trackModelWrite(
|
||||
invoke<string>("models_duplicate", { modelType: model.model, modelId: model.id }),
|
||||
platform.rpc<string>("models_duplicate", { modelType: model.model, modelId: model.id }),
|
||||
);
|
||||
}
|
||||
|
||||
export async function createGlobalModel<T extends Exclude<AnyModel, { workspaceId: string }>>(
|
||||
patch: Partial<T> & Pick<T, "model">,
|
||||
): Promise<string> {
|
||||
return trackModelWrite(invoke<string>("models_upsert", { model: patch }));
|
||||
return trackModelWrite(platform.rpc<string>("models_upsert", { model: patch }));
|
||||
}
|
||||
|
||||
export async function createWorkspaceModel<T extends Extract<AnyModel, { workspaceId: string }>>(
|
||||
patch: Partial<T> & Pick<T, "model" | "workspaceId">,
|
||||
): Promise<string> {
|
||||
return trackModelWrite(invoke<string>("models_upsert", { model: patch }));
|
||||
return trackModelWrite(platform.rpc<string>("models_upsert", { model: patch }));
|
||||
}
|
||||
|
||||
export function replaceModelsInStore<
|
||||
@@ -399,7 +396,7 @@ function shouldIgnoreModel({ model, updateSource }: ModelPayload) {
|
||||
}
|
||||
|
||||
// Never ignore same-window updates
|
||||
if (updateSource.label === getCurrentWebviewWindow().label) {
|
||||
if (updateSource.label === platform.window.label) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
import { PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse } from "./bindings/gen_api";
|
||||
|
||||
export * from "./bindings/gen_models";
|
||||
@@ -6,25 +6,25 @@ export * from "./bindings/gen_events";
|
||||
export * from "./bindings/gen_search";
|
||||
|
||||
export async function searchPlugins(query: string) {
|
||||
return invoke<PluginSearchResponse>("cmd_plugins_search", { query });
|
||||
return platform.rpc<PluginSearchResponse>("cmd_plugins_search", { query });
|
||||
}
|
||||
|
||||
export async function installPlugin(name: string, version: string | null) {
|
||||
return invoke<void>("cmd_plugins_install", { name, version });
|
||||
return platform.rpc<void>("cmd_plugins_install", { name, version });
|
||||
}
|
||||
|
||||
export async function uninstallPlugin(pluginId: string) {
|
||||
return invoke<void>("cmd_plugins_uninstall", { pluginId });
|
||||
return platform.rpc<void>("cmd_plugins_uninstall", { pluginId });
|
||||
}
|
||||
|
||||
export async function checkPluginUpdates() {
|
||||
return invoke<PluginUpdatesResponse>("cmd_plugins_updates", {});
|
||||
return platform.rpc<PluginUpdatesResponse>("cmd_plugins_updates", {});
|
||||
}
|
||||
|
||||
export async function updateAllPlugins() {
|
||||
return invoke<PluginNameVersion[]>("cmd_plugins_update_all", {});
|
||||
return platform.rpc<PluginNameVersion[]>("cmd_plugins_update_all", {});
|
||||
}
|
||||
|
||||
export async function installPluginFromDirectory(directory: string) {
|
||||
return invoke<void>("cmd_plugins_install_from_directory", { directory });
|
||||
return platform.rpc<void>("cmd_plugins_install_from_directory", { directory });
|
||||
}
|
||||
|
||||
+10
-13
@@ -1,5 +1,4 @@
|
||||
import { Channel, invoke } from "@tauri-apps/api/core";
|
||||
import { emit } from "@tauri-apps/api/event";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
import type { WatchResult } from "@yaakapp-internal/tauri-client";
|
||||
import { SyncOp } from "./bindings/gen_sync";
|
||||
import { WatchEvent } from "./bindings/gen_watch";
|
||||
@@ -7,18 +6,18 @@ import { WatchEvent } from "./bindings/gen_watch";
|
||||
export * from "./bindings/gen_models";
|
||||
|
||||
export async function calculateSync(workspaceId: string, syncDir: string) {
|
||||
return invoke<SyncOp[]>("cmd_sync_calculate", {
|
||||
return platform.rpc<SyncOp[]>("cmd_sync_calculate", {
|
||||
workspaceId,
|
||||
syncDir,
|
||||
});
|
||||
}
|
||||
|
||||
export async function calculateSyncFsOnly(dir: string) {
|
||||
return invoke<SyncOp[]>("cmd_sync_calculate_fs", { dir });
|
||||
return platform.rpc<SyncOp[]>("cmd_sync_calculate_fs", { dir });
|
||||
}
|
||||
|
||||
export async function applySync(workspaceId: string, syncDir: string, syncOps: SyncOp[]) {
|
||||
return invoke<void>("cmd_sync_apply", {
|
||||
return platform.rpc<void>("cmd_sync_apply", {
|
||||
workspaceId,
|
||||
syncDir,
|
||||
syncOps: syncOps,
|
||||
@@ -31,13 +30,11 @@ export function watchWorkspaceFiles(
|
||||
callback: (e: WatchEvent) => void,
|
||||
) {
|
||||
console.log("Watching workspace files", workspaceId, syncDir);
|
||||
const channel = new Channel<WatchEvent>();
|
||||
channel.onmessage = callback;
|
||||
const unlistenPromise = invoke<WatchResult>("cmd_sync_watch", {
|
||||
workspaceId,
|
||||
syncDir,
|
||||
channel,
|
||||
});
|
||||
const unlistenPromise = platform.rpcStream<WatchResult, WatchEvent>(
|
||||
"cmd_sync_watch",
|
||||
{ workspaceId, syncDir },
|
||||
callback,
|
||||
);
|
||||
|
||||
void unlistenPromise.then(({ unlistenEvent }) => {
|
||||
addWatchKey(unlistenEvent);
|
||||
@@ -53,7 +50,7 @@ export function watchWorkspaceFiles(
|
||||
}
|
||||
|
||||
function unlistenToWatcher(unlistenEvent: string) {
|
||||
void emit(unlistenEvent).then(() => {
|
||||
void platform.emit(unlistenEvent).then(() => {
|
||||
removeWatchKey(unlistenEvent);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
import { WebsocketConnection } from "@yaakapp-internal/models";
|
||||
|
||||
export function deleteWebsocketConnections(requestId: string) {
|
||||
return invoke("cmd_ws_delete_connections", {
|
||||
return platform.rpc("cmd_ws_delete_connections", {
|
||||
requestId,
|
||||
});
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export function connectWebsocket({
|
||||
environmentId: string | null;
|
||||
cookieJarId: string | null;
|
||||
}) {
|
||||
return invoke("cmd_ws_connect", {
|
||||
return platform.rpc("cmd_ws_connect", {
|
||||
requestId,
|
||||
environmentId,
|
||||
cookieJarId,
|
||||
@@ -24,7 +24,7 @@ export function connectWebsocket({
|
||||
}
|
||||
|
||||
export function closeWebsocket({ connectionId }: { connectionId: string }) {
|
||||
return invoke("cmd_ws_close", {
|
||||
return platform.rpc("cmd_ws_close", {
|
||||
connectionId,
|
||||
});
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export function sendWebsocket({
|
||||
connectionId: string;
|
||||
environmentId: string | null;
|
||||
}) {
|
||||
return invoke("cmd_ws_send", {
|
||||
return platform.rpc("cmd_ws_send", {
|
||||
connectionId,
|
||||
environmentId,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user