fix: Prevent duplicate context provider addition
This commit is contained in:
parent
af175c6fd9
commit
2d6eacbeab
2 changed files with 14 additions and 4 deletions
|
|
@ -12,6 +12,8 @@ import {
|
|||
import { GlobalContext } from "../util/GlobalContext";
|
||||
import { editConfigJson } from "../util/paths";
|
||||
|
||||
import { ConfigHandler } from "./ConfigHandler";
|
||||
|
||||
function stringify(obj: any, indentation?: number): string {
|
||||
return JSON.stringify(
|
||||
obj,
|
||||
|
|
@ -22,16 +24,24 @@ function stringify(obj: any, indentation?: number): string {
|
|||
);
|
||||
}
|
||||
|
||||
export function addContextProvider(provider: ContextProviderWithParams) {
|
||||
export function addContextProvider(provider: ContextProviderWithParams, configHandler?: ConfigHandler) {
|
||||
let isAdded = false;
|
||||
editConfigJson((config) => {
|
||||
|
||||
if (!config.contextProviders) {
|
||||
config.contextProviders = [provider];
|
||||
} else {
|
||||
config.contextProviders = [];
|
||||
}
|
||||
if (!config.contextProviders.some((p) => p.name === provider.name)) {
|
||||
config.contextProviders.push(provider);
|
||||
isAdded = true;
|
||||
}
|
||||
|
||||
return config;
|
||||
});
|
||||
|
||||
if (isAdded && configHandler) {
|
||||
void configHandler.reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
export function addModel(
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ export class Core {
|
|||
});
|
||||
|
||||
on("config/addContextProvider", async (msg) => {
|
||||
addContextProvider(msg.data);
|
||||
addContextProvider(msg.data, this.configHandler);
|
||||
});
|
||||
|
||||
on("config/updateSharedConfig", async (msg) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue