mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 19:11:58 +03:00
flush pending autosave before migrating the data folder
save_documents debounces 400ms; migrateDataDir used to fire without waiting for it, so a save still in flight to the old folder could land after migrate had already moved documents.json away, silently recreating it in the abandoned folder and stranding the last edit.
This commit is contained in:
parent
c3bc67bd5b
commit
aa29c12b37
1 changed files with 8 additions and 5 deletions
13
src/main.ts
13
src/main.ts
|
|
@ -425,12 +425,15 @@ function bindDataDirSettings(): void {
|
||||||
const picked = await chooseFolder();
|
const picked = await chooseFolder();
|
||||||
if (!picked || picked === settings.dataDir) return;
|
if (!picked || picked === settings.dataDir) return;
|
||||||
let strategy: "move" | "overwrite" | "use_existing" = "move";
|
let strategy: "move" | "overwrite" | "use_existing" = "move";
|
||||||
if (await dataDirHasDocuments(picked)) {
|
|
||||||
const ans = await askModal(t("folderConflict"), t("useExisting"), t("replaceMine"));
|
|
||||||
if (ans === null) return;
|
|
||||||
strategy = ans === "a" ? "use_existing" : "overwrite";
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
if (await dataDirHasDocuments(picked)) {
|
||||||
|
const ans = await askModal(t("folderConflict"), t("useExisting"), t("replaceMine"));
|
||||||
|
if (ans === null) return;
|
||||||
|
strategy = ans === "a" ? "use_existing" : "overwrite";
|
||||||
|
}
|
||||||
|
// a debounced save still aimed at the old folder would land after the
|
||||||
|
// migration moved documents.json away and silently strand the last edit
|
||||||
|
await flushAppData();
|
||||||
await migrateDataDir(settings.dataDir, picked, strategy);
|
await migrateDataDir(settings.dataDir, picked, strategy);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("migrate failed", e);
|
console.warn("migrate failed", e);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue