Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(obsidian): notify users of Harper updates (#1659)
Elijah Potter18c16605ddfc
diff --git a/packages/obsidian-plugin/src/HarperSettingTab.ts b/packages/obsidian-plugin/src/HarperSettingTab.tsindex 7999b477b..cfe9cedcb 100644--- a/packages/obsidian-plugin/src/HarperSettingTab.ts+++ b/packages/obsidian-plugin/src/HarperSettingTab.ts@@ -115,6 +115,13 @@ export class HarperSettingTab extends PluginSettingTab {});});+ new Setting(containerEl).setName('Get Notified of Harper Updates').addToggle((toggle) => {+ toggle.setValue(this.settings.showUpdateNotification ?? true).onChange(async (value) => {+ this.settings.showUpdateNotification = value;+ await this.state.initializeFromSettings(this.settings);+ });+ });+new Setting(containerEl).setName('The Danger Zone').addButton((button) => {button.setButtonText('Forget Ignored Suggestions')diff --git a/packages/obsidian-plugin/src/State.ts b/packages/obsidian-plugin/src/State.tsindex cd73d9121..8d9bee7e9 100644--- a/packages/obsidian-plugin/src/State.ts+++ b/packages/obsidian-plugin/src/State.ts@@ -14,6 +14,8 @@ export type Settings = {userDictionary?: string[];delay?: number;ignoredGlobs?: string[];+ /** An undefined value should be treated the same as `true`. */+ showUpdateNotification?: boolean;};const DEFAULT_DELAY = -1;@@ -28,6 +30,7 @@ export default class State {private onExtensionChange: () => void;private ignoredGlobs?: string[];private editorViewField?: StateField<MarkdownFileInfo>;+ private showUpdateNotification?: boolean;/** The CodeMirror extension objects that should be inserted by the host. */private editorExtensions: Extension[];@@ -87,6 +90,7 @@ export default class State {this.delay = settings.delay ?? DEFAULT_DELAY;this.ignoredGlobs = settings.ignoredGlobs;+ this.showUpdateNotification = settings.showUpdateNotification;// Reinitialize it.if (this.hasEditorLinter()) {@@ -218,6 +222,7 @@ export default class State {dialect: await this.harper.getDialect(),delay: this.delay,ignoredGlobs: this.ignoredGlobs,+ showUpdateNotification: this.showUpdateNotification,};}diff --git a/packages/obsidian-plugin/src/index.ts b/packages/obsidian-plugin/src/index.tsindex 18cbbfe30..99840a3e7 100644--- a/packages/obsidian-plugin/src/index.ts+++ b/packages/obsidian-plugin/src/index.ts@@ -19,10 +19,16 @@ async function getLatestVersion(): Promise<string> {return response.text();}-export async function logVersionInfo(): Promise<void> {+export async function logVersionInfo(showNotification: boolean): Promise<void> {try {const latest = await getLatestVersion();console.info(`Latest available Harper version: ${latest}`);++ if (latest != `v${packageJson.version}` && showNotification) {+ setTimeout(() => {+ new Notice('A newer version of Harper is available.');+ }, 5000);+ }} catch (err) {console.error(`Unable to obtain latest version: ${err}`);}@@ -30,8 +36,6 @@ export async function logVersionInfo(): Promise<void> {console.info(`Current version: ${packageJson.version}`);}-logVersionInfo();-export default class HarperPlugin extends Plugin {private state: State;private dialectSpan: HTMLSpanElement | null = null;@@ -59,6 +63,8 @@ export default class HarperPlugin extends Plugin {this.state.enableEditorLinter();this.addSettingTab(new HarperSettingTab(this.app, this, this.state));++ await logVersionInfo((await this.state.getSettings()).showUpdateNotification ?? true);}private getDialectStatus(dialectNum: Dialect): string {