From b9592920b71ea90229b08f658a9ec610cb7dfa4c Mon Sep 17 00:00:00 2001 From: SebastianMC <23032356+SebastianMC@users.noreply.github.com> Date: Thu, 3 Nov 2022 10:23:11 +0100 Subject: [PATCH] #22 - bugfix of the status indicator in ribbon icon sometimes not updated - plus version bump for release --- manifest.json | 2 +- package.json | 2 +- src/main.ts | 18 +++++++++++++++++- versions.json | 3 ++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index 8aa9237..ba4b320 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "custom-sort", "name": "Custom File Explorer sorting", - "version": "1.0.2", + "version": "1.0.3", "minAppVersion": "0.15.0", "description": "Allows for manual and automatic, config-driven reordering and sorting of files and folders in File Explorer", "author": "SebastianMC", diff --git a/package.json b/package.json index 1a6e4b7..88bbda6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-custom-sort", - "version": "1.0.2", + "version": "1.0.3", "description": "Custom Sort plugin for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index 541fbba..edf7ef2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -52,6 +52,7 @@ export default class CustomSortPlugin extends Plugin { settings: CustomSortPluginSettings statusBarItemEl: HTMLElement ribbonIconEl: HTMLElement + ribbonIconStateInaccurate: boolean sortSpecCache?: SortSpecsCollection | null initialAutoOrManualSortingTriggered: boolean @@ -152,6 +153,10 @@ export default class CustomSortPlugin extends Plugin { } else { if (iconToSet === ICON_SORT_ENABLED_ACTIVE) { iconToSet = ICON_SORT_ENABLED_NOT_APPLIED + + if (updateRibbonBtnIcon) { + this.ribbonIconStateInaccurate = true + } } } @@ -163,7 +168,7 @@ export default class CustomSortPlugin extends Plugin { } async onload() { - console.log("loading custom-sort"); + console.log(`loading custom-sort v${this.manifest.version}`); await this.loadSettings(); @@ -183,6 +188,10 @@ export default class CustomSortPlugin extends Plugin { this.switchPluginStateTo(this.settings.suspended) }); + if (!this.settings.suspended) { + this.ribbonIconStateInaccurate = true + } + this.addSettingTab(new CustomSortSettingTab(this.app, this)); this.registerEventHandlers() @@ -193,6 +202,7 @@ export default class CustomSortPlugin extends Plugin { } registerEventHandlers() { + const plugin: CustomSortPlugin = this this.registerEvent( // Keep in mind: this event is triggered once after app starts and then after each modification of _any_ metadata this.app.metadataCache.on("resolved", () => { @@ -208,6 +218,7 @@ export default class CustomSortPlugin extends Plugin { fileExplorerView.requestSort() } else { setIcon(this.ribbonIconEl, ICON_SORT_ENABLED_NOT_APPLIED) + plugin.ribbonIconStateInaccurate = true } this.updateStatusBar() } else { @@ -261,6 +272,11 @@ export default class CustomSortPlugin extends Plugin { return old.call(this, ...args); } + if (plugin.ribbonIconStateInaccurate && plugin.ribbonIconEl) { + plugin.ribbonIconStateInaccurate = false + setIcon(plugin.ribbonIconEl, ICON_SORT_ENABLED_ACTIVE) + } + // if custom sort is not specified, use the UI-selected const folder: TFolder = this.file let sortSpec: CustomSortSpec | null | undefined = plugin.sortSpecCache?.sortSpecByPath[folder.path] diff --git a/versions.json b/versions.json index f300c3e..bf6e6d4 100644 --- a/versions.json +++ b/versions.json @@ -14,5 +14,6 @@ "0.8.4": "0.15.0", "1.0.0": "0.15.0", "1.0.1": "0.15.0", - "1.0.2": "0.15.0" + "1.0.2": "0.15.0", + "1.0.3": "0.15.0" }