mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 07:25:10 +00:00
minor improvements and fixes for plugin migration
Co-authored-by: sadan4 <117494111+sadan4@users.noreply.github.com>
This commit is contained in:
parent
569d12f9e7
commit
f0bf8ab2e9
3 changed files with 41 additions and 18 deletions
|
@ -23,7 +23,14 @@ import { addContextMenuPatch, removeContextMenuPatch } from "@api/ContextMenu";
|
||||||
import { addMemberListDecorator, removeMemberListDecorator } from "@api/MemberListDecorators";
|
import { addMemberListDecorator, removeMemberListDecorator } from "@api/MemberListDecorators";
|
||||||
import { addMessageAccessory, removeMessageAccessory } from "@api/MessageAccessories";
|
import { addMessageAccessory, removeMessageAccessory } from "@api/MessageAccessories";
|
||||||
import { addMessageDecoration, removeMessageDecoration } from "@api/MessageDecorations";
|
import { addMessageDecoration, removeMessageDecoration } from "@api/MessageDecorations";
|
||||||
import { addMessageClickListener, addMessagePreEditListener, addMessagePreSendListener, removeMessageClickListener, removeMessagePreEditListener, removeMessagePreSendListener } from "@api/MessageEvents";
|
import {
|
||||||
|
addMessageClickListener,
|
||||||
|
addMessagePreEditListener,
|
||||||
|
addMessagePreSendListener,
|
||||||
|
removeMessageClickListener,
|
||||||
|
removeMessagePreEditListener,
|
||||||
|
removeMessagePreSendListener
|
||||||
|
} from "@api/MessageEvents";
|
||||||
import { addMessagePopoverButton, removeMessagePopoverButton } from "@api/MessagePopover";
|
import { addMessagePopoverButton, removeMessagePopoverButton } from "@api/MessagePopover";
|
||||||
import { Settings, SettingsStore } from "@api/Settings";
|
import { Settings, SettingsStore } from "@api/Settings";
|
||||||
import { disableStyle, enableStyle } from "@api/Styles";
|
import { disableStyle, enableStyle } from "@api/Styles";
|
||||||
|
@ -149,6 +156,27 @@ for (const p of pluginsValues) {
|
||||||
const def = p.settings.def[name];
|
const def = p.settings.def[name];
|
||||||
const checks = p.settings.checks?.[name];
|
const checks = p.settings.checks?.[name];
|
||||||
p.options[name] = { ...def, ...checks };
|
p.options[name] = { ...def, ...checks };
|
||||||
|
|
||||||
|
if (
|
||||||
|
(def.type === OptionType.ARRAY || def.type === OptionType.USERS || def.type === OptionType.GUILDS || def.type === OptionType.CHANNELS)
|
||||||
|
&& typeof p.settings.store[name] === "string"
|
||||||
|
) {
|
||||||
|
if (p.settings.store[name] === "")
|
||||||
|
p.settings.store[name] = def.default ?? [];
|
||||||
|
else {
|
||||||
|
logger.info(`Converting string values of setting ${name} of plugin ${p.name} to array`);
|
||||||
|
|
||||||
|
const sep = def.oldStringSeparator ?? ",";
|
||||||
|
let newVal: string[];
|
||||||
|
if (typeof sep === "string" || sep instanceof RegExp) newVal = p.settings.store[name].split(sep);
|
||||||
|
else newVal = sep(p.settings.store[name]);
|
||||||
|
|
||||||
|
// additional safeguard to prevent the new array to be an empty string, looks weird in the UI.
|
||||||
|
if (newVal.length > 1 || newVal[0] !== "") p.settings.store[name] = newVal;
|
||||||
|
else p.settings.store[name] = [];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,25 +283,11 @@ export function subscribeAllPluginsFluxEvents(fluxDispatcher: typeof FluxDispatc
|
||||||
|
|
||||||
export const startPlugin = traceFunction("startPlugin", function startPlugin(p: Plugin) {
|
export const startPlugin = traceFunction("startPlugin", function startPlugin(p: Plugin) {
|
||||||
const {
|
const {
|
||||||
name, commands, contextMenus, settings, managedStyle, userProfileBadge,
|
name, commands, contextMenus, managedStyle, userProfileBadge,
|
||||||
onBeforeMessageEdit, onBeforeMessageSend, onMessageClick,
|
onBeforeMessageEdit, onBeforeMessageSend, onMessageClick,
|
||||||
renderChatBarButton, renderMemberListDecorator, renderMessageAccessory, renderMessageDecoration, renderMessagePopoverButton
|
renderChatBarButton, renderMemberListDecorator, renderMessageAccessory, renderMessageDecoration, renderMessagePopoverButton
|
||||||
} = p;
|
} = p;
|
||||||
|
|
||||||
if (settings != null)
|
|
||||||
for (const setting of Object.keys(settings.def)) {
|
|
||||||
const { type } = settings.def[setting];
|
|
||||||
if (type === OptionType.ARRAY || type === OptionType.USERS || type === OptionType.GUILDS || type === OptionType.CHANNELS) {
|
|
||||||
if (typeof settings.store[setting] === "string") {
|
|
||||||
logger.info(`Converting string values of setting ${setting} of plugin ${name} to array`);
|
|
||||||
|
|
||||||
const sep = settings.def[setting].oldStringSeparator ?? ",";
|
|
||||||
if (typeof sep === "string") settings.store[setting] = settings.store[setting].split(sep);
|
|
||||||
else settings.store[setting] = sep(settings.store[setting]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p.start) {
|
if (p.start) {
|
||||||
logger.info("Starting plugin", name);
|
logger.info("Starting plugin", name);
|
||||||
if (p.started) {
|
if (p.started) {
|
||||||
|
|
|
@ -45,7 +45,14 @@ const settings = definePluginSettings({
|
||||||
additionalQuotes: {
|
additionalQuotes: {
|
||||||
description: "Additional custom quotes to possibly appear",
|
description: "Additional custom quotes to possibly appear",
|
||||||
type: OptionType.ARRAY,
|
type: OptionType.ARRAY,
|
||||||
oldStringSeparator: "|",
|
oldStringSeparator: s => {
|
||||||
|
if ("additionalQuotesDelimiter" in settings.store) {
|
||||||
|
const deli = settings.store.additionalQuotesDelimiter ?? "|";
|
||||||
|
delete settings.store.additionalQuotesDelimiter;
|
||||||
|
return s.split(deli);
|
||||||
|
}
|
||||||
|
return s.split("|");
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -315,10 +315,12 @@ export interface PluginSettingArrayDef {
|
||||||
/**
|
/**
|
||||||
* The text to show in the context-menu.
|
* The text to show in the context-menu.
|
||||||
* If not specified, the setting name will be used.
|
* If not specified, the setting name will be used.
|
||||||
|
* Only applies to User, Channel, and Guild arrays.
|
||||||
*/
|
*/
|
||||||
popoutText?: string;
|
popoutText?: string;
|
||||||
/**
|
/**
|
||||||
* If the context-menu entry should be hidden.
|
* If the context-menu entry should be hidden.
|
||||||
|
* Only applies to User, Channel, and Guild arrays.
|
||||||
*/
|
*/
|
||||||
hidePopout?: boolean;
|
hidePopout?: boolean;
|
||||||
default?: any[];
|
default?: any[];
|
||||||
|
@ -326,7 +328,7 @@ export interface PluginSettingArrayDef {
|
||||||
* If the setting used to be a string with a custom delimiter, you can specify the delimiter or a function to split the string
|
* If the setting used to be a string with a custom delimiter, you can specify the delimiter or a function to split the string
|
||||||
* @default ","
|
* @default ","
|
||||||
*/
|
*/
|
||||||
oldStringSeparator?: string | ((value: string) => string[]);
|
oldStringSeparator?: string | ((value: string) => string[]) | RegExp;
|
||||||
|
|
||||||
onChange?(newValue: any[]): void;
|
onChange?(newValue: any[]): void;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue