2023-02-12 18:18:46 +08:00
|
|
|
import { NavigationNative, React, ReactNative } from "@vendetta/metro/common";
|
|
|
|
|
import { storage } from "@vendetta/plugin";
|
|
|
|
|
import { useProxy } from "@vendetta/storage";
|
2023-02-12 20:31:51 +08:00
|
|
|
import { getAssetIDByName } from "@vendetta/ui/assets";
|
2023-02-12 18:18:46 +08:00
|
|
|
import { Forms } from "@vendetta/ui/components";
|
|
|
|
|
|
2023-02-12 20:31:51 +08:00
|
|
|
import { currentSettings } from ".";
|
2023-02-12 21:32:36 +08:00
|
|
|
import Constants from "./constants";
|
2023-02-12 20:31:51 +08:00
|
|
|
import { flush, initialize } from "./utils";
|
|
|
|
|
|
|
|
|
|
const { ScrollView, TouchableOpacity, Text } = ReactNative;
|
|
|
|
|
const { FormInput, FormDivider, FormSwitchRow, FormText, FormIcon, FormTextColors } = Forms;
|
2023-02-12 16:33:21 +08:00
|
|
|
|
|
|
|
|
export default function Settings() {
|
2023-02-12 18:18:46 +08:00
|
|
|
const settings = useProxy(storage) as PluginSettings;
|
|
|
|
|
const navigation = NavigationNative.useNavigation();
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
navigation.setOptions({
|
|
|
|
|
headerRight: () => (
|
|
|
|
|
<TouchableOpacity onPress={() => {
|
|
|
|
|
for (const key in storage) {
|
2023-02-12 20:31:51 +08:00
|
|
|
if (typeof storage[key] === "boolean" || storage[key]) {
|
|
|
|
|
currentSettings[key] = settings[key];
|
|
|
|
|
}
|
2023-02-12 18:18:46 +08:00
|
|
|
}
|
2023-02-12 20:31:51 +08:00
|
|
|
|
|
|
|
|
console.log("Applying settings...");
|
|
|
|
|
flush().then(() => initialize());
|
2023-02-12 18:18:46 +08:00
|
|
|
}}>
|
|
|
|
|
<FormText style={{ marginRight: 12 }}>UPDATE</FormText>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
}, []);
|
|
|
|
|
|
2023-02-12 16:33:21 +08:00
|
|
|
return (
|
2023-02-12 18:18:46 +08:00
|
|
|
<ScrollView>
|
|
|
|
|
<FormInput
|
2023-02-12 20:31:51 +08:00
|
|
|
value={settings.appName || undefined}
|
2023-02-12 18:18:46 +08:00
|
|
|
onChangeText={(value: string) => settings.appName = value.trim()}
|
2023-02-12 20:31:51 +08:00
|
|
|
title="Discord Application Name"
|
2023-02-12 21:32:36 +08:00
|
|
|
placeholder={Constants.DEFAULT_APP_NAME}
|
2023-02-12 18:18:46 +08:00
|
|
|
returnKeyType="done"
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
2023-02-12 20:31:51 +08:00
|
|
|
<FormInput required
|
|
|
|
|
value={settings.username || undefined}
|
2023-02-12 18:18:46 +08:00
|
|
|
onChangeText={(value: string) => settings.username = value.trim()}
|
2023-02-12 20:31:51 +08:00
|
|
|
title="Last.fm username"
|
|
|
|
|
helpText={!settings.username && <Text style={{ color: "#FF0000" }}>{"This field is required!"}</Text>}
|
2023-02-12 18:18:46 +08:00
|
|
|
placeholder="wumpus123"
|
|
|
|
|
returnKeyType="done"
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
|
|
|
|
<FormSwitchRow
|
|
|
|
|
label="Show time elapsed"
|
|
|
|
|
subLabel="Show the time elapsed since the song started playing"
|
2023-02-12 20:31:51 +08:00
|
|
|
leading={<FormIcon source={getAssetIDByName("clock")} />}
|
2023-02-12 18:18:46 +08:00
|
|
|
value={settings.showTimestamp}
|
|
|
|
|
onValueChange={(value: boolean) => settings.showTimestamp = value}
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
|
|
|
|
<FormSwitchRow
|
|
|
|
|
label="Set status as listening"
|
|
|
|
|
subLabel='Set your status as "Listening to" instead of "Playing"'
|
2023-02-12 20:31:51 +08:00
|
|
|
leading={<FormIcon source={getAssetIDByName("ic_headset_neutral")} />}
|
2023-02-12 18:18:46 +08:00
|
|
|
value={settings.listeningTo}
|
|
|
|
|
onValueChange={(value: boolean) => settings.listeningTo = value}
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
|
|
|
|
<FormSwitchRow
|
|
|
|
|
label="Verbose logging"
|
|
|
|
|
subLabel="Log more information to the console for debugging purposes"
|
2023-02-12 20:31:51 +08:00
|
|
|
leading={<FormIcon source={getAssetIDByName("icon-qs-files")} />}
|
2023-02-12 18:18:46 +08:00
|
|
|
value={settings.verboseLogging}
|
|
|
|
|
onValueChange={(value: boolean) => settings.verboseLogging = value}
|
|
|
|
|
/>
|
|
|
|
|
</ScrollView>
|
2023-02-12 16:33:21 +08:00
|
|
|
)
|
|
|
|
|
}
|