Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

refactor: connectDocToIPC

Lin Onetwoe6abaf7aa469
diff --git a/packages/data-center/src/provider/tauri-ipc/index.ts b/packages/data-center/src/provider/tauri-ipc/index.ts
index 447e758b87..d81722c557 100644
--- a/packages/data-center/src/provider/tauri-ipc/index.ts
+++ b/packages/data-center/src/provider/tauri-ipc/index.ts
@@ -1,15 +1,24 @@
import * as Y from 'yjs';
import assert from 'assert';
-import type { ConfigStore, InitialParams } from '../index.js';
+import type {
+ ConfigStore,
+ DataCenterSignals,
+ InitialParams,
+ Logger,
+} from '../index.js';
import { LocalProvider } from '../local/index.js';
import * as ipcMethods from './ipc/methods.js';
+import { getApis } from 'src/apis/index.js';
+import { token } from 'src/apis/token.js';
+import { IndexedDBProvider } from '../local/indexeddb.js';
export class TauriIPCProvider extends LocalProvider {
static id = 'tauri-ipc';
#ipc = ipcMethods;
async init(params: InitialParams) {
+ // set members like this._workspace in super
super.init(params);
}
@@ -22,6 +31,31 @@ export class TauriIPCProvider extends LocalProvider {
meta: { id },
} = this._workspace;
this.#initDocFromIPC(id, doc);
+ this.#connectDocToIPC(id, doc);
+ this._logger('Local data loaded');
+ }
+
+ async #initDocFromIPC(workspaceID: string, doc: Y.Doc) {
+ this._logger(`Loading ${workspaceID}...`);
+ const updates = await this.#ipc.getYDocument({ id: Number(workspaceID) });
+ if (updates) {
+ await new Promise(resolve => {
+ doc.once('update', resolve);
+ Y.applyUpdate(doc, new Uint8Array(updates.update));
+ });
+ this._logger(`Loaded: ${workspaceID}`);
+
+ // only add to list as online workspace
+ this._signals.listAdd.emit({
+ workspace: workspaceID,
+ provider: this.id,
+ locally: true,
+ });
+ }
+ }
+
+ async #connectDocToIPC(workspaceID: string, doc: Y.Doc) {
+ this._logger(`Connecting yDoc for ${workspaceID}...`);
doc.on(
'update',
async (
@@ -35,7 +69,7 @@ export class TauriIPCProvider extends LocalProvider {
// TODO: update seems too frequent upon each keydown, why no batching?
const success = await this.#ipc.updateYDocument({
update: Array.from(update),
- id: Number(id),
+ id: Number(workspaceID),
});
if (!success) {
throw new Error(
@@ -48,26 +82,14 @@ export class TauriIPCProvider extends LocalProvider {
}
}
);
- this._logger('Local data loaded');
}
- async #initDocFromIPC(workspaceID: string, doc: Y.Doc) {
- this._logger(`Loading ${workspaceID}...`);
- const updates = await this.#ipc.getYDocument({ id: Number(workspaceID) });
- if (updates) {
- await new Promise(resolve => {
- doc.once('update', resolve);
- Y.applyUpdate(doc, new Uint8Array(updates.update));
- });
- this._logger(`Loaded: ${workspaceID}`);
-
- // only add to list as online workspace
- this._signals.listAdd.emit({
- workspace: workspaceID,
- provider: this.id,
- locally: true,
- });
- }
+ static async auth(
+ _config: Readonly<ConfigStore<string>>,
+ _logger: Logger,
+ _signals: DataCenterSignals
+ ) {
+ // no auth on local provider
}
async clear() {