#22 - bugfix of the status indicator in ribbon icon sometimes not updated

- plus version bump for release
This commit is contained in:
SebastianMC 2022-11-03 10:23:11 +01:00
parent 641690eac2
commit b9592920b7
4 changed files with 21 additions and 4 deletions

View File

@ -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",

View File

@ -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": {

View File

@ -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]

View File

@ -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"
}