Add ignore list
Add support for ignore list, which may be easier to setup by people, so I dont need to add many as f*ck buttons to display settings
This commit is contained in:
parent
fd02080c2b
commit
fc3ff41838
2 changed files with 157 additions and 101 deletions
|
|
@ -65,65 +65,23 @@ class PluginManager {
|
||||||
let willUpdateRPC = false;
|
let willUpdateRPC = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// skip if Spotify is playing and user wants to ignore it
|
// Check if any ignored app is active
|
||||||
if (currentSettings.ignoreSpotify) {
|
if (currentSettings.ignoreList && currentSettings.ignoreList.length > 0) {
|
||||||
const spotifyActivity = SelfPresenceStore.findActivity(
|
const ignoredActivity = SelfPresenceStore.findActivity((act) => {
|
||||||
(act) => act.sync_id,
|
if (!act.name) return false;
|
||||||
);
|
return currentSettings.ignoreList.some((ignoredApp: string) =>
|
||||||
if (spotifyActivity) {
|
act.name.toLowerCase().includes(ignoredApp.toLowerCase()),
|
||||||
logVerbose("Spotify is currently playing, clearing activity");
|
);
|
||||||
setDebugInfo("isSpotifyIgnored", true);
|
});
|
||||||
|
|
||||||
|
if (ignoredActivity) {
|
||||||
|
logVerbose(
|
||||||
|
`Ignored app (${ignoredActivity.name}) is currently playing, clearing activity`,
|
||||||
|
);
|
||||||
|
// Remove these setDebugInfo calls that cause TypeScript errors
|
||||||
clearActivity();
|
clearActivity();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setDebugInfo("isSpotifyIgnored", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip if YouTube Music is playing and user wants to ignore it
|
|
||||||
if (currentSettings.ignoreYouTubeMusic) {
|
|
||||||
const YOUTUBE_MUSIC_APP_ID = "463097721130188830";
|
|
||||||
const PLUGIN_APP_ID = Constants.APPLICATION_ID;
|
|
||||||
|
|
||||||
const youtubeActivity = SelfPresenceStore.findActivity(
|
|
||||||
(act) =>
|
|
||||||
act.application_id === YOUTUBE_MUSIC_APP_ID &&
|
|
||||||
act.application_id !== PLUGIN_APP_ID,
|
|
||||||
);
|
|
||||||
if (youtubeActivity) {
|
|
||||||
logVerbose("YouTube Music is currently playing, clearing activity");
|
|
||||||
setDebugInfo("isYouTubeMusicIgnored", true);
|
|
||||||
clearActivity();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setDebugInfo("isYouTubeMusicIgnored", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip if Kizzy is playing and user wants to ignore it
|
|
||||||
if (currentSettings.ignoreKizzy) {
|
|
||||||
const kizzyActivity = SelfPresenceStore.findActivity(
|
|
||||||
(act) => act.name && act.name.toLowerCase() === "kizzy",
|
|
||||||
);
|
|
||||||
if (kizzyActivity) {
|
|
||||||
logVerbose("Kizzy is currently playing, clearing activity");
|
|
||||||
setDebugInfo("isKizzyIgnored", true);
|
|
||||||
clearActivity();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setDebugInfo("isKizzyIgnored", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip if Metrolist is playing and user wants to ignore it
|
|
||||||
if (currentSettings.ignoreMetrolist) {
|
|
||||||
const metrolistActivity = SelfPresenceStore.findActivity(
|
|
||||||
(act) => act.name && act.name.toLowerCase() === "metrolist",
|
|
||||||
);
|
|
||||||
if (metrolistActivity) {
|
|
||||||
logVerbose("Metrolist is currently playing, clearing activity");
|
|
||||||
setDebugInfo("isMetrolistIgnored", true);
|
|
||||||
clearActivity();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setDebugInfo("isMetrolistIgnored", false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
incrementApiCall();
|
incrementApiCall();
|
||||||
|
|
@ -175,7 +133,7 @@ class PluginManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
activityTimestamps = {
|
activityTimestamps = {
|
||||||
start: startTime * 1000, // Discord wants milliseconds
|
start: startTime * 1000,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (lastTrack.to) {
|
if (lastTrack.to) {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ plugin.storage.listenbrainzUsername ??= "";
|
||||||
plugin.storage.listenbrainzToken ??= "";
|
plugin.storage.listenbrainzToken ??= "";
|
||||||
plugin.storage.addToSidebar ??= false;
|
plugin.storage.addToSidebar ??= false;
|
||||||
plugin.storage.showLargeText ??= true;
|
plugin.storage.showLargeText ??= true;
|
||||||
plugin.storage.showLargeText ??= true;
|
plugin.storage.ignoreList ??= [];
|
||||||
|
|
||||||
const get = (k: string, fallback?: any) => plugin.storage[k] ?? fallback;
|
const get = (k: string, fallback?: any) => plugin.storage[k] ?? fallback;
|
||||||
const set = (k: string, v: any) => (plugin.storage[k] = v);
|
const set = (k: string, v: any) => (plugin.storage[k] = v);
|
||||||
|
|
@ -354,50 +354,112 @@ function DisplaySettingsPage() {
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
</TableRowGroup>
|
||||||
label="Ignore Spotify"
|
</Stack>
|
||||||
subLabel="Don't show activity when Spotify is playing"
|
<RN.View style={{ height: 64 }} />
|
||||||
value={get(
|
</ScrollView>
|
||||||
"ignoreSpotify",
|
);
|
||||||
Constants.DEFAULT_SETTINGS.ignoreSpotify,
|
}
|
||||||
)}
|
|
||||||
onValueChange={(value: boolean) => {
|
function IgnoreListSettingsPage() {
|
||||||
set("ignoreSpotify", value);
|
useProxy(plugin.storage);
|
||||||
forceUpdate();
|
const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
|
||||||
}}
|
const [newAppName, setNewAppName] = React.useState("");
|
||||||
|
|
||||||
|
const addAppToIgnoreList = () => {
|
||||||
|
if (!newAppName.trim()) {
|
||||||
|
showToast("Please enter an app name", getAssetIDByName("Small"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ignoreList = get("ignoreList", []);
|
||||||
|
if (!ignoreList.includes(newAppName.trim())) {
|
||||||
|
set("ignoreList", [...ignoreList, newAppName.trim()]);
|
||||||
|
setNewAppName("");
|
||||||
|
forceUpdate();
|
||||||
|
showToast("App added to ignore list", getAssetIDByName("Check"));
|
||||||
|
} else {
|
||||||
|
showToast("App already in ignore list", getAssetIDByName("Warning"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeAppFromIgnoreList = (appName: string) => {
|
||||||
|
const ignoreList = get("ignoreList", []);
|
||||||
|
set(
|
||||||
|
"ignoreList",
|
||||||
|
ignoreList.filter((app: string) => app !== appName),
|
||||||
|
);
|
||||||
|
forceUpdate();
|
||||||
|
showToast("App removed from ignore list", getAssetIDByName("Check"));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ padding: 10 }}>
|
||||||
|
<Stack spacing={8}>
|
||||||
|
<TableRowGroup title="Add App to Ignore">
|
||||||
|
<Stack spacing={4}>
|
||||||
|
<TextInput
|
||||||
|
placeholder="Enter app name"
|
||||||
|
value={newAppName}
|
||||||
|
onChange={setNewAppName}
|
||||||
|
isClearable
|
||||||
|
onSubmitEditing={addAppToIgnoreList}
|
||||||
|
returnKeyType="done"
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</TableRowGroup>
|
||||||
|
|
||||||
|
<TableRowGroup>
|
||||||
|
<TableRow
|
||||||
|
label="Add to Ignore List"
|
||||||
|
subLabel="Add the current app name to your ignore list"
|
||||||
|
trailing={<TableRow.Arrow />}
|
||||||
|
onPress={addAppToIgnoreList}
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
</TableRowGroup>
|
||||||
label="Ignore YouTube Music"
|
|
||||||
subLabel="Don't show activity when YouTube Music is playing (PC client)"
|
{get("ignoreList", []).length > 0 && (
|
||||||
value={get(
|
<TableRowGroup title="Ignored Apps">
|
||||||
"ignoreYouTubeMusic",
|
{get("ignoreList", []).map((appName: string, index: number) => (
|
||||||
Constants.DEFAULT_SETTINGS.ignoreYouTubeMusic,
|
<TableRow
|
||||||
)}
|
key={index}
|
||||||
onValueChange={(value: boolean) => {
|
label={appName}
|
||||||
set("ignoreYouTubeMusic", value);
|
trailing={
|
||||||
forceUpdate();
|
<RN.TouchableOpacity
|
||||||
}}
|
onPress={() => removeAppFromIgnoreList(appName)}
|
||||||
|
style={{
|
||||||
|
padding: 8,
|
||||||
|
backgroundColor: "#ff4d4d",
|
||||||
|
borderRadius: 12,
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<RN.Image
|
||||||
|
source={getAssetIDByName("TrashIcon")}
|
||||||
|
style={{ width: 14, height: 14, tintColor: "#ffffff" }}
|
||||||
|
/>
|
||||||
|
</RN.TouchableOpacity>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</TableRowGroup>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<TableRowGroup title="About Ignore List">
|
||||||
|
<TableRow
|
||||||
|
label="How it Works"
|
||||||
|
subLabel="When any app in your ignore list is active, your music status will be hidden"
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableRow
|
||||||
label="Ignore Kizzy"
|
label="Detection"
|
||||||
subLabel="Don't show activity when Kizzy is playing"
|
subLabel="Apps are detected by their Discord activity name"
|
||||||
value={get("ignoreKizzy", Constants.DEFAULT_SETTINGS.ignoreKizzy)}
|
|
||||||
onValueChange={(value: boolean) => {
|
|
||||||
set("ignoreKizzy", value);
|
|
||||||
forceUpdate();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableRow
|
||||||
label="Ignore Metrolist"
|
label="Examples"
|
||||||
subLabel="Don't show activity when Metrolist is playing"
|
subLabel="Spotify, YouTube Music, Kizzy, Metrolist, echo"
|
||||||
value={get(
|
|
||||||
"ignoreMetrolist",
|
|
||||||
Constants.DEFAULT_SETTINGS.ignoreMetrolist,
|
|
||||||
)}
|
|
||||||
onValueChange={(value: boolean) => {
|
|
||||||
set("ignoreMetrolist", value);
|
|
||||||
forceUpdate();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</TableRowGroup>
|
</TableRowGroup>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
@ -571,6 +633,17 @@ export default function Settings() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<TableRow
|
||||||
|
label="Ignore List"
|
||||||
|
subLabel="Configure apps that should hide your status"
|
||||||
|
trailing={<TableRow.Arrow />}
|
||||||
|
onPress={() =>
|
||||||
|
navigation.push("VendettaCustomPage", {
|
||||||
|
title: "Ignore List Settings",
|
||||||
|
render: IgnoreListSettingsPage,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
<TableRow
|
<TableRow
|
||||||
label="Logging Settings"
|
label="Logging Settings"
|
||||||
subLabel="Configure logging and debugging options"
|
subLabel="Configure logging and debugging options"
|
||||||
|
|
@ -584,8 +657,33 @@ export default function Settings() {
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="Add to Sidebar"
|
label="Add to Sidebar"
|
||||||
subLabel="Show plugin in Discord settings"
|
subLabel="Show plugin in Discord settings (may crash Discord)"
|
||||||
value={false}
|
value={get("addToSidebar", false)}
|
||||||
|
onValueChange={(value: boolean) => {
|
||||||
|
if (value) {
|
||||||
|
const { showConfirmationAlert } = window;
|
||||||
|
showConfirmationAlert({
|
||||||
|
title: "Warning: Potential Discord Crash",
|
||||||
|
content:
|
||||||
|
"Enabling 'Add to Sidebar' may cause Discord to crash or become unstable. This feature is experimental and not recommended.",
|
||||||
|
confirmText: "Enable Anyway",
|
||||||
|
cancelText: "Cancel",
|
||||||
|
confirmColor: "red",
|
||||||
|
onConfirm: () => {
|
||||||
|
set("addToSidebar", true);
|
||||||
|
forceUpdate();
|
||||||
|
showToast(
|
||||||
|
"Sidebar feature enabled - use with caution",
|
||||||
|
getAssetIDByName("Warning"),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onCancel: () => forceUpdate(),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
set("addToSidebar", false);
|
||||||
|
forceUpdate();
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</TableRowGroup>
|
</TableRowGroup>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue