/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2022 Sofia Lima
*
* 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 .
*/
import { Settings } from "@api/settings";
import { Link } from "@components/Link";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { filters, findByPropsLazy, mapMangledModuleLazy } from "@webpack";
import { FluxDispatcher, Forms } from "@webpack/common";
interface ActivityAssets {
large_image?: string;
large_text?: string;
small_image?: string;
small_text?: string;
}
interface Activity {
state: string;
details?: string;
timestamps?: {
start?: number;
};
assets?: ActivityAssets;
buttons?: Array;
name: string;
application_id: string;
metadata?: {
button_urls?: Array;
};
type: number;
flags: number;
}
interface TrackData {
name: string;
album: string;
artist: string;
url: string;
imageUrl?: string;
}
// only relevant enum values
enum ActivityType {
PLAYING = 0,
LISTENING = 2,
}
enum ActivityFlag {
INSTANCE = 1 << 0,
}
const applicationId = "1043533871037284423";
const presenceStore = findByPropsLazy("getLocalPresence");
const assetManager = mapMangledModuleLazy(
"getAssetImage: size must === [number, number] for Twitch",
{
getAsset: filters.byCode("apply("),
}
);
async function getApplicationAsset(key: string): Promise {
return (await assetManager.getAsset(applicationId, [key, undefined]))[0];
}
function setActivity(activity?: Activity) {
FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", activity: activity });
}
export default definePlugin({
name: "LastFMRichPresence",
description: "Little plugin for Last.fm rich presence",
authors: [Devs.dzshn],
settingsAboutComponent: () => (
<>
How to get an API key
An API key is required to fetch your current track. To get one, you can
visit this page and
fill in the following information: