Skip to content

Commit

Permalink
feat: add option to disable status bar
Browse files Browse the repository at this point in the history
close #70
  • Loading branch information
Vinzent03 committed May 2, 2021
1 parent b9ab82a commit 0ab55d3
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface ObsidianGitSettings {
pullBeforePush: boolean;
disablePopups: boolean;
listChangedFilesInMessageBody: boolean;
showStatusBar: boolean;
}
const DEFAULT_SETTINGS: ObsidianGitSettings = {
commitMessage: "vault backup: {{date}}",
Expand All @@ -32,6 +33,7 @@ const DEFAULT_SETTINGS: ObsidianGitSettings = {
pullBeforePush: true,
disablePopups: false,
listChangedFilesInMessageBody: false,
showStatusBar: true
};

export default class ObsidianGit extends Plugin {
Expand All @@ -48,7 +50,7 @@ export default class ObsidianGit extends Plugin {

setState(state: PluginState) {
this.state = state;
this.statusBar.display();
this.statusBar?.display();
}

async onload() {
Expand Down Expand Up @@ -83,12 +85,14 @@ export default class ObsidianGit extends Plugin {
new ChangedFilesModal(this, status.files).open();
}
});
// init statusBar
let statusBarEl = this.addStatusBarItem();
this.statusBar = new StatusBar(statusBarEl, this);
this.registerInterval(
window.setInterval(() => this.statusBar.display(), 1000)
);
if (this.settings.showStatusBar) {
// init statusBar
let statusBarEl = this.addStatusBarItem();
this.statusBar = new StatusBar(statusBarEl, this);
this.registerInterval(
window.setInterval(() => this.statusBar.display(), 1000)
);
}

this.init();
}
Expand Down Expand Up @@ -373,7 +377,7 @@ export default class ObsidianGit extends Plugin {

// region: displaying / formatting messages
displayMessage(message: string, timeout: number = 4 * 1000): void {
this.statusBar.displayMessage(message.toLowerCase(), timeout);
this.statusBar?.displayMessage(message.toLowerCase(), timeout);

if (!this.settings.disablePopups) {
new Notice(message);
Expand All @@ -384,7 +388,7 @@ export default class ObsidianGit extends Plugin {
displayError(message: string, timeout: number = 0): void {
new Notice(message);
console.log(`git obsidian error: ${message}`);
this.statusBar.displayMessage(message.toLowerCase(), timeout);
this.statusBar?.displayMessage(message.toLowerCase(), timeout);
}

async formatCommitMessage(template: string): Promise<string> {
Expand Down Expand Up @@ -627,6 +631,18 @@ class ObsidianGitSettingsTab extends PluginSettingTab {
plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("Show status bar")
.setDesc("Obsidian must be restarted for the changes to take affect")
.addToggle((toggle) =>
toggle
.setValue(plugin.settings.showStatusBar)
.onChange((value) => {
plugin.settings.showStatusBar = value;
plugin.saveSettings();
})
);
}
}

Expand Down

0 comments on commit 0ab55d3

Please sign in to comment.