2024-06-20 12:35:05 -04:00
|
|
|
/*
|
|
|
|
* Vencord, a Discord client mod
|
|
|
|
* Copyright (c) 2024 Vendicated and contributors
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2024-04-17 14:29:47 -04:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2022 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 { Link } from "@components/Link";
|
2024-06-06 03:30:30 -04:00
|
|
|
import { Devs, EquicordDevs } from "@utils/constants";
|
2024-04-17 14:29:47 -04:00
|
|
|
import { localStorage } from "@utils/localStorage";
|
|
|
|
import { closeAllModals, openModal } from "@utils/modal";
|
|
|
|
import definePlugin from "@utils/types";
|
|
|
|
import { findByProps } from "@webpack";
|
|
|
|
import { Button, FluxDispatcher, Forms, React, showToast, Toasts } from "@webpack/common";
|
|
|
|
|
|
|
|
import AppIconModal from "./AppIconModal";
|
|
|
|
|
|
|
|
function removeAppIcon() {
|
|
|
|
const current_icon = findByProps("getCurrentDesktopIcon").getCurrentDesktopIcon();
|
|
|
|
let icons = JSON.parse(localStorage.getItem("vc_app_icons") || "[]");
|
|
|
|
const index = icons.findIndex(icon => current_icon === icon.id);
|
|
|
|
if (index !== -1) {
|
|
|
|
icons = icons.filter(e => e.id !== current_icon);
|
2024-06-20 12:35:05 -04:00
|
|
|
delete findByProps("UZ", "QA").QA[current_icon];
|
|
|
|
delete findByProps("UZ", "QA").UZ[findByProps("UZ", "QA").UZ.findIndex((icon => current_icon === icon?.id))];
|
2024-04-17 14:29:47 -04:00
|
|
|
localStorage.setItem("vc_app_icons", JSON.stringify(icons));
|
|
|
|
showToast("Icon successfully deleted!", Toasts.Type.SUCCESS);
|
|
|
|
FluxDispatcher.dispatch({
|
|
|
|
type: "APP_ICON_UPDATED",
|
|
|
|
id: "AppIcon"
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
showToast("Cannot delete native App Icons!", Toasts.Type.FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
name: "CustomAppIcons",
|
|
|
|
description: "Add/upload custom (In-)App Icons.",
|
2024-06-06 03:30:30 -04:00
|
|
|
authors: [Devs.HappyEnderman, EquicordDevs.SerStars],
|
2024-04-17 14:29:47 -04:00
|
|
|
patches: [
|
|
|
|
{
|
2024-06-20 12:35:05 -04:00
|
|
|
find: /\i\.\i\.APP_ICON_UPSELL/,
|
2024-04-17 14:29:47 -04:00
|
|
|
replacement: [
|
|
|
|
{
|
|
|
|
match: /\w+\.jsx\)\(\w+,{markAsDismissed:\w+,isCoachmark:\w+}\)/,
|
|
|
|
replace(str) {
|
|
|
|
return str + ",$self.addButtons()";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
start() {
|
2024-06-01 14:32:22 -04:00
|
|
|
console.log("Well hello there!, CustomAppIcons has started :)");
|
2024-04-17 14:29:47 -04:00
|
|
|
const appIcons = JSON.parse(localStorage.getItem("vc_app_icons") ?? "[]");
|
|
|
|
for (const icon of appIcons) {
|
2024-06-20 12:35:05 -04:00
|
|
|
findByProps("UZ", "QA").UZ.push(icon);
|
|
|
|
findByProps("UZ", "QA").QA[icon.id] = icon;
|
2024-04-17 14:29:47 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
stop() {
|
|
|
|
|
|
|
|
},
|
|
|
|
addButtons() {
|
|
|
|
|
|
|
|
const { editorFooter } = findByProps("editorFooter");
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Button color={Button.Colors.BRAND_NEW} size={Button.Sizes.MEDIUM} className={editorFooter} onClick={() => {
|
|
|
|
openModal(props => <AppIconModal {...props} />);
|
|
|
|
}}>
|
|
|
|
Add Custom App Icon
|
|
|
|
</Button>
|
|
|
|
<Button color={Button.Colors.RED} size={Button.Sizes.MEDIUM} className={editorFooter} onClick={removeAppIcon}>
|
|
|
|
Remove Custom selected App Icon
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
settingsAboutComponent: () => {
|
|
|
|
return (
|
|
|
|
<><Forms.FormTitle>
|
|
|
|
<Forms.FormTitle>How to use?</Forms.FormTitle>
|
|
|
|
</Forms.FormTitle>
|
2024-06-20 12:35:05 -04:00
|
|
|
<Forms.FormText>
|
|
|
|
<Forms.FormText>Go to <Link href="/settings/appearance" onClick={e => { e.preventDefault(); closeAllModals(); FluxDispatcher.dispatch({ type: "USER_SETTINGS_MODAL_SET_SECTION", section: "Appearance" }); }}>Appearance Settings</Link> tab.</Forms.FormText>
|
|
|
|
<Forms.FormText>Scroll down to "In-app Icons" and click on "Preview App Icon".</Forms.FormText>
|
|
|
|
<Forms.FormText>And upload your own custom icon!</Forms.FormText>
|
|
|
|
<Forms.FormText>You can only use links when you are uploading your Custom Icon.</Forms.FormText>
|
|
|
|
</Forms.FormText></>
|
2024-04-17 14:29:47 -04:00
|
|
|
);
|
|
|
|
}
|
2024-04-18 19:15:01 -04:00
|
|
|
});
|