diff --git a/src/data/collector.ts b/src/data/collector.ts index 195d45f..43e1c02 100644 --- a/src/data/collector.ts +++ b/src/data/collector.ts @@ -1,14 +1,17 @@ import moment from "moment"; import type { MetadataCache, TFile, Vault } from "obsidian"; +import type { BetterWordCountSettings } from "src/settings/settings"; import { getCharacterCount, getSentenceCount, getWordCount } from "./stats"; export class DataCollector { private vault: Vault; private metadataCache: MetadataCache; + private settings: BetterWordCountSettings; - constructor(vault: Vault, metadataCache: MetadataCache) { + constructor(vault: Vault, metadataCache: MetadataCache, settings: BetterWordCountSettings) { this.vault = vault; this.metadataCache = metadataCache; + this.settings = settings; } getTotalFileCount() { diff --git a/src/data/manager.ts b/src/data/manager.ts index 8162202..5eea5ed 100644 --- a/src/data/manager.ts +++ b/src/data/manager.ts @@ -1,6 +1,7 @@ import moment from "moment"; import { debounce, Debouncer, MetadataCache, TFile, Vault } from "obsidian"; import { STATS_FILE } from "src/constants"; +import type { BetterWordCountSettings } from "src/settings/settings"; import { DataCollector } from "./collector"; import { getCharacterCount, getSentenceCount, getWordCount } from "./stats"; @@ -41,34 +42,38 @@ export interface TotalCounts { export class DataManager { private vault: Vault; private metadataCache: MetadataCache; + private settings: BetterWordCountSettings; private history: History; private today: string; private collector: DataCollector; private todayCounts: TodayCounts; public debounceChange: Debouncer<[file: TFile, data: string]>; - constructor(vault: Vault, metadataCache: MetadataCache) { + constructor(vault: Vault, metadataCache: MetadataCache, settings: BetterWordCountSettings) { this.vault = vault; this.metadataCache = metadataCache; - this.collector = new DataCollector(vault, metadataCache); + this.settings = settings; + this.collector = new DataCollector(vault, metadataCache, settings); this.debounceChange = debounce( (file: TFile, data: string) => this.change(file, data), 1000, false ); - this.vault.adapter.exists(".vault-stats").then(async (exists) => { - if (!exists) { - this.vault.adapter.write(".vault-stats", "{}"); - } - - this.history = Object.assign( - JSON.parse(await this.vault.adapter.read(".vault-stats")) - ); - - this.updateToday(); - this.update(); - }); + if(this.settings.collectStats){ + this.vault.adapter.exists(".vault-stats").then(async (exists) => { + if (!exists) { + this.vault.adapter.write(".vault-stats", "{}"); + } + + this.history = Object.assign( + JSON.parse(await this.vault.adapter.read(".vault-stats")) + ); + + this.updateToday(); + this.update(); + }); + } } async update(): Promise { diff --git a/src/main.ts b/src/main.ts index 0a9347b..7a40f63 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,7 +38,8 @@ export default class BetterWordCount extends Plugin { if (this.settings.collectStats) { this.dataManager = new DataManager( this.app.vault, - this.app.metadataCache + this.app.metadataCache, + this.settings ); } diff --git a/src/status/manager.ts b/src/status/manager.ts index 655432e..e438580 100644 --- a/src/status/manager.ts +++ b/src/status/manager.ts @@ -30,8 +30,8 @@ export class BarManager { this.statusBar = statusBar; this.settings = settings; this.vault = vault; - this.dataCollector = new DataCollector(vault, metadataCache); - this.dataManager = new DataManager(vault, metadataCache); + this.dataCollector = new DataCollector(vault, metadataCache, settings); + this.dataManager = new DataManager(vault, metadataCache, settings); this.deboucer = debounce( (text: string) => this.updateStatusBar(text), 20,