Skip to content

Commit

Permalink
enhance: force save graph after sync
Browse files Browse the repository at this point in the history
  • Loading branch information
debanjandhar12 committed Jan 25, 2024
1 parent d2d2309 commit d723aac
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/syncLogseqToAnki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ export class LogseqToAnkiSync {
// Force persistance of note's logseq block uuid accross re-index by adding id property to block in logseq
if (!note.properties["id"]) {
try {
LogseqProxy.Editor.upsertBlockProperty(note.uuid, "id", note.uuid);
await LogseqProxy.Editor.upsertBlockProperty(note.uuid, "id", note.uuid);
} catch (e) {
console.error(e);
}
}
}

notes = await sortAsync(notes, async (a) => {
return _.get(await LogseqProxy.Editor.getBlock(a.uuid), "id", 0); // Sort by db/id
});
Expand Down Expand Up @@ -217,6 +218,15 @@ export class LogseqToAnkiSync {
await AnkiConnect.invoke("reloadCollection", {});
window.parent.LogseqAnkiSync.dispatchEvent("syncLogseqToAnkiComplete");

// Save logseq graph if any changes were made
if (toCreateNotes.some((note) => !note.properties["id"])) {
try {
await window.parent.logseq.api.force_save_graph();
await new Promise((resolve) => setTimeout(resolve, 2000));
} catch (e) {
}
}

// -- Show Result / Summery --
let summery = `Sync Completed! \n Created Blocks: ${
toCreateNotes.length - failedCreated.size
Expand Down

0 comments on commit d723aac

Please sign in to comment.