mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-30 03:32:26 +08:00
feat(edit-docs): wait for import to finish before starting electron
This commit is contained in:
parent
ac4a8a44d4
commit
4969cf7d5b
@ -20,22 +20,9 @@ async function main() {
|
|||||||
await initializeTranslations();
|
await initializeTranslations();
|
||||||
const zipBuffer = await createImportZip();
|
const zipBuffer = await createImportZip();
|
||||||
await initializeDatabase();
|
await initializeDatabase();
|
||||||
cls.init(() => {
|
await importData(zipBuffer);
|
||||||
importData(zipBuffer);
|
|
||||||
});
|
|
||||||
|
|
||||||
await startElectron();
|
await startElectron();
|
||||||
|
await registerHandlers();
|
||||||
|
|
||||||
const events = (await import("./src/services/events.js")).default;
|
|
||||||
const debouncer = debounce(() => {
|
|
||||||
console.log("Exporting data");
|
|
||||||
exportData();
|
|
||||||
}, 10_000);;
|
|
||||||
events.subscribe(events.ENTITY_CHANGED, async () => {
|
|
||||||
console.log("Got entity changed");
|
|
||||||
debouncer();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initializeDatabase() {
|
async function initializeDatabase() {
|
||||||
@ -48,37 +35,42 @@ async function initializeDatabase() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function importData(input: Buffer) {
|
function importData(input: Buffer) {
|
||||||
const beccaLoader = ((await import("./src/becca/becca_loader.js")).default);
|
return new Promise<void>((resolve, reject) => {
|
||||||
const notes = ((await import("./src/services/notes.js")).default);
|
cls.init(async () => {
|
||||||
beccaLoader.load();
|
const beccaLoader = ((await import("./src/becca/becca_loader.js")).default);
|
||||||
const becca = ((await import("./src/becca/becca.js")).default);
|
const notes = ((await import("./src/services/notes.js")).default);
|
||||||
const utils = ((await import("./src/services/utils.js")).default);
|
beccaLoader.load();
|
||||||
const eraseService = ((await import("./src/services/erase.js")).default);
|
const becca = ((await import("./src/becca/becca.js")).default);
|
||||||
const deleteId = utils.randomString(10);
|
const utils = ((await import("./src/services/utils.js")).default);
|
||||||
|
const eraseService = ((await import("./src/services/erase.js")).default);
|
||||||
|
const deleteId = utils.randomString(10);
|
||||||
|
|
||||||
const existingNote = becca.getNote(NOTE_ID_USER_GUIDE);
|
const existingNote = becca.getNote(NOTE_ID_USER_GUIDE);
|
||||||
if (existingNote) {
|
if (existingNote) {
|
||||||
existingNote.deleteNote(deleteId);
|
existingNote.deleteNote(deleteId);
|
||||||
}
|
}
|
||||||
eraseService.eraseNotesWithDeleteId(deleteId);
|
eraseService.eraseNotesWithDeleteId(deleteId);
|
||||||
|
|
||||||
const { note } = notes.createNewNoteWithTarget("into", "none_root", {
|
const { note } = notes.createNewNoteWithTarget("into", "none_root", {
|
||||||
parentNoteId: "root",
|
parentNoteId: "root",
|
||||||
noteId: NOTE_ID_USER_GUIDE,
|
noteId: NOTE_ID_USER_GUIDE,
|
||||||
title: "User Guide",
|
title: "User Guide",
|
||||||
content: "The sub-children of this note are automatically synced.",
|
content: "The sub-children of this note are automatically synced.",
|
||||||
type: "text"
|
type: "text"
|
||||||
|
});
|
||||||
|
|
||||||
|
const TaskContext = (await import("./src/services/task_context.js")).default;
|
||||||
|
const { importZip } = ((await import("./src/services/import/zip.js")).default);
|
||||||
|
const context = new TaskContext("no-report");
|
||||||
|
await importZip(context, input, note, { preserveIds: true });
|
||||||
|
|
||||||
|
const { runOnDemandChecks } = (await import("./src/services/consistency_checks.js")).default;
|
||||||
|
await runOnDemandChecks(true);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const TaskContext = (await import("./src/services/task_context.js")).default;
|
|
||||||
const { importZip } = ((await import("./src/services/import/zip.js")).default);
|
|
||||||
const context = new TaskContext("no-report");
|
|
||||||
await importZip(context, input, note, { preserveIds: true });
|
|
||||||
|
|
||||||
const { runOnDemandChecks } = (await import("./src/services/consistency_checks.js")).default;
|
|
||||||
await runOnDemandChecks(true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createImportZip() {
|
async function createImportZip() {
|
||||||
@ -162,4 +154,16 @@ async function cleanUpMeta() {
|
|||||||
await fs.writeFile(metaPath, JSON.stringify(meta, null, 4));
|
await fs.writeFile(metaPath, JSON.stringify(meta, null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function registerHandlers() {
|
||||||
|
const events = (await import("./src/services/events.js")).default;
|
||||||
|
const debouncer = debounce(() => {
|
||||||
|
console.log("Exporting data");
|
||||||
|
exportData();
|
||||||
|
}, 10_000);;
|
||||||
|
events.subscribe(events.ENTITY_CHANGED, async (e) => {
|
||||||
|
console.log("Got entity changed ", e);
|
||||||
|
debouncer();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await main();
|
await main();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user