mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-31 21:38:18 +00:00
refactor(syncguard): read host-local preferences
This commit is contained in:
1 parent
9b47310a3c
commit
7c1385fd79
2 files changed
+10
-7
No files matched your search
@@ -3,6 +3,7 @@ import { REMOTE_COUCHDB } from "@vrtmrz/livesync-commonlib/compat/common/types";
|
|||||||
import { isAnyNote } from "@vrtmrz/livesync-commonlib/compat/common/utils";
|
import { isAnyNote } from "@vrtmrz/livesync-commonlib/compat/common/utils";
|
||||||
import { compatGlobal } from "@vrtmrz/livesync-commonlib/compat/common/coreEnvFunctions";
|
import { compatGlobal } from "@vrtmrz/livesync-commonlib/compat/common/coreEnvFunctions";
|
||||||
import type { LiveSyncCore } from "@/main.ts";
|
import type { LiveSyncCore } from "@/main.ts";
|
||||||
|
import { getSyncGuardSettings } from "@/modules/services/ObsidianSettingService.ts";
|
||||||
import { EVENT_SETTING_SAVED, EVENT_VAULT_REFLECTION_FAILED } from "@/common/events";
|
import { EVENT_SETTING_SAVED, EVENT_VAULT_REFLECTION_FAILED } from "@/common/events";
|
||||||
import type { SyncGuardOverlay } from "./SyncGuardOverlay";
|
import type { SyncGuardOverlay } from "./SyncGuardOverlay";
|
||||||
import { SyncGuardState } from "./SyncGuardState";
|
import { SyncGuardState } from "./SyncGuardState";
|
||||||
@@ -63,11 +64,10 @@ export function useSyncGuardFeature(host: LiveSyncCore, createOverlay: SyncGuard
|
|||||||
const isEnabled = () => {
|
const isEnabled = () => {
|
||||||
const settings = services.setting.currentSettings();
|
const settings = services.setting.currentSettings();
|
||||||
return settings.isConfigured && settings.liveSync && settings.remoteType === REMOTE_COUCHDB &&
|
return settings.isConfigured && settings.liveSync && settings.remoteType === REMOTE_COUCHDB &&
|
||||||
settings.syncGuardEnabled;
|
getSyncGuardSettings(services.setting).syncGuardEnabled;
|
||||||
};
|
};
|
||||||
const isCouchDbCatchUp = () => services.replicator.replicationStatics.value.couchDB?.phase === "catch-up";
|
const isCouchDbCatchUp = () => services.replicator.replicationStatics.value.couchDB?.phase === "catch-up";
|
||||||
const beginCatchUp = () => {
|
const beginCatchUp = () => {
|
||||||
const settings = services.setting.currentSettings();
|
|
||||||
if (!isEnabled()) {
|
if (!isEnabled()) {
|
||||||
guard.disable();
|
guard.disable();
|
||||||
return;
|
return;
|
||||||
@@ -89,7 +89,7 @@ export function useSyncGuardFeature(host: LiveSyncCore, createOverlay: SyncGuard
|
|||||||
if (guard.presentation.phase === "observing" && sameCatchUp) {
|
if (guard.presentation.phase === "observing" && sameCatchUp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
guard.resume(Boolean(isEnabled()), settings.syncGuardMinimumFiles);
|
guard.resume(Boolean(isEnabled()), getSyncGuardSettings(services.setting).syncGuardMinimumFiles);
|
||||||
guard.catchUpActivityChanged(isCouchDbCatchUp(), readPendingCount(), Date.now());
|
guard.catchUpActivityChanged(isCouchDbCatchUp(), readPendingCount(), Date.now());
|
||||||
};
|
};
|
||||||
const onReplicationChanged = () => {
|
const onReplicationChanged = () => {
|
||||||
@@ -124,7 +124,7 @@ export function useSyncGuardFeature(host: LiveSyncCore, createOverlay: SyncGuard
|
|||||||
};
|
};
|
||||||
const onSettingsChanged = () => {
|
const onSettingsChanged = () => {
|
||||||
if (!isEnabled()) guard.disable();
|
if (!isEnabled()) guard.disable();
|
||||||
else guard.updateThreshold(services.setting.currentSettings().syncGuardMinimumFiles);
|
else guard.updateThreshold(getSyncGuardSettings(services.setting).syncGuardMinimumFiles);
|
||||||
};
|
};
|
||||||
const onPendingChanged = () => checkForUnlock();
|
const onPendingChanged = () => checkForUnlock();
|
||||||
const onFiniteChanged = () => {
|
const onFiniteChanged = () => {
|
||||||
|
|||||||
@@ -50,17 +50,20 @@ function setup(overrides: { enabled?: boolean; minimumFiles?: number } = {}) {
|
|||||||
const batched = reactiveSource(0);
|
const batched = reactiveSource(0);
|
||||||
const conflictProcessQueueCount = reactiveSource(0);
|
const conflictProcessQueueCount = reactiveSource(0);
|
||||||
const settings = {
|
const settings = {
|
||||||
|
syncGuardEnabled: overrides.enabled ?? true,
|
||||||
|
syncGuardMinimumFiles: overrides.minimumFiles ?? 2,
|
||||||
|
};
|
||||||
|
const sharedSettings = {
|
||||||
isConfigured: true,
|
isConfigured: true,
|
||||||
liveSync: true,
|
liveSync: true,
|
||||||
remoteType: REMOTE_COUCHDB,
|
remoteType: REMOTE_COUCHDB,
|
||||||
syncGuardEnabled: overrides.enabled ?? true,
|
|
||||||
syncGuardMinimumFiles: overrides.minimumFiles ?? 2,
|
|
||||||
};
|
};
|
||||||
const host = {
|
const host = {
|
||||||
services: {
|
services: {
|
||||||
context: createServiceContext(),
|
context: createServiceContext(),
|
||||||
setting: {
|
setting: {
|
||||||
currentSettings: () => settings,
|
currentSettings: () => sharedSettings,
|
||||||
|
syncGuardSettings: settings,
|
||||||
onSettingRealised: { addHandler: (fn: () => Promise<boolean>) => onSettingRealised.push(fn) },
|
onSettingRealised: { addHandler: (fn: () => Promise<boolean>) => onSettingRealised.push(fn) },
|
||||||
},
|
},
|
||||||
replication: {
|
replication: {
|
||||||
|
|||||||
Reference in new issue
Block a user