import { plugin } from "@vendetta"; import { Forms } from "@vendetta/ui/components"; import { useProxy } from "@vendetta/storage"; import { getAssetIDByName } from "@vendetta/ui/assets"; import { showToast } from "@vendetta/ui/toasts"; import { React } from "@vendetta/metro/common"; import { ScrollView, View, Linking } from "react-native"; import { changelog, currentVersion } from "../../changelog"; import { findByProps } from "@vendetta/metro"; const { TableRowGroup, TableSwitchRow, Stack, TableRow } = findByProps( "TableSwitchRow", "TableRowGroup", "Stack", "TableRow", ); const { TextInput } = findByProps("TextInput"); import { currentSettings, pluginState } from "../.."; import Constants from "../../constants"; import { initialize } from "../../manager"; import { lastfmClient } from "../../utils/lastfm"; export default function Settings() { useProxy(currentSettings); const [loading, setLoading] = React.useState(false); const saveSettings = (key: string, value: any) => { currentSettings[key] = value; plugin.storage[key] = value; }; const testConnection = async () => { if (!currentSettings.username || !currentSettings.apiKey) { showToast( "Please enter both username and API key", getAssetIDByName("Small"), ); return; } setLoading(true); try { await lastfmClient.fetchLatestScrobble(); showToast("Connection successful!", getAssetIDByName("Check")); await initialize(); } catch (error) { showToast( `Connection failed: ${error.message}`, getAssetIDByName("Small"), ); } finally { setLoading(false); } }; return ( saveSettings("username", value)} /> saveSettings("apiKey", value)} secureTextEntry={true} /> Linking.openURL("https://www.last.fm/api/account/create") } /> : } onPress={testConnection} disabled={loading} /> saveSettings("appName", value)} /> { const interval = Number(value); if (interval >= Constants.MIN_UPDATE_INTERVAL) { saveSettings("timeInterval", interval); } else { showToast( `Minimum interval is ${Constants.MIN_UPDATE_INTERVAL} seconds`, getAssetIDByName("Small"), ); } }} keyboardType="numeric" /> saveSettings("listeningTo", value) } /> saveSettings("showTimestamp", value) } /> saveSettings("ignoreSpotify", value) } /> saveSettings("verboseLogging", value) } /> } onPress={() => { // You might want to implement a navigation to your ChangelogView here // For now, we'll open the GitHub URL Linking.openURL(Constants.GITHUB_COMMITS_URL); }} /> ); }