mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 08:36:22 +08:00
refactor: move ipc method and types to data-center folder
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||
import * as Y from 'yjs';
|
||||
import { Observable } from 'lib0/observable';
|
||||
import { DocProvider } from '@blocksuite/store';
|
||||
import type { Awareness } from 'y-protocols/awareness';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { updateYDocument } from './methods';
|
||||
|
||||
export class TauriIPCProvider
|
||||
extends Observable<string>
|
||||
implements DocProvider
|
||||
{
|
||||
#yDocument: Y.Doc;
|
||||
constructor(
|
||||
room: string,
|
||||
yDocument: Y.Doc,
|
||||
options?: { awareness?: Awareness }
|
||||
) {
|
||||
super();
|
||||
this.#yDocument = yDocument;
|
||||
this.#yDocument.on(
|
||||
'updateV2',
|
||||
async (
|
||||
update: Uint8Array,
|
||||
origin: any,
|
||||
_yDocument: Y.Doc,
|
||||
_transaction: Y.Transaction
|
||||
) => {
|
||||
try {
|
||||
// TODO: need handle potential data race when update is frequent?
|
||||
// TODO: update seems too frequent upon each keydown, why no batching?
|
||||
const success = await updateYDocument({
|
||||
update: Array.from(update),
|
||||
room,
|
||||
});
|
||||
} catch (error) {
|
||||
// TODO: write error log to disk, and add button to open them in settings panel
|
||||
console.error("#yDocument.on('updateV2'", error);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
connect() {}
|
||||
|
||||
destroy() {}
|
||||
disconnect() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
async clearData() {}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { YDocumentUpdate } from '../types/ipc/document';
|
||||
import { CreateWorkspace } from '../types/ipc/workspace';
|
||||
import { GetBlob, PutBlob } from '../types/ipc/blob';
|
||||
|
||||
export const updateYDocument = async (parameters: YDocumentUpdate) =>
|
||||
await invoke<boolean>('update_y_document', {
|
||||
parameters,
|
||||
});
|
||||
|
||||
export const createWorkspace = async (parameters: CreateWorkspace) =>
|
||||
await invoke<boolean>('create_workspace', {
|
||||
parameters,
|
||||
});
|
||||
|
||||
export const putBlob = async (parameters: PutBlob) =>
|
||||
await invoke<string>('put_blob', {
|
||||
parameters,
|
||||
});
|
||||
|
||||
export const getBlob = async (parameters: GetBlob) =>
|
||||
await invoke<number[]>('get_blob', {
|
||||
parameters,
|
||||
});
|
||||
@@ -14,12 +14,12 @@ export type IBlobParameters =
|
||||
};
|
||||
|
||||
export interface PutBlob {
|
||||
[k: string]: unknown;
|
||||
blob: number[];
|
||||
workspace_id: number;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface GetBlob {
|
||||
[k: string]: unknown;
|
||||
id: string;
|
||||
workspace_id: number;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
export interface YDocumentUpdate {
|
||||
[k: string]: unknown;
|
||||
room: string;
|
||||
update: number[];
|
||||
[k: string]: unknown;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
*/
|
||||
|
||||
export interface CreateWorkspace {
|
||||
[k: string]: unknown;
|
||||
avatar: string;
|
||||
id: number;
|
||||
name: string;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user