Fixed
-  No longer unnecessary acknowledgements are sent when starting peer-to-peer synchronisation.

Refactored
- Platform impedance-matching-layer has been improved.
- Some UIs have been get isomorphic among Obsidian and web applications (for `webpeer`).
This commit is contained in:
vorotamoroz
2025-02-14 11:15:22 +00:00
parent 4e8243b3d5
commit cc29b4058d
9 changed files with 266 additions and 195 deletions

View File

@@ -20,6 +20,7 @@ import {
EVENT_DATABASE_REBUILT,
EVENT_PLUGIN_UNLOADED,
EVENT_REQUEST_OPEN_P2P,
EVENT_SETTING_SAVED,
eventHub,
} from "../../common/events.ts";
import {
@@ -31,8 +32,9 @@ import {
import type { LiveSyncAbstractReplicator } from "../../lib/src/replication/LiveSyncAbstractReplicator.ts";
import { Logger } from "octagonal-wheels/common/logger";
import { $msg } from "../../lib/src/common/i18n.ts";
import type { CommandShim } from "./P2PReplicator/P2PReplicatorPaneCommon.ts";
export class P2PReplicator extends LiveSyncCommands implements IObsidianModule {
export class P2PReplicator extends LiveSyncCommands implements IObsidianModule, CommandShim {
$anyNewReplicator(settingOverride: Partial<RemoteDBSettings> = {}): Promise<LiveSyncAbstractReplicator> {
const settings = { ...this.settings, ...settingOverride };
if (settings.remoteType == REMOTE_P2P) {
@@ -66,6 +68,9 @@ export class P2PReplicator extends LiveSyncCommands implements IObsidianModule {
eventHub.onEvent(EVENT_PLUGIN_UNLOADED, () => {
void this.close();
});
eventHub.onEvent(EVENT_SETTING_SAVED, async () => {
await this.initialiseP2PReplicator();
});
// throw new Error("Method not implemented.");
}
async $everyOnInitializeDatabase(): Promise<boolean> {
@@ -154,8 +159,13 @@ export class P2PReplicator extends LiveSyncCommands implements IObsidianModule {
if (!this._replicatorInstance) {
await this.initialiseP2PReplicator();
if (!this.settings.P2P_AutoStart) {
// While auto start is enabled, we don't need to open the connection (Literally, it's already opened automatically)
await this._replicatorInstance!.open();
}
} else {
await this._replicatorInstance?.open();
}
await this._replicatorInstance?.open();
}
async close() {
await this._replicatorInstance?.close();
@@ -208,7 +218,9 @@ export class P2PReplicator extends LiveSyncCommands implements IObsidianModule {
simpleStore: getPlugin().$$getSimpleStore("p2p-sync"),
};
this._replicatorInstance = new TrysteroReplicator(env);
// p2p_replicator.set(this.p2pReplicator);
if (this.settings.P2P_AutoStart && this.settings.P2P_Enabled) {
await this.open();
}
return this._replicatorInstance;
} catch (e) {
this._log(
@@ -219,4 +231,10 @@ export class P2PReplicator extends LiveSyncCommands implements IObsidianModule {
throw e;
}
}
enableBroadcastCastings() {
return this?._replicatorInstance?.enableBroadcastChanges();
}
disableBroadcastCastings() {
return this?._replicatorInstance?.disableBroadcastChanges();
}
}