mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 17:48:30 +02:00
Ability to open workspace from directory, WorkspaceMeta, and many sync improvements
This commit is contained in:
@@ -1,48 +1,46 @@
|
||||
import { Channel, invoke } from '@tauri-apps/api/core';
|
||||
import { emit } from '@tauri-apps/api/event';
|
||||
import { Workspace } from '@yaakapp-internal/models';
|
||||
import { useEffect } from 'react';
|
||||
import { SyncOp } from './bindings/sync';
|
||||
import { WatchEvent, WatchResult } from './bindings/watch';
|
||||
|
||||
export async function calculateSync(workspace: Workspace) {
|
||||
if (!workspace.settingSyncDir) return;
|
||||
|
||||
export async function calculateSync(workspaceId: string, syncDir: string) {
|
||||
return invoke<SyncOp[]>('plugin:yaak-sync|calculate', {
|
||||
workspaceId: workspace.id,
|
||||
dir: workspace.settingSyncDir,
|
||||
workspaceId,
|
||||
syncDir,
|
||||
});
|
||||
}
|
||||
|
||||
export async function applySync(workspace: Workspace, syncOps: SyncOp[]) {
|
||||
if (!workspace.settingSyncDir) return;
|
||||
export async function calculateSyncFsOnly(dir: string) {
|
||||
return invoke<SyncOp[]>('plugin:yaak-sync|calculate_fs', { dir });
|
||||
}
|
||||
|
||||
export async function applySync(workspaceId: string, syncDir: string, syncOps: SyncOp[]) {
|
||||
return invoke<void>('plugin:yaak-sync|apply', {
|
||||
workspaceId: workspace.id,
|
||||
dir: workspace.settingSyncDir,
|
||||
workspaceId,
|
||||
syncDir,
|
||||
syncOps: syncOps,
|
||||
});
|
||||
}
|
||||
|
||||
export function useWatchWorkspace(workspace: Workspace | null, callback: (e: WatchEvent) => void) {
|
||||
useEffect(() => {
|
||||
if (workspace == null) return;
|
||||
if (!workspace.settingSyncDir) return;
|
||||
export function watchWorkspaceFiles(
|
||||
workspaceId: string,
|
||||
syncDir: string,
|
||||
callback: (e: WatchEvent) => void,
|
||||
) {
|
||||
const channel = new Channel<WatchEvent>();
|
||||
channel.onmessage = callback;
|
||||
const promise = invoke<WatchResult>('plugin:yaak-sync|watch', {
|
||||
workspaceId,
|
||||
syncDir,
|
||||
channel,
|
||||
});
|
||||
|
||||
const channel = new Channel<WatchEvent>();
|
||||
channel.onmessage = callback;
|
||||
const promise = invoke<WatchResult>('plugin:yaak-sync|watch', {
|
||||
workspaceId: workspace.id,
|
||||
channel,
|
||||
});
|
||||
|
||||
return () => {
|
||||
promise
|
||||
.then(({ unlistenEvent }) => {
|
||||
console.log('Cancelling workspace watch', workspace.id, unlistenEvent);
|
||||
return emit(unlistenEvent);
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
||||
}, [workspace]);
|
||||
return () => {
|
||||
promise
|
||||
.then(({ unlistenEvent }) => {
|
||||
console.log('Cancelling workspace watch', workspaceId, unlistenEvent);
|
||||
return emit(unlistenEvent);
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user