mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-07-23 13:02:58 +00:00
Serialise startup compatibility dialogues
This commit is contained in:
+3
-1
@@ -143,6 +143,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
setNoticeClass(Notice);
|
||||
|
||||
const serviceHub = new ObsidianServiceHub(this);
|
||||
let waitForCompatibilityReview = (): Promise<void> => Promise.resolve();
|
||||
|
||||
this.core = new LiveSyncBaseCore(
|
||||
serviceHub,
|
||||
@@ -161,7 +162,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
new ModuleObsidianGlobalHistory(this, core),
|
||||
// new ModuleDev(this, core),
|
||||
new SetupManager(core), // this should be moved to core?
|
||||
new ModuleMigration(core),
|
||||
new ModuleMigration(core, () => waitForCompatibilityReview()),
|
||||
];
|
||||
return extraModules;
|
||||
},
|
||||
@@ -199,6 +200,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
core,
|
||||
createObsidianCompatibilityReviewUi(core.confirm)
|
||||
);
|
||||
waitForCompatibilityReview = () => compatibilityReview.openReview();
|
||||
useReviewHarness(core, this, replicator, compatibilityReview);
|
||||
// p2pReplicatorResult = useP2PReplicator(core, [
|
||||
// VIEW_TYPE_P2P,
|
||||
|
||||
@@ -44,6 +44,13 @@ type ErrorInfo = {
|
||||
const INCOMPLETE_DOCUMENT_NOTICE_GROUP = "startup-integrity-check";
|
||||
|
||||
export class ModuleMigration extends AbstractModule<LiveSyncCore> {
|
||||
constructor(
|
||||
core: LiveSyncCore,
|
||||
private readonly waitForCompatibilityReview: () => Promise<void> = () => Promise.resolve()
|
||||
) {
|
||||
super(core);
|
||||
}
|
||||
|
||||
async migrateUsingDoctor(skipRebuild: boolean = false, activateReason = "updated", forceRescan = false) {
|
||||
const { shouldRebuild, shouldRebuildLocal, isModified, settings } = await performDoctorConsultation(
|
||||
{
|
||||
@@ -354,6 +361,7 @@ export class ModuleMigration extends AbstractModule<LiveSyncCore> {
|
||||
reportDatabaseNotReady: () => this._log($msg("moduleMigration.logLocalDatabaseNotReady"), LOG_LEVEL_NOTICE),
|
||||
hasCompromisedChunks: () => this.hasCompromisedChunks(),
|
||||
hasIncompleteDocuments: () => this.hasIncompleteDocs(),
|
||||
waitForCompatibilityReview: () => this.waitForCompatibilityReview(),
|
||||
runDoctor: () => this.migrateUsingDoctor(false),
|
||||
migrateBulkSend: () => this.migrateDisableBulkSend(),
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ export interface ConfiguredStartupLifecycleRuntime {
|
||||
reportDatabaseNotReady(): void;
|
||||
hasCompromisedChunks(): Promise<boolean>;
|
||||
hasIncompleteDocuments(): Promise<boolean>;
|
||||
waitForCompatibilityReview(): Promise<void>;
|
||||
runDoctor(): Promise<boolean>;
|
||||
migrateBulkSend(): Promise<void>;
|
||||
}
|
||||
@@ -33,6 +34,7 @@ export async function runConfiguredStartupLifecycle(runtime: ConfiguredStartupLi
|
||||
}
|
||||
if (!(await runtime.hasCompromisedChunks())) return false;
|
||||
if (!(await runtime.hasIncompleteDocuments())) return false;
|
||||
await runtime.waitForCompatibilityReview();
|
||||
if (!(await runtime.runDoctor())) return false;
|
||||
await runtime.migrateBulkSend();
|
||||
return true;
|
||||
|
||||
@@ -19,6 +19,7 @@ function createRuntime(): ConfiguredStartupLifecycleRuntime & { events: string[]
|
||||
events.push("incomplete-documents");
|
||||
return true;
|
||||
}),
|
||||
waitForCompatibilityReview: vi.fn(async () => {}),
|
||||
runDoctor: vi.fn(async () => {
|
||||
events.push("doctor");
|
||||
return true;
|
||||
@@ -38,6 +39,25 @@ describe("runConfiguredStartupLifecycle", () => {
|
||||
expect(runtime.events).toEqual(["compromised-chunks", "incomplete-documents", "doctor", "bulk-send"]);
|
||||
});
|
||||
|
||||
it("keeps Config Doctor behind the initial compatibility review", async () => {
|
||||
const runtime = createRuntime();
|
||||
Object.assign(runtime, {
|
||||
waitForCompatibilityReview: vi.fn(async () => {
|
||||
runtime.events.push("compatibility-review");
|
||||
}),
|
||||
});
|
||||
|
||||
await expect(runConfiguredStartupLifecycle(runtime)).resolves.toBe(true);
|
||||
|
||||
expect(runtime.events).toEqual([
|
||||
"compromised-chunks",
|
||||
"incomplete-documents",
|
||||
"compatibility-review",
|
||||
"doctor",
|
||||
"bulk-send",
|
||||
]);
|
||||
});
|
||||
|
||||
it("stops before onboarding or checks when the database is unavailable", async () => {
|
||||
const runtime = createRuntime();
|
||||
runtime.databaseReady = false;
|
||||
|
||||
Reference in New Issue
Block a user