mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-07-05 12:25:22 +00:00
7e59010824
Local database maintenance actions require local chunk revisions and fully replicated chunks, but previously failed with a notice when those settings were not already configured. This adds a small prerequisite confirmation helper for the maintenance commands. When required settings are missing, the user can apply them and continue from the action they already started, or cancel without changing settings. Covers both required maintenance settings: - Compute revisions for chunks enabled - Fetch chunks on demand disabled Fixes #980
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import type { ObsidianLiveSyncSettings } from "@lib/common/types";
|
|
|
|
type MaintenancePrerequisiteSettings = Pick<
|
|
ObsidianLiveSyncSettings,
|
|
"doNotUseFixedRevisionForChunks" | "readChunksOnline"
|
|
>;
|
|
|
|
type MaintenancePrerequisiteOptions = {
|
|
operationName: string;
|
|
settings: MaintenancePrerequisiteSettings;
|
|
askSelectStringDialogue: (
|
|
message: string,
|
|
buttons: readonly ["Apply and continue", "Cancel"],
|
|
options: { title: string; defaultAction: "Cancel" }
|
|
) => Promise<"Apply and continue" | "Cancel" | false | undefined>;
|
|
applyPartial: (settings: Partial<ObsidianLiveSyncSettings>, saveImmediately?: boolean) => Promise<void>;
|
|
};
|
|
|
|
export async function ensureLocalDatabaseMaintenancePrerequisites({
|
|
operationName,
|
|
settings,
|
|
askSelectStringDialogue,
|
|
applyPartial,
|
|
}: MaintenancePrerequisiteOptions): Promise<boolean> {
|
|
const requiredSettings = {
|
|
doNotUseFixedRevisionForChunks: true,
|
|
readChunksOnline: false,
|
|
} satisfies MaintenancePrerequisiteSettings;
|
|
|
|
const missing = [
|
|
...(settings.doNotUseFixedRevisionForChunks ? [] : ["- Compute revisions for chunks: On (currently Off)"]),
|
|
...(settings.readChunksOnline ? ["- Fetch chunks on demand: Off (currently On)"] : []),
|
|
];
|
|
|
|
if (missing.length == 0) return true;
|
|
|
|
const APPLY = "Apply and continue";
|
|
const CANCEL = "Cancel";
|
|
const result = await askSelectStringDialogue(
|
|
`${operationName} requires the following settings:\n\n${missing.join(
|
|
"\n"
|
|
)}\n\nApply these settings and continue?`,
|
|
[APPLY, CANCEL],
|
|
{
|
|
title: `${operationName} prerequisites`,
|
|
defaultAction: CANCEL,
|
|
}
|
|
);
|
|
|
|
if (result !== APPLY) return false;
|
|
|
|
await applyPartial(requiredSettings, true);
|
|
return true;
|
|
}
|