Skip to content

Commit

Permalink
feat: Add "Disable notifications" setting + some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
denolehov committed Oct 29, 2020
1 parent 80dbf0f commit ec240a7
Showing 1 changed file with 48 additions and 28 deletions.
76 changes: 48 additions & 28 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,12 @@ export default class ObsidianGit extends Plugin {
if (this.settings.autoPullOnBoot) {
setTimeout(
async () =>
await this.isRepoClean().then(
async (isClean) =>
isClean &&
(await this.pull().then((filesUpdated) => {
this.setState(PluginState.idle);
new Notice(
`Pulled new changes. ${filesUpdated} files updated.`
);
}))
),
await this.pull().then((filesUpdated) => {
this.setState(PluginState.idle);
this.maybeNotice(
`Pulled new changes. ${filesUpdated} files updated.`
);
}),
700
);
}
Expand All @@ -75,20 +71,17 @@ export default class ObsidianGit extends Plugin {
this.addCommand({
id: "pull",
name: "Pull from remote repository",
callback: async () =>
await this.isRepoClean().then(async (isClean) => {
if (isClean) {
let filesUpdated = await this.pull();
if (filesUpdated > 0) {
new Notice(
`Pulled new changes. ${filesUpdated} files updated.`
);
} else {
new Notice("Everything is up-to-date");
}
}
this.setState(PluginState.idle);
}),
callback: async () => {
let filesUpdated = await this.pull();
if (filesUpdated > 0) {
this.maybeNotice(
`Pulled new changes. ${filesUpdated} files updated.`
);
} else {
this.maybeNotice("Everything is up-to-date");
}
this.setState(PluginState.idle);
},
});

this.addCommand({
Expand All @@ -97,13 +90,17 @@ export default class ObsidianGit extends Plugin {
callback: async () =>
await this.isRepoClean().then(async (isClean) => {
if (isClean) {
new Notice("No updates detected. Nothing to push.");
this.maybeNotice(
"No updates detected. Nothing to push."
);
} else {
new Notice("Pushing changes to remote repository..");
this.maybeNotice(
"Pushing changes to remote repository.."
);
await this.add()
.then(async () => await this.commit())
.then(async () => await this.push());
new Notice("Pushed!");
this.maybeNotice("Pushed!");
}
this.setState(PluginState.idle);
}),
Expand Down Expand Up @@ -164,7 +161,7 @@ export default class ObsidianGit extends Plugin {
await this.add()
.then(async () => await this.commit())
.then(async () => await this.push());
new Notice("Pushed changes to remote repository");
this.maybeNotice("Pushed changes to remote repository");
}
this.setState(PluginState.idle);
}),
Expand All @@ -180,12 +177,21 @@ export default class ObsidianGit extends Plugin {

return false;
}

maybeNotice(text: string): void {
if (!this.settings.disablePopups) {
new Notice(text);
} else {
console.log(`git obsidian: ${text}`);
}
}
}

class ObsidianGitSettings {
commitMessage: string = "vault backup";
autoSaveInterval: number = 0;
autoPullOnBoot: boolean = false;
disablePopups: boolean = false;
}

class ObsidianGitSettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -256,6 +262,20 @@ class ObsidianGitSettingsTab extends PluginSettingTab {
plugin.saveData(plugin.settings);
})
);

new Setting(containerEl)
.setName("Disable notifications")
.setDesc(
"Disable notifications for git operations to minimize distraction (refer to status bar for updates)"
)
.addToggle((toggle) =>
toggle
.setValue(plugin.settings.disablePopups)
.onChange((value) => {
plugin.settings.disablePopups = value;
plugin.saveData(plugin.settings);
})
);
}
}

Expand Down

0 comments on commit ec240a7

Please sign in to comment.