Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
thororen1234 2025-02-27 22:19:58 -05:00
commit ae1d98c8cf
No known key found for this signature in database
6 changed files with 132 additions and 11 deletions

View file

@ -5,8 +5,11 @@
*/
import { definePluginSettings } from "@api/Settings";
import { ErrorBoundary, Flex } from "@components/index";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType, StartAt } from "@utils/types";
import { Margins } from "@utils/margins";
import definePlugin, { defineDefault, OptionType, StartAt } from "@utils/types";
import { Checkbox, Forms, Text } from "@webpack/common";
const Noop = () => { };
const NoopLogger = {
@ -24,6 +27,48 @@ const NoopLogger = {
const logAllow = new Set();
interface AllowLevels {
error: boolean;
warn: boolean;
trace: boolean;
log: boolean;
info: boolean;
debug: boolean;
}
interface AllowLevelSettingProps {
settingKey: keyof AllowLevels;
}
function AllowLevelSetting({ settingKey }: AllowLevelSettingProps) {
const { allowLevel } = settings.use(["allowLevel"]);
const value = allowLevel[settingKey];
return (
<Checkbox
value={value}
onChange={(_, newValue) => settings.store.allowLevel[settingKey] = newValue}
size={20}
>
<Text variant="text-sm/normal">{settingKey[0].toUpperCase() + settingKey.slice(1)}</Text>
</Checkbox>
);
}
const AllowLevelSettings = ErrorBoundary.wrap(() => {
return (
<Forms.FormSection>
<Forms.FormTitle tag="h3">Filter List</Forms.FormTitle>
<Forms.FormText className={Margins.bottom8} type={Forms.FormText.Types.DESCRIPTION}>Always allow loggers of these types</Forms.FormText>
<Flex flexDirection="row">
{Object.keys(settings.store.allowLevel).map(key => (
<AllowLevelSetting key={key} settingKey={key as keyof AllowLevels} />
))}
</Flex>
</Forms.FormSection>
);
});
const settings = definePluginSettings({
disableLoggers: {
type: OptionType.BOOLEAN,
@ -45,6 +90,18 @@ const settings = definePluginSettings({
logAllow.clear();
newVal.split(";").map(x => x.trim()).forEach(logAllow.add.bind(logAllow));
}
},
allowLevel: {
type: OptionType.COMPONENT,
component: AllowLevelSettings,
default: defineDefault<AllowLevels>({
error: true,
warn: false,
trace: false,
log: false,
info: false,
debug: false
})
}
});
@ -61,8 +118,9 @@ export default definePlugin({
},
NoopLogger: () => NoopLogger,
shouldLog(logger: string) {
return logAllow.has(logger);
shouldLog(logger: string, level: keyof AllowLevels) {
return logAllow.has(logger) || settings.store.allowLevel[level] === true;
},
patches: [
@ -136,13 +194,13 @@ export default definePlugin({
replace: ""
}
},
// Patches discords generic logger function
// Patches Discord generic logger function
{
find: "Σ:",
predicate: () => settings.store.disableLoggers,
replacement: {
match: /(?<=&&)(?=console)/,
replace: "$self.shouldLog(arguments[0])&&"
replace: "$self.shouldLog(arguments[0],arguments[1])&&"
}
},
{

View file

@ -165,8 +165,35 @@ export default definePlugin({
{
find: ".contain,SCALE_DOWN:",
replacement: {
match: /\.slide,\i\),/g,
replace: `$&id:"${ELEMENT_ID}",`
match: /imageClassName:/,
replace: `id:"${ELEMENT_ID}",$&`
}
},
{
find: ".dimensionlessImage,",
replacement: [
{
match: /className:\i\.media,/,
replace: `id:"${ELEMENT_ID}",$&`
},
{
// This patch needs to be above the next one as it uses the zoomed class as an anchor
match: /\.zoomed]:.+?,(?=children:)/,
replace: "$&onClick:()=>{},"
},
{
match: /className:\i\(\)\(\i\.wrapper,.+?}\),/,
replace: ""
},
]
},
// Make media viewer options not hide when zoomed in with the default Discord feature
{
find: '="FOCUS_SENSITIVE",',
replacement: {
match: /(?<=\.hidden]:)\i/,
replace: "false"
}
},