mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-26 13:24:48 +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
+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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user