XL v1.2.3 context menu fixes
This commit is contained in:
parent
fa73be4e8f
commit
0a79f144c0
|
@ -23,7 +23,7 @@
|
|||
|
||||
@else@*/
|
||||
/*
|
||||
* Copyright© 2019-2020, _Lighty_
|
||||
* Copyright© 2019-2020, _Lighty_
|
||||
* All rights reserved.
|
||||
* Code may not be redistributed, modified or otherwise taken without explicit permission.
|
||||
*/
|
||||
|
@ -41,7 +41,7 @@ var XenoLib = (() => {
|
|||
twitter_username: ''
|
||||
}
|
||||
],
|
||||
version: '1.2.2',
|
||||
version: '1.2.3',
|
||||
description: 'Simple library to complement plugins with shared code without lowering performance.',
|
||||
github: 'https://github.com/1Lighty',
|
||||
github_raw: 'https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/1XenoLib.plugin.js'
|
||||
|
@ -50,7 +50,7 @@ var XenoLib = (() => {
|
|||
{
|
||||
title: 'Hopefully fixed',
|
||||
type: 'fixed',
|
||||
items: ["Reworked the context menu patching, so plugins like BDContextMenu by Zerebos don't break", 'Added utility function for renaming plugins to prepare for future plugin renames']
|
||||
items: ['Fixed BDFDB causing issues with patching context menus']
|
||||
}
|
||||
]
|
||||
};
|
||||
|
@ -250,23 +250,36 @@ var XenoLib = (() => {
|
|||
if (!modules.hasOwnProperty(index)) continue;
|
||||
const module = modules[index];
|
||||
if (!module.exports || !module.exports.__esModule || !module.exports.default) continue;
|
||||
if (module.exports.default.toString().search(regex) !== -1) return module;
|
||||
/* if BDFDB was inited before us, patch the already patched function */
|
||||
if (module.exports.default.toString().search(regex) !== -1 || (module.exports.default.isBDFDBpatched && module.exports.default.originalsource.toString().search(regex) !== -1)) return module;
|
||||
}
|
||||
}
|
||||
const somemoremenus = [getModule(/case \w.ContextMenuTypes.CHANNEL_LIST_TEXT/), getModule(/case \w.ContextMenuTypes.GUILD_CHANNEL_LIST/), getModule(/case \w.ContextMenuTypes.USER_CHANNEL_MEMBERS/)];
|
||||
somemoremenus.forEach(menu => {
|
||||
if (!menu) return Logger.warn('Special context menu is undefined!');
|
||||
const originalFunc = menu.exports.default;
|
||||
const origDef = menu.exports.default;
|
||||
const originalFunc = Utilities.getNestedProp(menu, 'exports.BDFDBpatch.default.originalMethod') || menu.exports.default;
|
||||
Patcher.after(menu.exports, 'default', (_, [props], ret) => handleContextMenu({ props }, ret));
|
||||
Patcher.instead(menu.exports.default, 'toString', (_this, args, orig) => {
|
||||
return originalFunc.toString(...args);
|
||||
});
|
||||
/* make it friendly to other plugins and libraries that search by string
|
||||
note: removing this makes BDFDB shit itself
|
||||
*/
|
||||
Patcher.instead(menu.exports.default, 'toString', (_, args, __) => originalFunc.toString(...args));
|
||||
/* if BDFDB already patched it, patch the function BDFDB is storing in case it decides to unaptch
|
||||
this is to prevent BDFDB from removing our patch
|
||||
this function is never called in BDFDB, it's only stored for restore
|
||||
*/
|
||||
if (origDef.isBDFDBpatched && menu.exports.BDFDBpatch && typeof menu.exports.BDFDBpatch.default.originalMethod === 'function') {
|
||||
Patcher.after(menu.exports.BDFDBpatch.default, 'originalMethod', (_, [props], ret) => handleContextMenu({ props }, ret));
|
||||
/* make it friendly to other plugins and libraries that search by string
|
||||
note: removing this makes BDFDB shit itself
|
||||
*/
|
||||
Patcher.instead(menu.exports.BDFDBpatch.default.originalMethod, 'toString', (_, args, __) => originalFunc.toString(...args));
|
||||
}
|
||||
});
|
||||
XenoLib.__contextPatches.__contextPatched = true;
|
||||
}
|
||||
XenoLib.patchContext = callback => {
|
||||
XenoLib.__contextPatches.push(callback);
|
||||
if (!XenoLib.__contextPatches.__contextPatched) patchAllContextMenus();
|
||||
};
|
||||
class ContextMenuWrapper extends React.PureComponent {
|
||||
render() {
|
||||
|
@ -283,14 +296,9 @@ var XenoLib = (() => {
|
|||
}
|
||||
};
|
||||
|
||||
if (global.XenoLib) {
|
||||
if (global.XenoLib.__contextPatches && global.XenoLib.__contextPatches.length) {
|
||||
XenoLib.__contextPatches.push(...global.XenoLib.__contextPatches);
|
||||
patchAllContextMenus();
|
||||
}
|
||||
}
|
||||
if (global.XenoLib) if (global.XenoLib.__contextPatches && global.XenoLib.__contextPatches.length) XenoLib.__contextPatches.push(...global.XenoLib.__contextPatches);
|
||||
XenoLib.unpatchContext = callback => XenoLib.__contextPatches.splice(XenoLib.__contextPatches.indexOf(callback), 1);
|
||||
|
||||
patchAllContextMenus(); /* prevent BDFDB from being a gay piece of crap by patching it first */
|
||||
XenoLib.createContextMenuItem = (label, action, options = {}) =>
|
||||
React.createElement(ContextMenuItem, {
|
||||
label,
|
||||
|
|
Loading…
Reference in New Issue