From 16823529f9597db2bdbd94638c112b148ae2bc4b Mon Sep 17 00:00:00 2001 From: dhruvik7 Date: Sun, 14 Feb 2021 20:42:02 -0500 Subject: [PATCH] 1.0.1 --- main.ts | 27 ++++++++++++--------------- manifest.json | 4 ++-- package.json | 2 +- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/main.ts b/main.ts index 264d712..6c8d2a4 100644 --- a/main.ts +++ b/main.ts @@ -1,4 +1,4 @@ -import { TFile, Plugin } from 'obsidian'; +import { TFile, Plugin, MarkdownView } from 'obsidian'; interface WordCount { initial: number; @@ -26,18 +26,18 @@ export default class DailyStats extends Plugin { this.statusBarEl = this.addStatusBarItem(); this.updateDate(); - if (this.today in this.settings.dayCounts) { + if (this.settings.dayCounts.hasOwnProperty(this.today)) { this.updateCounts(); } else { this.currentWordCount = 0; } this.registerEvent( - this.app.workspace.on("quit", this.onunload, this) + this.app.workspace.on("quit", this.onunload.bind(this)) ); this.registerEvent( - this.app.workspace.on("quick-preview", this.onQuickPreview, this) + this.app.workspace.on("quick-preview", this.onQuickPreview.bind(this)) ); this.registerInterval( @@ -56,12 +56,9 @@ export default class DailyStats extends Plugin { await this.saveSettings(); } - //Credit: better-word-count by Luke Leppan (https://github.com/lukeleppan/better-word-count) onQuickPreview(file: TFile, contents: string) { - const leaf = this.app.workspace.activeLeaf; - - if (leaf && leaf.view.getViewType() === "markdown") { - this.updateWordCount(contents, file.name); + if (this.app.workspace.getActiveViewOfType(MarkdownView)) { + this.updateWordCount(contents, file.path); } } @@ -86,17 +83,17 @@ export default class DailyStats extends Plugin { return words; } - updateWordCount(contents: string, filename: string) { + updateWordCount(contents: string, filepath: string) { const curr = this.getWordCount(contents); - if (this.today in this.settings.dayCounts) { - if (filename in this.settings.todaysWordCount) {//updating existing file - this.settings.todaysWordCount[filename].current = curr; + if (this.settings.dayCounts.hasOwnProperty(this.today)) { + if (this.settings.todaysWordCount.hasOwnProperty(filepath)) {//updating existing file + this.settings.todaysWordCount[filepath].current = curr; } else {//created new file during session - this.settings.todaysWordCount[filename] = { initial: curr, current: curr }; + this.settings.todaysWordCount[filepath] = { initial: curr, current: curr }; } } else {//new day, flush the cache this.settings.todaysWordCount = {}; - this.settings.todaysWordCount[filename] = { initial: curr, current: curr }; + this.settings.todaysWordCount[filepath] = { initial: curr, current: curr }; } this.updateCounts(); } diff --git a/manifest.json b/manifest.json index ed24bb9..d44afb0 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "id": "obsidian-daily-stats", "name": "Daily Stats", - "version": "1.0.0", - "minAppVersion": "0.9.12", + "version": "1.0.1", + "minAppVersion": "0.9.10", "description": "Track your daily word count across all notes in your vault.", "author": "Dhruvik Parikh", "authorUrl": "https://github.com/dhruvik7", diff --git a/package.json b/package.json index 977a1fe..96cfcd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-daily-stats", - "version": "1.0.0", + "version": "1.0.1", "description": "This is an Obsidian.md plugin that lets you view your daily word count.", "main": "main.js", "scripts": {