Fix name attribute in dynamic config

This commit is contained in:
TC
2023-04-04 22:13:04 +02:00
parent cad8e4fe83
commit 5a775b238c

View File

@ -155,7 +155,7 @@ module.exports.PluginConfig = class PluginConfig {
if (typeof fn !== "function" || fn.name in ignoredMethods) return; if (typeof fn !== "function" || fn.name in ignoredMethods) return;
this[fnName] = async (...args) => { this[fnName] = async (...args) => {
return await ipcRenderer.invoke( return await ipcRenderer.invoke(
`${this.name}-config-${fnName}`, `${this.#name}-config-${fnName}`,
...args, ...args,
); );
}; };
@ -166,38 +166,38 @@ module.exports.PluginConfig = class PluginConfig {
} }
this.#subscribers[valueName] = fn; this.#subscribers[valueName] = fn;
ipcRenderer.on( ipcRenderer.on(
`${this.name}-config-changed-${valueName}`, `${this.#name}-config-changed-${valueName}`,
(_, value) => { (_, value) => {
fn(value); fn(value);
}, },
); );
ipcRenderer.send(`${this.name}-config-subscribe`, valueName); ipcRenderer.send(`${this.#name}-config-subscribe`, valueName);
}; };
this.subscribeAll = (fn) => { this.subscribeAll = (fn) => {
ipcRenderer.on(`${this.name}-config-changed`, (_, value) => { ipcRenderer.on(`${this.#name}-config-changed`, (_, value) => {
fn(value); fn(value);
}); });
ipcRenderer.send(`${this.name}-config-subscribe-all`); ipcRenderer.send(`${this.#name}-config-subscribe-all`);
}; };
} }
} else if (process.type === "browser") { } else if (process.type === "browser") {
for (const [fnName, fn] of Object.entries(this)) { for (const [fnName, fn] of Object.entries(this)) {
if (typeof fn !== "function" || fn.name in ignoredMethods) return; if (typeof fn !== "function" || fn.name in ignoredMethods) return;
ipcMain.handle(`${this.name}-config-${fnName}`, (_, ...args) => { ipcMain.handle(`${this.#name}-config-${fnName}`, (_, ...args) => {
return fn(...args); return fn(...args);
}); });
} }
ipcMain.on(`${this.name}-config-subscribe`, (_, valueName) => { ipcMain.on(`${this.#name}-config-subscribe`, (_, valueName) => {
this.subscribe(valueName, (value) => { this.subscribe(valueName, (value) => {
sendToFront(`${this.name}-config-changed-${valueName}`, value); sendToFront(`${this.#name}-config-changed-${valueName}`, value);
}); });
}); });
ipcMain.on(`${this.name}-config-subscribe-all`, () => { ipcMain.on(`${this.#name}-config-subscribe-all`, () => {
this.subscribeAll((value) => { this.subscribeAll((value) => {
sendToFront(`${this.name}-config-changed`, value); sendToFront(`${this.#name}-config-changed`, value);
}); });
}); });
} }