mirror of
https://github.com/devonthesofa/obsidian-note-status.git
synced 2026-07-22 12:30:24 +00:00
fix: reload commands when settings changed
This commit is contained in:
parent
248dbd7700
commit
5c3ed9b00c
3 changed files with 21 additions and 9 deletions
|
|
@ -310,17 +310,13 @@ export class CommandsService {
|
|||
return statuses.length > 0 ? statuses.map((s) => s.name) : ["unknown"];
|
||||
}
|
||||
|
||||
public unload(): void {
|
||||
// Remove existing commands
|
||||
this.removeQuickStatusCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all quick status commands
|
||||
*/
|
||||
private removeQuickStatusCommands(): void {
|
||||
const allStatuses = BaseNoteStatusService.getAllAvailableStatuses();
|
||||
|
||||
//TODO: If there is an update the
|
||||
allStatuses.forEach((status) => {
|
||||
// @ts-ignore
|
||||
this.app.commands.removeCommand(
|
||||
|
|
@ -333,9 +329,9 @@ export class CommandsService {
|
|||
});
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
// Commands are automatically cleaned up when the plugin is disabled
|
||||
// But we can track them for debugging purposes
|
||||
public destroy(): void {
|
||||
// Remove existing commands
|
||||
this.removeQuickStatusCommands();
|
||||
this.registeredCommands.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class SettingsService {
|
|||
if (!(key in this.settings)) {
|
||||
throw new Error(`The "${key}" setting is not a known setting key`);
|
||||
}
|
||||
// const oldValue = this.settings[key]; // TODO: Send the old value
|
||||
this.settings[key] = value;
|
||||
this.saveSettings().catch(console.error);
|
||||
// INFO: Send the propgation event
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import eventBus from "@/core/eventBus";
|
||||
import { Plugin } from "obsidian";
|
||||
import { CommandsService } from "../../core/commandsService";
|
||||
|
||||
|
|
@ -24,11 +25,25 @@ export class CommandsIntegration {
|
|||
async integrate(): Promise<void> {
|
||||
// Register all commands from the service
|
||||
this.commandsService.registerAllCommands();
|
||||
|
||||
eventBus.subscribe(
|
||||
"plugin-settings-changed",
|
||||
({ value, key }) => {
|
||||
if (
|
||||
key === "quickStatusCommands" ||
|
||||
key === "useMultipleStatuses"
|
||||
) {
|
||||
this.commandsService.destroy();
|
||||
/// BUG: if removed a command will persist because is not removed, you need the oldStates to send it to be disabled // const oldValue = this.settings[key]; // TODO: Send the old value
|
||||
this.commandsService.registerAllCommands(); // INFO: Reset the registered commands
|
||||
}
|
||||
},
|
||||
"statusBarIntegrationSubscription2",
|
||||
);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
if (this.commandsService) {
|
||||
this.commandsService.unload();
|
||||
this.commandsService.destroy();
|
||||
}
|
||||
CommandsIntegration.instance = null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue