diff --git a/src/main.ts b/src/main.ts index 22f0212..c10d284 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,11 +22,11 @@ export default class BetterWordCount extends Plugin { async onload() { // Settings Store - this.register( - settingsStore.subscribe((value) => { - this.settings = value; - }) - ); + // this.register( + // settingsStore.subscribe((value) => { + // this.settings = value; + // }) + // ); // Handle Settings this.settings = Object.assign(DEFAULT_SETTINGS, await this.loadData()); this.addSettingTab(new BetterWordCountSettingsTab(this.app, this)); @@ -51,14 +51,20 @@ export default class BetterWordCount extends Plugin { this.app.workspace.on( "active-leaf-change", async (leaf: WorkspaceLeaf) => { - await this.statsManager.recalcTotals(); this.giveEditorPlugin(leaf); + if (leaf.view.getViewType() !== "markdown") { + this.statusBar.updateAltBar(); + } + + if (!this.settings.collectStats) return; + await this.statsManager.recalcTotals(); } ) ); this.registerEvent( this.app.vault.on("delete", async () => { + if (!this.settings.collectStats) return; await this.statsManager.recalcTotals(); }) ); diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index daf2a81..c0f6d10 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -1,44 +1,74 @@ -export enum Counter { - fileWords, - fileChars, - fileSentences, - totalWords, - totalChars, - totalSentences, - totalNotes, +export enum MetricCounter { + words, + characters, + sentences, + files, +} + +export enum MetricType { + file, + daily, + total, + folder, +} + +export interface Metric { + type: MetricType; + counter: MetricCounter; + folder?: string; } export interface StatusBarItem { prefix: string; suffix: string; - count: Counter; + metric: Metric; } export const BLANK_SB_ITEM: StatusBarItem = { prefix: "", suffix: "", - count: null, + metric: { + type: null, + counter: null, + }, }; export interface BetterWordCountSettings { statusBar: StatusBarItem[]; + altBar: StatusBarItem[]; countComments: boolean; collectStats: boolean; } -export const DEFAULT_SETTINGS: BetterWordCountSettings = Object.freeze({ +export const DEFAULT_SETTINGS: BetterWordCountSettings = { statusBar: [ { prefix: "", suffix: " words", - count: Counter.fileWords, + metric: { + type: MetricType.file, + counter: MetricCounter.words, + }, }, { prefix: " ", suffix: " characters", - count: Counter.fileChars, + metric: { + type: MetricType.file, + counter: MetricCounter.characters, + }, + }, + ], + altBar: [ + { + prefix: "", + suffix: "files", + metric: { + type: MetricType.total, + counter: MetricCounter.files, + }, }, ], countComments: false, collectStats: false, -}); +}; diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts index 98a2e68..0e55833 100644 --- a/src/settings/SettingsTab.ts +++ b/src/settings/SettingsTab.ts @@ -18,7 +18,7 @@ export default class BetterWordCountSettingsTab extends PluginSettingTab { new Setting(containerEl) .setName("Collect Statistics") .setDesc( - "Reload Required for change to take effect. Turn on to start collecting daily statistics of your writing. Stored in the .vault-stats file in the root of your vault. This is required for counts of the day." + "Reload Required for change to take effect. Turn on to start collecting daily statistics of your writing. Stored in the vault-stats.json file in the .obsidian of your vault. This is required for counts of the day as well as total counts." ) .addToggle((cb: ToggleComponent) => { cb.setValue(this.plugin.settings.collectStats); @@ -39,13 +39,6 @@ export default class BetterWordCountSettingsTab extends PluginSettingTab { }); // Status Bar Settings - containerEl - .createEl("h4", { text: "Status Bar Settings" }) - .addClass("bwc-status-bar-settings-title"); - containerEl.createEl("p", { - text: "Here you can customize what statistics are displayed on the status bar.", - }); - addStatusBarSettings(this.plugin, containerEl); } } diff --git a/src/settings/StatusBarSettings.svelte b/src/settings/StatusBarSettings.svelte index 9ca823b..9e2843a 100644 --- a/src/settings/StatusBarSettings.svelte +++ b/src/settings/StatusBarSettings.svelte @@ -1,38 +1,50 @@
Here you can customize what statistics are displayed on the status bar when editing a markdown note.