feat(Last.fm): Hide when Spotify is running
This commit is contained in:
parent
168e4eb129
commit
14ee13b281
5 changed files with 31 additions and 2 deletions
|
|
@ -86,6 +86,14 @@ export default function Settings() {
|
|||
onValueChange={(value: boolean) => settings.listeningTo = value}
|
||||
/>
|
||||
<FormDivider />
|
||||
<FormSwitchRow
|
||||
label="Hide when Spotify is running"
|
||||
subLabel="Hide the status when a Spotify activity is detected"
|
||||
leading={<FormIcon source={getAssetIDByName("img_account_sync_spotify_light_and_dark")} />}
|
||||
value={settings.ignoreSpotify}
|
||||
onValueChange={(value: boolean) => settings.ignoreSpotify = value}
|
||||
/>
|
||||
<FormDivider />
|
||||
<FormSwitchRow
|
||||
label="Verbose logging"
|
||||
subLabel="Log more information to the console for debugging purposes"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const Constants = {
|
||||
DEFAULT_APP_NAME: "Music",
|
||||
DEFAULT_TIME_INTERVAL: 5,
|
||||
/** The application ID of the plugin */
|
||||
/** The application ID of the Discord's developer app */
|
||||
APPLICATION_ID: "1054951789318909972",
|
||||
/** Last.fm api key */
|
||||
LFM_API_KEY: "615322f0047e12aedbc610d9d71f7430",
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export const global = {} as {
|
|||
lastTrackUrl?: string,
|
||||
};
|
||||
|
||||
plugin.storage.ignoreSpotify ??= true;
|
||||
export const currentSettings = { ...plugin.storage } as PluginSettings;
|
||||
|
||||
// Discord modules that we need
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ type PluginSettings = {
|
|||
timeInterval: number;
|
||||
/** Whether or not to show "Listening to" */
|
||||
listeningTo: boolean;
|
||||
/** Ignore when Spotify is running */
|
||||
ignoreSpotify: boolean;
|
||||
/** Whether or not to show verbose logging */
|
||||
verboseLogging: boolean;
|
||||
};
|
||||
|
|
@ -29,6 +31,13 @@ type Activity = {
|
|||
assets?: ActivityAssets;
|
||||
};
|
||||
|
||||
enum ActivityType {
|
||||
PLAYING = 0,
|
||||
STREAMING = 1,
|
||||
LISTENING = 2,
|
||||
COMPETING = 5
|
||||
}
|
||||
|
||||
// The assets of the activity
|
||||
type ActivityAssets = {
|
||||
large_image?: string;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { findByProps } from "@vendetta/metro";
|
||||
import { findByProps, findByStoreName } from "@vendetta/metro";
|
||||
import { FluxDispatcher } from "@vendetta/metro/common";
|
||||
import { getAssetIDByName } from "@vendetta/ui/assets";
|
||||
import { showToast } from "@vendetta/ui/toasts";
|
||||
|
|
@ -6,6 +6,7 @@ import { currentSettings, global, verboseLog } from ".";
|
|||
import Constants from "./constants";
|
||||
|
||||
const AssetManager = findByProps("getAssetIds");
|
||||
const PresenceStore = findByStoreName("PresenceStore");
|
||||
|
||||
/** Fetches the latest user's scrobble */
|
||||
async function fetchLatestScrobble(): Promise<Track> {
|
||||
|
|
@ -98,6 +99,16 @@ async function update() {
|
|||
throw new Error("Username is not set");
|
||||
}
|
||||
|
||||
if (currentSettings.ignoreSpotify) {
|
||||
for (const activity of PresenceStore.getActivities()) {
|
||||
if (activity?.type === ActivityType.LISTENING && activity.application_id !== Constants.APPLICATION_ID) {
|
||||
verboseLog("--> Spotify is currently playing, aborting...");
|
||||
clearActivity();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const lastTrack = await fetchLatestScrobble().catch(async (err) => {
|
||||
verboseLog("--> An error occurred while fetching the last track, aborting...");
|
||||
clearActivity();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue