mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-17 02:17:03 -04:00
Add tracer, fix MessageActions slow startup
This commit is contained in:
parent
851d07f31a
commit
0af4579204
4 changed files with 87 additions and 21 deletions
|
@ -20,6 +20,7 @@ import Plugins from "~plugins";
|
|||
|
||||
import { registerCommand, unregisterCommand } from "../api/Commands";
|
||||
import { Settings } from "../api/settings";
|
||||
import { traceFunction } from "../debug/Tracer";
|
||||
import Logger from "../utils/logger";
|
||||
import { Patch, Plugin } from "../utils/types";
|
||||
|
||||
|
@ -43,12 +44,12 @@ for (const p of Object.values(Plugins))
|
|||
}
|
||||
}
|
||||
|
||||
export function startAllPlugins() {
|
||||
export const startAllPlugins = traceFunction("startAllPlugins", function startAllPlugins() {
|
||||
for (const name in Plugins)
|
||||
if (isPluginEnabled(name)) {
|
||||
startPlugin(Plugins[name]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export function startDependenciesRecursive(p: Plugin) {
|
||||
let restartNeeded = false;
|
||||
|
@ -70,7 +71,7 @@ export function startDependenciesRecursive(p: Plugin) {
|
|||
return { restartNeeded, failures };
|
||||
}
|
||||
|
||||
export function startPlugin(p: Plugin) {
|
||||
export const startPlugin = traceFunction("startPlugin", function startPlugin(p: Plugin) {
|
||||
if (p.start) {
|
||||
logger.info("Starting plugin", p.name);
|
||||
if (p.started) {
|
||||
|
@ -100,9 +101,9 @@ export function startPlugin(p: Plugin) {
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}, p => `startPlugin ${p.name}`);
|
||||
|
||||
export function stopPlugin(p: Plugin) {
|
||||
export const stopPlugin = traceFunction("stopPlugin", function stopPlugin(p: Plugin) {
|
||||
if (p.stop) {
|
||||
logger.info("Stopping plugin", p.name);
|
||||
if (!p.started) {
|
||||
|
@ -131,4 +132,4 @@ export function stopPlugin(p: Plugin) {
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}, p => `stopPlugin ${p.name}`);
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
*/
|
||||
|
||||
import { addClickListener, removeClickListener } from "../api/MessageEvents";
|
||||
import { lazyWebpack } from "../utils";
|
||||
import { Devs } from "../utils/constants";
|
||||
import definePlugin from "../utils/types";
|
||||
import { find, findByProps } from "../webpack";
|
||||
import { filters } from "../webpack";
|
||||
import { UserStore } from "../webpack/common";
|
||||
|
||||
let isDeletePressed = false;
|
||||
|
@ -33,10 +34,10 @@ export default definePlugin({
|
|||
dependencies: ["MessageEventsAPI"],
|
||||
|
||||
start() {
|
||||
const { deleteMessage, startEditMessage } = findByProps("deleteMessage", "startEditMessage");
|
||||
const { can } = findByProps("can", "initialize");
|
||||
const { MANAGE_MESSAGES } = find(m => typeof m.MANAGE_MESSAGES === "bigint");
|
||||
const { isEditing } = findByProps("isEditing", "isEditingAny");
|
||||
const MessageActions = lazyWebpack(filters.byProps("deleteMessage", "startEditMessage"));
|
||||
const PermissionStore = lazyWebpack(filters.byProps("can", "initialize"));
|
||||
const Permissions = lazyWebpack(m => typeof m.MANAGE_MESSAGES === "bigint");
|
||||
const EditStore = lazyWebpack(filters.byProps("isEditing", "isEditingAny"));
|
||||
|
||||
document.addEventListener("keydown", keydown);
|
||||
document.addEventListener("keyup", keyup);
|
||||
|
@ -44,12 +45,12 @@ export default definePlugin({
|
|||
this.onClick = addClickListener((msg, chan, event) => {
|
||||
const isMe = msg.author.id === UserStore.getCurrentUser().id;
|
||||
if (!isDeletePressed) {
|
||||
if (isMe && event.detail >= 2 && !isEditing(chan.id, msg.id)) {
|
||||
startEditMessage(chan.id, msg.id, msg.content);
|
||||
if (isMe && event.detail >= 2 && !EditStore.isEditing(chan.id, msg.id)) {
|
||||
MessageActions.startEditMessage(chan.id, msg.id, msg.content);
|
||||
event.preventDefault();
|
||||
}
|
||||
} else if (isMe || can(MANAGE_MESSAGES, chan)) {
|
||||
deleteMessage(chan.id, msg.id);
|
||||
} else if (isMe || PermissionStore.can(Permissions.MANAGE_MESSAGES, chan)) {
|
||||
MessageActions.deleteMessage(chan.id, msg.id);
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue