Last.fm: fix async function
This commit is contained in:
parent
85ef273cde
commit
c86e190274
3 changed files with 10 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
export default {
|
const Constants = {
|
||||||
|
DEFAULT_APP_NAME: "Music",
|
||||||
/** The application ID of the plugin */
|
/** The application ID of the plugin */
|
||||||
APPLICATION_ID: "1054951789318909972",
|
APPLICATION_ID: "1054951789318909972",
|
||||||
/** Last.fm api key */
|
/** Last.fm api key */
|
||||||
|
|
@ -9,3 +10,5 @@ export default {
|
||||||
"c6f59c1e5e7240a4c0d427abd71f3dbb",
|
"c6f59c1e5e7240a4c0d427abd71f3dbb",
|
||||||
]
|
]
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export default Constants;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { getAssetIDByName } from "@vendetta/ui/assets";
|
||||||
import { Forms } from "@vendetta/ui/components";
|
import { Forms } from "@vendetta/ui/components";
|
||||||
|
|
||||||
import { currentSettings } from ".";
|
import { currentSettings } from ".";
|
||||||
|
import Constants from "./constants";
|
||||||
import { flush, initialize } from "./utils";
|
import { flush, initialize } from "./utils";
|
||||||
|
|
||||||
const { ScrollView, TouchableOpacity, Text } = ReactNative;
|
const { ScrollView, TouchableOpacity, Text } = ReactNative;
|
||||||
|
|
@ -39,7 +40,7 @@ export default function Settings() {
|
||||||
value={settings.appName || undefined}
|
value={settings.appName || undefined}
|
||||||
onChangeText={(value: string) => settings.appName = value.trim()}
|
onChangeText={(value: string) => settings.appName = value.trim()}
|
||||||
title="Discord Application Name"
|
title="Discord Application Name"
|
||||||
placeholder="Music"
|
placeholder={Constants.DEFAULT_APP_NAME}
|
||||||
returnKeyType="done"
|
returnKeyType="done"
|
||||||
/>
|
/>
|
||||||
<FormDivider />
|
<FormDivider />
|
||||||
|
|
|
||||||
|
|
@ -83,11 +83,11 @@ export async function update() {
|
||||||
|
|
||||||
if (!currentSettings.username) {
|
if (!currentSettings.username) {
|
||||||
showToast("Last.fm username is not set!", getAssetIDByName("Small"));
|
showToast("Last.fm username is not set!", getAssetIDByName("Small"));
|
||||||
await flush(); // Flush as we always needs reinitialization
|
await flush(); // Flush as we always need reinitialization
|
||||||
throw new Error("Username is not set");
|
throw new Error("Username is not set");
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastTrack = await fetchLatestScrobble().catch(async (err) => {
|
const lastTrack = await fetchLatestScrobble().catch(async function (err) {
|
||||||
verboseLog("--> An error occurred while fetching the last track, aborting...");
|
verboseLog("--> An error occurred while fetching the last track, aborting...");
|
||||||
await clearActivity().catch();
|
await clearActivity().catch();
|
||||||
throw err;
|
throw err;
|
||||||
|
|
@ -106,7 +106,7 @@ export async function update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const activity = {
|
const activity = {
|
||||||
name: currentSettings.appName || "Music",
|
name: currentSettings.appName || Constants.DEFAULT_APP_NAME,
|
||||||
type: currentSettings.listeningTo ? 2 : 0,
|
type: currentSettings.listeningTo ? 2 : 0,
|
||||||
details: lastTrack.name,
|
details: lastTrack.name,
|
||||||
state: `by ${lastTrack.artist}`,
|
state: `by ${lastTrack.artist}`,
|
||||||
|
|
@ -128,7 +128,7 @@ export async function update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await sendRequest(activity).catch(async (err) => {
|
const response = await sendRequest(activity).catch(async function (err) {
|
||||||
verboseLog("--> An error occurred while setting the activity");
|
verboseLog("--> An error occurred while setting the activity");
|
||||||
await clearActivity().catch();
|
await clearActivity().catch();
|
||||||
throw err;
|
throw err;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue