Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
userXinos committed Sep 9, 2022
1 parent 47afe15 commit e5930f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
13 changes: 3 additions & 10 deletions modules/Patcher/General.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ module.exports = class General {
const menu = render(config);

if (menu?.type?.displayName) {
patchMenu(menu?.type?.displayName, menu);
patchMenu(menu.type.displayName);
} else {
menu.type = memorizeRender(menu.type, (res) => {
res.props.children.type = memorizeRender(res.props.children.type, (res2) => {
patchMenu(res2?.type?.displayName, menu);
patchMenu(res2?.type?.displayName);
return res2;
});
return res;
Expand All @@ -103,21 +103,14 @@ module.exports = class General {
this.uninjectIDs.push(id);


function patchMenu (name, menu) {
function patchMenu (name) {
const moduleByDisplayName = getModuleByDisplayName(name, false);
const module = getModule((m) => m.default === menu.type || m.__powercordOriginal_default === menu.type, false);

if (name && name in menus) {
if (moduleByDisplayName !== null) {
injectWithSettingsBind(`${name}.default`, menus[name]);
}
delete menus[name];

if (moduleByDisplayName !== null) {
menu.type = moduleByDisplayName;
} else if (module !== null) {
menu.type = module.default;
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions utils/inject2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ const { inject } = require('powercord/injector');
* @param {String|Object} funcPath (ex ModuleName.default)
* @param {function} patch
*/
module.exports = function inject2 (funcPath, patch, listInjectID = null) {
module.exports = function inject2 (funcPath, patch) {
const path = funcPath.split('.');
const moduleName = path.shift();
const method = path.pop();
const injectId = `image-tools${moduleName.replace(/[A-Z]/g, (l) => `-${l.toLowerCase()}`)}`;
if (listInjectID?.includes(injectId)) return injectId;
const module = getModule((m) => m?.default?.displayName === moduleName, false);
const injectTo = getModulePath(); // eslint-disable-line no-use-before-define

if (module === null) {
const id = 'image-tools';
const { plugins } = powercord.pluginManager;
const out = (plugins.has(id)) ? plugins.get(id) : global.console;
const log = (plugins.has(id)) ? plugins.get(id) : global.console;

out.error(`Module ${moduleName} not found`);
log.error(`Module ${moduleName} not found`);
return;
}

Expand Down

0 comments on commit e5930f9

Please sign in to comment.