From c86e190274e6d3d57ab52cc043027bd0b6a17367 Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Sun, 12 Feb 2023 21:32:36 +0800 Subject: [PATCH] Last.fm: fix async function --- plugins/Last.fm/src/constants.ts | 5 ++++- plugins/Last.fm/src/settings.tsx | 3 ++- plugins/Last.fm/src/utils.ts | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/Last.fm/src/constants.ts b/plugins/Last.fm/src/constants.ts index 9211a02..7ed101e 100644 --- a/plugins/Last.fm/src/constants.ts +++ b/plugins/Last.fm/src/constants.ts @@ -1,4 +1,5 @@ -export default { +const Constants = { + DEFAULT_APP_NAME: "Music", /** The application ID of the plugin */ APPLICATION_ID: "1054951789318909972", /** Last.fm api key */ @@ -9,3 +10,5 @@ export default { "c6f59c1e5e7240a4c0d427abd71f3dbb", ] } as const; + +export default Constants; diff --git a/plugins/Last.fm/src/settings.tsx b/plugins/Last.fm/src/settings.tsx index efb5f07..5e6afbc 100644 --- a/plugins/Last.fm/src/settings.tsx +++ b/plugins/Last.fm/src/settings.tsx @@ -5,6 +5,7 @@ import { getAssetIDByName } from "@vendetta/ui/assets"; import { Forms } from "@vendetta/ui/components"; import { currentSettings } from "."; +import Constants from "./constants"; import { flush, initialize } from "./utils"; const { ScrollView, TouchableOpacity, Text } = ReactNative; @@ -39,7 +40,7 @@ export default function Settings() { value={settings.appName || undefined} onChangeText={(value: string) => settings.appName = value.trim()} title="Discord Application Name" - placeholder="Music" + placeholder={Constants.DEFAULT_APP_NAME} returnKeyType="done" /> diff --git a/plugins/Last.fm/src/utils.ts b/plugins/Last.fm/src/utils.ts index b865f7c..87b9214 100644 --- a/plugins/Last.fm/src/utils.ts +++ b/plugins/Last.fm/src/utils.ts @@ -83,11 +83,11 @@ export async function update() { if (!currentSettings.username) { 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"); } - 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..."); await clearActivity().catch(); throw err; @@ -106,7 +106,7 @@ export async function update() { } const activity = { - name: currentSettings.appName || "Music", + name: currentSettings.appName || Constants.DEFAULT_APP_NAME, type: currentSettings.listeningTo ? 2 : 0, details: lastTrack.name, 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"); await clearActivity().catch(); throw err;