Skip to content

Commit

Permalink
fix: fix undefined backup settings and rearrange settings a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
denolehov committed Oct 30, 2020
1 parent 26cd1e3 commit 68f8b84
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class ObsidianGit extends Plugin {
);
}

if (this.settings.backupInterval > 0) {
if (this.settings.autoSaveInterval > 0) {
this.enableAutoBackup();
}

Expand Down Expand Up @@ -175,7 +175,7 @@ export default class ObsidianGit extends Plugin {
}

enableAutoBackup() {
let minutes = this.settings.backupInterval;
let minutes = this.settings.autoSaveInterval;
this.intervalID = window.setInterval(
async () =>
await this.isRepoClean().then(async (isClean) => {
Expand Down Expand Up @@ -212,7 +212,7 @@ export default class ObsidianGit extends Plugin {

class ObsidianGitSettings {
commitMessage: string = "vault backup: {{date}}";
backupInterval: number = 0;
autoSaveInterval: number = 0;
autoPullOnBoot: boolean = false;
disablePopups: boolean = false;
currentBranch: string;
Expand All @@ -227,6 +227,38 @@ class ObsidianGitSettingsTab extends PluginSettingTab {
containerEl.empty();
containerEl.createEl("h2", { text: "Git Backup settings" });

new Setting(containerEl)
.setName("Vault backup interval (minutes)")
.setDesc(
"Commit and push changes every X minutes. To disable automatic backup, specify negative value or zero (default)"
)
.addText((text) =>
text
.setValue(String(plugin.settings.autoSaveInterval))
.onChange((value) => {
if (!isNaN(Number(value))) {
plugin.settings.autoSaveInterval = Number(value);
plugin.saveData(plugin.settings);

if (plugin.settings.autoSaveInterval > 0) {
plugin.disableAutoBackup(); // call clearInterval() before setting up a new one
plugin.enableAutoBackup();
new Notice(
`Automatic backup enabled! Every ${plugin.settings.autoSaveInterval} minutes.`
);
} else if (
plugin.settings.autoSaveInterval <= 0 &&
plugin.intervalID
) {
plugin.disableAutoBackup() &&
new Notice("Automatic backup disabled!");
}
} else {
new Notice("Please specify a valid number.");
}
})
);

new Setting(containerEl)
.setName("Commit message")
.setDesc("Specify a custom commit message")
Expand Down Expand Up @@ -272,38 +304,6 @@ class ObsidianGitSettingsTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName("Vault backup interval (minutes)")
.setDesc(
"Commit and push changes every X minutes. To disable automatic backup, specify negative value or zero (default)"
)
.addText((text) =>
text
.setValue(String(plugin.settings.backupInterval))
.onChange((value) => {
if (!isNaN(Number(value))) {
plugin.settings.backupInterval = Number(value);
plugin.saveData(plugin.settings);

if (plugin.settings.backupInterval > 0) {
plugin.disableAutoBackup(); // call clearInterval() before setting up a new one
plugin.enableAutoBackup();
new Notice(
`Automatic backup enabled! Every ${plugin.settings.backupInterval} minutes.`
);
} else if (
plugin.settings.backupInterval <= 0 &&
plugin.intervalID
) {
plugin.disableAutoBackup() &&
new Notice("Automatic backup disabled!");
}
} else {
new Notice("Please specify a valid number.");
}
})
);

new Setting(containerEl)
.setName("Pull updates on startup")
.setDesc("Automatically pull updates when Obsidian starts")
Expand Down

0 comments on commit 68f8b84

Please sign in to comment.