Future proof FakeNitro and Experiments to not brick Discord startup
This commit is contained in:
		
							parent
							
								
									dfb06e47d0
								
							
						
					
					
						commit
						80b738ff3e
					
				
					 2 changed files with 38 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -20,10 +20,12 @@ import { definePluginSettings } from "@api/Settings";
 | 
			
		|||
import ErrorBoundary from "@components/ErrorBoundary";
 | 
			
		||||
import { ErrorCard } from "@components/ErrorCard";
 | 
			
		||||
import { Devs } from "@utils/constants";
 | 
			
		||||
import { Logger } from "@utils/Logger";
 | 
			
		||||
import { Margins } from "@utils/margins";
 | 
			
		||||
import definePlugin, { OptionType } from "@utils/types";
 | 
			
		||||
import { findByPropsLazy } from "@webpack";
 | 
			
		||||
import { Forms, React } from "@webpack/common";
 | 
			
		||||
import { Forms, React, UserStore } from "@webpack/common";
 | 
			
		||||
import { User } from "discord-types/general";
 | 
			
		||||
 | 
			
		||||
const KbdStyles = findByPropsLazy("key", "removeBuildOverride");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -68,8 +70,8 @@ export default definePlugin({
 | 
			
		|||
            predicate: () => settings.store.enableIsStaff,
 | 
			
		||||
            replacement: [
 | 
			
		||||
                {
 | 
			
		||||
                    match: /=>*?(\i)\.hasFlag\((\i\.\i)\.STAFF\)}/,
 | 
			
		||||
                    replace: (_, user, flags) => `=>Vencord.Webpack.Common.UserStore.getCurrentUser()?.id===${user}.id||${user}.hasFlag(${flags}.STAFF)}`
 | 
			
		||||
                    match: /(?<=>)(\i)\.hasFlag\((\i\.\i)\.STAFF\)(?=})/,
 | 
			
		||||
                    replace: (_, user, flags) => `$self.isStaff(${user},${flags})`
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    match: /hasFreePremium\(\){return this.isStaff\(\)\s*?\|\|/,
 | 
			
		||||
| 
						 | 
				
			
			@ -86,6 +88,15 @@ export default definePlugin({
 | 
			
		|||
        }
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    isStaff(user: User, flags: any) {
 | 
			
		||||
        try {
 | 
			
		||||
            return UserStore.getCurrentUser()?.id === user.id || user.hasFlag(flags.STAFF);
 | 
			
		||||
        } catch (err) {
 | 
			
		||||
            new Logger("Experiments").error(err);
 | 
			
		||||
            return user.hasFlag(flags.STAFF);
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    settingsAboutComponent: () => {
 | 
			
		||||
        const isMacOS = navigator.platform.includes("Mac");
 | 
			
		||||
        const modKey = isMacOS ? "cmd" : "ctrl";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -413,31 +413,35 @@ export default definePlugin({
 | 
			
		|||
    },
 | 
			
		||||
 | 
			
		||||
    handleProtoChange(proto: any, user: any) {
 | 
			
		||||
        if (proto == null || typeof proto === "string" || !UserSettingsProtoStore || !PreloadedUserSettingsActionCreators || !AppearanceSettingsActionCreators || !ClientThemeSettingsActionsCreators) return;
 | 
			
		||||
        try {
 | 
			
		||||
            if (proto == null || typeof proto === "string") return;
 | 
			
		||||
 | 
			
		||||
        const premiumType: number = user?.premium_type ?? UserStore?.getCurrentUser()?.premiumType ?? 0;
 | 
			
		||||
            const premiumType: number = user?.premium_type ?? UserStore?.getCurrentUser()?.premiumType ?? 0;
 | 
			
		||||
 | 
			
		||||
        if (premiumType !== 2) {
 | 
			
		||||
            proto.appearance ??= AppearanceSettingsActionCreators.create();
 | 
			
		||||
            if (premiumType !== 2) {
 | 
			
		||||
                proto.appearance ??= AppearanceSettingsActionCreators.create();
 | 
			
		||||
 | 
			
		||||
            if (UserSettingsProtoStore.settings.appearance?.theme != null) {
 | 
			
		||||
                const appearanceSettingsDummy = AppearanceSettingsActionCreators.create({
 | 
			
		||||
                    theme: UserSettingsProtoStore.settings.appearance.theme
 | 
			
		||||
                });
 | 
			
		||||
                if (UserSettingsProtoStore.settings.appearance?.theme != null) {
 | 
			
		||||
                    const appearanceSettingsDummy = AppearanceSettingsActionCreators.create({
 | 
			
		||||
                        theme: UserSettingsProtoStore.settings.appearance.theme
 | 
			
		||||
                    });
 | 
			
		||||
 | 
			
		||||
                proto.appearance.theme = appearanceSettingsDummy.theme;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (UserSettingsProtoStore.settings.appearance?.clientThemeSettings?.backgroundGradientPresetId?.value != null) {
 | 
			
		||||
                const clientThemeSettingsDummy = ClientThemeSettingsActionsCreators.create({
 | 
			
		||||
                    backgroundGradientPresetId: {
 | 
			
		||||
                        value: UserSettingsProtoStore.settings.appearance.clientThemeSettings.backgroundGradientPresetId.value
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                proto.appearance.clientThemeSettings ??= clientThemeSettingsDummy;
 | 
			
		||||
                proto.appearance.clientThemeSettings.backgroundGradientPresetId = clientThemeSettingsDummy.backgroundGradientPresetId;
 | 
			
		||||
                    proto.appearance.theme = appearanceSettingsDummy.theme;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (UserSettingsProtoStore.settings.appearance?.clientThemeSettings?.backgroundGradientPresetId?.value != null) {
 | 
			
		||||
                    const clientThemeSettingsDummy = ClientThemeSettingsActionsCreators.create({
 | 
			
		||||
                        backgroundGradientPresetId: {
 | 
			
		||||
                            value: UserSettingsProtoStore.settings.appearance.clientThemeSettings.backgroundGradientPresetId.value
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
 | 
			
		||||
                    proto.appearance.clientThemeSettings ??= clientThemeSettingsDummy;
 | 
			
		||||
                    proto.appearance.clientThemeSettings.backgroundGradientPresetId = clientThemeSettingsDummy.backgroundGradientPresetId;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } catch (err) {
 | 
			
		||||
            new Logger("FakeNitro").error(err);
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue