Wire up changes
This commit is contained in:
parent
71fe58ffad
commit
dd4e03257d
1 changed files with 19 additions and 8 deletions
|
|
@ -7,10 +7,11 @@ import { SyncView } from "./views/sync-view.js";
|
||||||
|
|
||||||
import { Logger } from "./logger.js";
|
import { Logger } from "./logger.js";
|
||||||
import { SyncEventHandler } from "./events/sync-event-handler.js";
|
import { SyncEventHandler } from "./events/sync-event-handler.js";
|
||||||
import { SyncServer } from "./services/sync_service.js";
|
import { SyncService } from "./services/sync_service.js";
|
||||||
import { Database } from "./database/database.js";
|
import { Database } from "./database/database.js";
|
||||||
import { applyRemoteChangesLocally } from "./apply-remote-changes-locally.js";
|
import { applyRemoteChangesLocally } from "./sync-operations/apply-remote-changes-locally.js";
|
||||||
import { ObsidianFileOperations } from "./file-operations/obsidian-file-operations.js";
|
import { ObsidianFileOperations } from "./file-operations/obsidian-file-operations.js";
|
||||||
|
import { applyLocalChangesRemotely } from "./sync-operations/apply-local-changes-remotely.js";
|
||||||
|
|
||||||
export default class SyncPlugin extends Plugin {
|
export default class SyncPlugin extends Plugin {
|
||||||
private remoteListenerIntervalId: number | null = null;
|
private remoteListenerIntervalId: number | null = null;
|
||||||
|
|
@ -39,7 +40,7 @@ export default class SyncPlugin extends Plugin {
|
||||||
this.saveData.bind(this)
|
this.saveData.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
const syncServer = new SyncServer(database);
|
const syncServer = new SyncService(database);
|
||||||
|
|
||||||
this.addSettingTab(
|
this.addSettingTab(
|
||||||
new SyncSettingsTab(this.app, this, database, syncServer)
|
new SyncSettingsTab(this.app, this, database, syncServer)
|
||||||
|
|
@ -51,7 +52,7 @@ export default class SyncPlugin extends Plugin {
|
||||||
this.operations
|
this.operations
|
||||||
);
|
);
|
||||||
|
|
||||||
this.app.workspace.onLayoutReady(() =>
|
this.app.workspace.onLayoutReady(() => {
|
||||||
[
|
[
|
||||||
this.app.vault.on(
|
this.app.vault.on(
|
||||||
"create",
|
"create",
|
||||||
|
|
@ -69,20 +70,30 @@ export default class SyncPlugin extends Plugin {
|
||||||
"rename",
|
"rename",
|
||||||
eventHandler.onRename.bind(eventHandler)
|
eventHandler.onRename.bind(eventHandler)
|
||||||
),
|
),
|
||||||
].forEach((event) => this.registerEvent(event))
|
].forEach((event) => this.registerEvent(event));
|
||||||
);
|
|
||||||
|
applyLocalChangesRemotely(database, syncServer, this.operations);
|
||||||
|
});
|
||||||
|
|
||||||
this.registerRemoteEventListener(
|
this.registerRemoteEventListener(
|
||||||
database,
|
database,
|
||||||
syncServer,
|
syncServer,
|
||||||
database.getSettings().fetchChangesUpdateIntervalMs
|
database.getSettings().fetchChangesUpdateIntervalMs
|
||||||
);
|
);
|
||||||
database.addOnSettingsChangeHandlers((settings) => {
|
database.addOnSettingsChangeHandlers((settings, oldSettings) => {
|
||||||
this.registerRemoteEventListener(
|
this.registerRemoteEventListener(
|
||||||
database,
|
database,
|
||||||
syncServer,
|
syncServer,
|
||||||
settings.fetchChangesUpdateIntervalMs
|
settings.fetchChangesUpdateIntervalMs
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!oldSettings.isSyncEnabled && settings.isSyncEnabled) {
|
||||||
|
applyLocalChangesRemotely(
|
||||||
|
database,
|
||||||
|
syncServer,
|
||||||
|
this.operations
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.registerView(SyncView.TYPE, (leaf) => new SyncView(leaf));
|
this.registerView(SyncView.TYPE, (leaf) => new SyncView(leaf));
|
||||||
|
|
@ -123,7 +134,7 @@ export default class SyncPlugin extends Plugin {
|
||||||
|
|
||||||
private registerRemoteEventListener(
|
private registerRemoteEventListener(
|
||||||
database: Database,
|
database: Database,
|
||||||
syncServer: SyncServer,
|
syncServer: SyncService,
|
||||||
intervalMs: number
|
intervalMs: number
|
||||||
) {
|
) {
|
||||||
if (this.remoteListenerIntervalId) {
|
if (this.remoteListenerIntervalId) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue