feat(settings): keep SyncGuard preferences in device-local storage

This commit is contained in:
Artem Ovchinnikov committed 2026-10-29 13:05:28 +03:00
1 parent 47828e934b
commit 9b47310a3c
6 files changed
+309 -36

No files matched your search

@@ -1,25 +1,50 @@
export {
AllSettingDefault,
OnDialogSettingsDefault,
SettingInformation,
} from "@vrtmrz/livesync-commonlib/compat/common/settingConstants";
export type {
AllSettings,
AllSettingItemKey,
AllStringItemKey,
AllNumericItemKey,
AllBooleanItemKey,
OnDialogSettings,
ValueOf,
} from "@vrtmrz/livesync-commonlib/compat/common/settingConstants";
export { OnDialogSettingsDefault } from "@vrtmrz/livesync-commonlib/compat/common/settingConstants";
export type { OnDialogSettings } from "@vrtmrz/livesync-commonlib/compat/common/settingConstants";
import {
AllSettingDefault as CommonlibAllSettingDefault,
SettingInformation as CommonlibSettingInformation,
getConfig as getCommonlibConfig,
getConfName as getCommonlibConfName,
type AllSettingItemKey,
type AllSettings as CommonlibAllSettings,
type AllSettingItemKey as CommonlibAllSettingItemKey,
type AllStringItemKey as CommonlibAllStringItemKey,
type AllNumericItemKey as CommonlibAllNumericItemKey,
type AllBooleanItemKey as CommonlibAllBooleanItemKey,
} from "@vrtmrz/livesync-commonlib/compat/common/settingConstants";
import type { ConfigurationItem } from "@vrtmrz/livesync-commonlib/compat/common/types";
import type { MessageTranslator } from "@vrtmrz/livesync-commonlib/context";
import { translateLiveSyncMessage } from "@/common/translation";
import {
DEFAULT_SYNC_GUARD_SETTINGS,
isSyncGuardSettingKey,
type SyncGuardSettingKey,
type SyncGuardSettings,
} from "@/modules/services/ObsidianSettingService";
export type AllSettings = Omit<CommonlibAllSettings, SyncGuardSettingKey> & SyncGuardSettings;
export type AllStringItemKey = CommonlibAllStringItemKey;
export type AllNumericItemKey = Exclude<CommonlibAllNumericItemKey, SyncGuardSettingKey> | "syncGuardMinimumFiles";
export type AllBooleanItemKey = Exclude<CommonlibAllBooleanItemKey, SyncGuardSettingKey> | "syncGuardEnabled";
export type AllSettingItemKey = Exclude<CommonlibAllSettingItemKey, SyncGuardSettingKey> | SyncGuardSettingKey;
export type ValueOf<T extends AllSettingItemKey> = AllSettings[T];
const syncGuardSettingInformation: Record<SyncGuardSettingKey, ConfigurationItem> = {
syncGuardEnabled: {
name: "Enable SyncGuard",
desc: "Enable device-local SyncGuard protection during synchronisation.",
},
syncGuardMinimumFiles: {
name: "SyncGuard minimum files",
desc: "Minimum number of Vault files required for SyncGuard protection to apply.",
},
};
export const AllSettingDefault = { ...CommonlibAllSettingDefault, ...DEFAULT_SYNC_GUARD_SETTINGS };
export const SettingInformation: Partial<Record<AllSettingItemKey, ConfigurationItem>> = {
...CommonlibSettingInformation,
...syncGuardSettingInformation,
};
// Commonlib defaults `translate` to its English-only translator, so every caller which omits
// it silently renders English regardless of `displayLanguage`. Default it to the LiveSync
@@ -28,10 +53,12 @@ import { translateLiveSyncMessage } from "@/common/translation";
/** `getConfig` with the LiveSync catalogue applied by default. */
export function getConfig(key: AllSettingItemKey, translate: MessageTranslator = translateLiveSyncMessage) {
return getCommonlibConfig(key, translate);
if (isSyncGuardSettingKey(key)) return syncGuardSettingInformation[key];
return getCommonlibConfig(key as CommonlibAllSettingItemKey, translate);
}
/** `getConfName` with the LiveSync catalogue applied by default. See `getConfig`. */
export function getConfName(key: AllSettingItemKey, translate: MessageTranslator = translateLiveSyncMessage) {
return getCommonlibConfName(key, translate);
if (isSyncGuardSettingKey(key)) return syncGuardSettingInformation[key].name;
return getCommonlibConfName(key as CommonlibAllSettingItemKey, translate);
}