mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-11-03 23:08:18 +00:00
Reserve setup initialisation before enabling settings
This commit is contained in:
1 parent
7faf51a6c4
commit
40a4987b0b
6 files changed
+222
-16
No files matched your search
@@ -0,0 +1,35 @@
|
||||
export type SetupInitialisationMode = "fetch" | "rebuild";
|
||||
|
||||
export interface SetupInitialisationScheduler {
|
||||
scheduleFetch(prepareBeforeRestart?: () => Promise<void>): Promise<boolean>;
|
||||
scheduleRebuild(prepareBeforeRestart?: () => Promise<void>): Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserves the next-start initialisation operation before enabling settings.
|
||||
* The scheduler owns suspension, rollback, and restart ordering.
|
||||
*/
|
||||
export function applySettingsWithScheduledInitialisation(
|
||||
scheduler: SetupInitialisationScheduler,
|
||||
mode: SetupInitialisationMode,
|
||||
applySettings: () => Promise<void>
|
||||
): Promise<boolean> {
|
||||
return mode === "fetch" ? scheduler.scheduleFetch(applySettings) : scheduler.scheduleRebuild(applySettings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses Fetch only for the transition from an unconfigured device to an
|
||||
* explicitly configured existing device. Ordinary edits apply immediately.
|
||||
*/
|
||||
export async function applySettingsAndFetchOnActivation(
|
||||
scheduler: SetupInitialisationScheduler,
|
||||
wasConfigured: boolean | undefined,
|
||||
willBeConfigured: boolean | undefined,
|
||||
applySettings: () => Promise<void>
|
||||
): Promise<boolean> {
|
||||
if (!wasConfigured && willBeConfigured) {
|
||||
return await applySettingsWithScheduledInitialisation(scheduler, "fetch", applySettings);
|
||||
}
|
||||
await applySettings();
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user