### Fixed

- Fixed an issue with automatic synchronisation starting (#702).
This commit is contained in:
vorotamoroz
2025-08-29 11:46:11 +01:00
parent fec203a751
commit a2cc093a9e
3 changed files with 37 additions and 13 deletions

View File

@@ -582,6 +582,11 @@ export default class ObsidianLiveSyncPlugin
$everyBeforeReplicate(showMessage: boolean): Promise<boolean> { $everyBeforeReplicate(showMessage: boolean): Promise<boolean> {
return InterceptiveEvery; return InterceptiveEvery;
} }
$$canReplicate(showMessage: boolean = false): Promise<boolean> {
throwShouldBeOverridden();
}
$$replicate(showMessage: boolean = false): Promise<boolean | void> { $$replicate(showMessage: boolean = false): Promise<boolean | void> {
throwShouldBeOverridden(); throwShouldBeOverridden();
} }

View File

@@ -173,17 +173,23 @@ Even if you choose to clean up, you will see this option again if you exit Obsid
} }
}); });
} }
async $$_replicate(showMessage: boolean = false): Promise<boolean | void> {
//--? async $$canReplicate(showMessage: boolean = false): Promise<boolean> {
if (!this.core.$$isReady()) return; if (!this.core.$$isReady()) {
Logger(`Not ready`);
return false;
}
if (isLockAcquired("cleanup")) { if (isLockAcquired("cleanup")) {
Logger($msg("Replicator.Message.Cleaned"), LOG_LEVEL_NOTICE); Logger($msg("Replicator.Message.Cleaned"), LOG_LEVEL_NOTICE);
return; return false;
} }
if (this.settings.versionUpFlash != "") { if (this.settings.versionUpFlash != "") {
Logger($msg("Replicator.Message.VersionUpFlash"), LOG_LEVEL_NOTICE); Logger($msg("Replicator.Message.VersionUpFlash"), LOG_LEVEL_NOTICE);
return; return false;
} }
if (!(await this.core.$everyCommitPendingFileEvent())) { if (!(await this.core.$everyCommitPendingFileEvent())) {
Logger($msg("Replicator.Message.Pending"), LOG_LEVEL_NOTICE); Logger($msg("Replicator.Message.Pending"), LOG_LEVEL_NOTICE);
return false; return false;
@@ -197,6 +203,12 @@ Even if you choose to clean up, you will see this option again if you exit Obsid
Logger($msg("Replicator.Message.SomeModuleFailed"), LOG_LEVEL_NOTICE); Logger($msg("Replicator.Message.SomeModuleFailed"), LOG_LEVEL_NOTICE);
return false; return false;
} }
return true;
}
async $$_replicate(showMessage: boolean = false): Promise<boolean | void> {
const checkBeforeReplicate = await this.$$canReplicate(showMessage);
if (!checkBeforeReplicate) return false;
//<-- Here could be an module. //<-- Here could be an module.
const ret = await this.core.replicator.openReplication(this.settings, false, showMessage, false); const ret = await this.core.replicator.openReplication(this.settings, false, showMessage, false);

View File

@@ -15,15 +15,22 @@ export class ModuleReplicatorCouchDB extends AbstractModule implements ICoreModu
return Promise.resolve(new LiveSyncCouchDBReplicator(this.core)); return Promise.resolve(new LiveSyncCouchDBReplicator(this.core));
} }
$everyAfterResumeProcess(): Promise<boolean> { $everyAfterResumeProcess(): Promise<boolean> {
if (!this.core.$$isSuspended) return Promise.resolve(true);
if (!this.core.$$isReady) return Promise.resolve(true);
if (this.settings.remoteType != REMOTE_MINIO && this.settings.remoteType != REMOTE_P2P) { if (this.settings.remoteType != REMOTE_MINIO && this.settings.remoteType != REMOTE_P2P) {
// If LiveSync enabled, open replication const LiveSyncEnabled = this.settings.liveSync;
if (this.settings.liveSync) { const continuous = LiveSyncEnabled;
fireAndForget(() => this.core.$$replicate(false)); const eventualOnStart = !LiveSyncEnabled && this.settings.syncOnStart;
}
// If sync on start enabled, open replication // If enabled LiveSync or on start, open replication
if (!this.settings.liveSync && this.settings.syncOnStart) { if (LiveSyncEnabled || eventualOnStart) {
// Possibly ok as if only share the result // And note that we do not open the conflict detection dialogue directly during this process.
fireAndForget(() => this.core.$$replicate(false)); // This should be raised explicitly if needed.
fireAndForget(async () => {
const canReplicate = await this.core.$$canReplicate(false);
if (!canReplicate) return;
void this.core.replicator.openReplication(this.settings, continuous, false, false);
});
} }
} }