Skip to content

Commit

Permalink
fix: storing lastAutos in a file caused many problems
Browse files Browse the repository at this point in the history
close #90 #78
  • Loading branch information
Vinzent03 committed Jul 13, 2021
1 parent 68b42d4 commit 2812d94
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ export default class ObsidianGit extends Plugin {
window.setInterval(() => this.statusBar.display(), 1000)
);
}
if (this.app.workspace.layoutReady) {
this.init();
} else {
this.app.workspace.on("layout-ready", () => this.init());
}
this.app.workspace.onLayoutReady(() => this.init());

}

async onunload() {
Expand All @@ -113,31 +110,17 @@ export default class ObsidianGit extends Plugin {
}

async saveLastAuto(date: Date, mode: "backup" | "pull") {
const fileName = ".obsidian-git-data";
let data = "\n";
if (await this.app.vault.adapter.exists(fileName)) {
data = await this.app.vault.adapter.read(fileName);
}
const lines = data.split("\n");
if (mode === "backup") {
lines[0] = date.toString();
window.localStorage.setItem(this.manifest.id + ":lastAutoBackup", date.toString());
} else if (mode === "pull") {
lines[1] = date.toString();
window.localStorage.setItem(this.manifest.id + ":lastAutoPull", date.toString());
}

await this.app.vault.adapter.write(fileName, lines.join("\n"));
}

async loadLastAuto(): Promise<{ "backup": Date, "pull": Date; }> {
const fileName = ".obsidian-git-data";
let data = "\n";
if (await this.app.vault.adapter.exists(fileName)) {
data = await this.app.vault.adapter.read(fileName);
}
const lines = data.split("\n");
return {
"backup": new Date(lines[0]),
"pull": new Date(lines[1])
"backup": new Date(window.localStorage.getItem(this.manifest.id + ":lastAutoBackup") ?? ""),
"pull": new Date(window.localStorage.getItem(this.manifest.id + ":lastAutoPull") ?? "")
};
}

Expand Down

0 comments on commit 2812d94

Please sign in to comment.