Equicord/src/equicordplugins/holyNotes/index.tsx

135 lines
4.6 KiB
TypeScript
Raw Normal View History

2024-04-17 14:29:47 -04:00
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2024 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import "./style.css";
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { DataStore } from "@api/index";
2025-01-22 21:22:25 -05:00
import { addMessagePopoverButton, removeMessagePopoverButton } from "@api/MessagePopover";
2024-04-17 14:29:47 -04:00
import ErrorBoundary from "@components/ErrorBoundary";
2024-07-07 00:48:27 -04:00
import { EquicordDevs } from "@utils/constants";
2024-04-17 14:29:47 -04:00
import { classes } from "@utils/misc";
import { openModal } from "@utils/modal";
import definePlugin from "@utils/types";
2025-07-10 19:40:07 -04:00
import { Message } from "@vencord/discord-types";
2025-06-18 11:53:57 -04:00
import { findByCodeLazy, findByProps, findComponentByCodeLazy } from "@webpack";
2024-04-17 14:29:47 -04:00
import { ChannelStore, Menu } from "@webpack/common";
import { Popover as NoteButtonPopover, Popover } from "./components/icons/NoteButton";
import { NoteModal } from "./components/modals/Notebook";
2024-06-01 14:36:26 -04:00
import noteHandler, { noteHandlerCache } from "./NoteHandler";
2024-04-17 14:29:47 -04:00
import { DataStoreToCache, HolyNoteStore } from "./utils";
2025-06-16 15:13:02 -04:00
export const MessageType = findByCodeLazy("isEdited(){");
2025-03-25 11:33:48 -04:00
const HeaderBarIcon = findComponentByCodeLazy(".HEADER_BAR_BADGE_TOP:", '.iconBadge,"top"');
2024-04-17 14:29:47 -04:00
const messageContextMenuPatch: NavContextMenuPatchCallback = async (children, { message }: { message: Message; }) => {
children.push(
<Menu.MenuItem label="Add Message To" id="add-message-to-note">
{Object.keys(noteHandler.getAllNotes()).map((notebook: string, index: number) => (
<Menu.MenuItem
key={notebook}
2024-04-17 14:29:47 -04:00
label={notebook}
id={notebook}
action={() => noteHandler.addNote(message, notebook)}
/>
))}
</Menu.MenuItem>
);
};
function ToolBarHeader() {
const iconClasses = findByProps("iconWrapper", "clickable");
return (
<ErrorBoundary noop={true}>
<HeaderBarIcon
tooltip="Holy Notes"
position="bottom"
className={classes("vc-note-button", iconClasses.iconWrapper, iconClasses.clickable)}
icon={e => Popover(e)}
onClick={() => openModal(props => <NoteModal {...props} />)}
/>
</ErrorBoundary>
);
}
export default definePlugin({
name: "HolyNotes",
description: "Holy Notes allows you to save messages",
2024-07-07 00:48:27 -04:00
authors: [EquicordDevs.Wolfie],
2024-04-17 14:29:47 -04:00
dependencies: ["MessagePopoverAPI", "ChatInputButtonAPI"],
patches: [
{
2025-08-06 19:07:26 -04:00
find: ".controlButtonWrapper,",
2024-04-17 14:29:47 -04:00
replacement: {
match: /(function \i\(\i\){)(.{1,200}toolbar.{1,100}mobileToolbar)/,
replace: "$1$self.toolbarAction(arguments[0]);$2"
}
}
],
toolboxActions: {
async "Open Notes"() {
openModal(props => <NoteModal {...props} />);
}
},
contextMenus: {
"message": messageContextMenuPatch
},
toolbarAction(e) {
if (Array.isArray(e.toolbar))
2025-07-09 13:48:34 -04:00
return e.toolbar.unshift(
2024-04-17 14:29:47 -04:00
<ErrorBoundary noop={true}>
<ToolBarHeader />
</ErrorBoundary>
);
e.toolbar = [
<ErrorBoundary noop={true} key={"HolyNotes"}>
2024-04-17 14:29:47 -04:00
<ToolBarHeader />
</ErrorBoundary>,
e.toolbar,
];
},
async start() {
if (await DataStore.keys(HolyNoteStore).then(keys => !keys.includes("Main"))) return noteHandler.newNoteBook("Main");
if (!noteHandlerCache.has("Main")) await DataStoreToCache();
2025-01-22 21:22:25 -05:00
addMessagePopoverButton("HolyNotes", message => {
2024-04-17 14:29:47 -04:00
return {
label: "Save Note",
icon: NoteButtonPopover,
message: message,
channel: ChannelStore.getChannel(message.channel_id),
onClick: () => noteHandler.addNote(message, "Main")
};
});
},
async stop() {
2025-01-22 21:22:25 -05:00
removeMessagePopoverButton("HolyNotes");
2024-04-17 14:29:47 -04:00
}
});