import BDV2 from "../modules/v2"; import V2C_SettingsTitle from "./settingsTitle"; import V2C_SettingsGroup from "./settingsGroup"; import dataStore from "../modules/dataStore"; import { defaultRPC, settingsRPC } from "../0globals"; import CustomRichPresence from "../modules/CustomRichPresence" import { remote } from "electron"; import MarginTop from "./margintop"; import Utils from "../modules/utils"; const React = BDV2.React; let V2C_PresenceSettingsModules export default class V2C_PresenceSettings extends React.Component { constructor(props) { super(props); this.state = { data: dataStore.getSettingGroup("rpc") || defaultRPC, assets: [] } this.preview = null this.isfetching = false if(this.state.data.application_id){ this.fetchAssets() } this.assetComponents = new Set() } updateWhenFetched(comp){ this.assetComponents.add(comp) } /** * * @param {InputText} setting */ onChange(setting, value){ let defaultSetting = RPCProps.find(e => e.id === setting.props.id) this.setState({ data: Object.assign(settingsRPC, this.state.data, { [defaultSetting.id]: !!value ? value : null }), assets: this.state.assets }) if(setting.props.id === "application_id"){ this.fetchAssets() } dataStore.setSettingGroup("rpc", settingsRPC); this.preview.forceUpdate() CustomRichPresence.set(settingsRPC) } fetchAssets(){ if(this.isfetching === true){ let app = this.state.data.application_id setTimeout(() => { if(this.state.data.application_id !== app){ return } this.fetchAssets() }, 5000); } if(!this.state.data.application_id){ this.setState({ data: this.state.data, assets: [] }) this.forceUpdate() this.assetComponents.forEach(e => e.forceUpdate()) return } this.isfetching = true CustomRichPresence.fetchAssets(this.state.data.application_id) .then(assets => { this.isfetching = false this.setState({ data: this.state.data, assets: Object.keys(assets).map(k => { let asset = assets[k] return { id: asset.id, name: asset.name, type: asset.type } }) }) this.forceUpdate() this.assetComponents.forEach(e => e.forceUpdate()) }).catch(() => { this.isfetching = false this.setState({ data: this.state.data, assets: [] }) this.forceUpdate() this.assetComponents.forEach(e => e.forceUpdate()) }) } updatePreview(data){ this.setState({ data }) } get modules(){ return V2C_PresenceSettingsModules || (V2C_PresenceSettingsModules = [ BDModules.get(e => e.marginBottom20)[0] ]) } render() { let [ marginModule ] = this.modules return [ , , ,
{/** options */} {this.optionsComponents}
,
{/** preview */}
,
, , ] } get optionsComponents(){ return this._optionsComponents || (this._optionsComponents = RPCProps.map(e => { if(e.type === "text"){ return }else if(e.type === "number"){ let array = []/* if(e.id === "timestamps.start"){ array.unshift( { DiscordNative.clipboard.copy(Date.now()+"") }} />) }*/ return array }else if(e.type === "choice"){ if(["assets.small", "assets.large"].includes(e.id)){ return { return { value: "asset-"+e.id, label: e.name } }))}/> }else{ return "Unknown choice." } } })) } } const RPCProps = [ { title: "Application ID", id: "application_id", type: "number", placeholder: "711416957718757418" }, { title: "Name", id: "name", type: "text", placeholder: "Lightcord" }, { title: "Details", id: "details", type: "text", placeholder: "Browsing Discord" }, { title: "State", id: "state", type: "text", placeholder: "Lightcord Client" }, { title: "Timestamp Start", id: "timestamps.start", type: "number", get placeholder(){ return Date.now() } }, { title: "LargeAsset", id: "assets.large", type: "choice" }, { title: "SmallAsset", id: "assets.small", type: "choice" }, ] let inputTextModules class InputText extends React.PureComponent { get modules(){ if(inputTextModules && inputTextModules[0])return inputTextModules return inputTextModules = [ BDModules.get(e => e.removeKeybind)[0], BDModules.get(e => e.marginBottom20)[0], BDModules.get(e => e.defaultMarginh5)[0], BDModules.get(e => e.colorStandard)[0], BDModules.get(e => e.size32)[0], BDModules.get(e => e._horizontal)[0], BDModules.get(e => e.inputMini)[0], BDModules.get(e => e.size16 && e.size20)[0], ] } constructor(props){ super(props) let setting = this.props.setting this.state = { data: this.props.manager.state.data[setting.id] } this.input = { this.setState({ data: value }) if(!this.lastEdited || this.lastEdited < Date.now() - 500){ this.props.manager.onChange(this, value) this.lastEdited = Date.now() }else if(!this.isTiming){ this.isTiming = setTimeout(() => { this.props.manager.onChange(this, this.state.data) this.isTiming = null this.lastEdited = Date.now() }, 500); } }} type="text"/> } render(){ let setting = this.props.setting let [ rowModule, marginModule, marginModule2, colorModule, sizeModule, flexModule, inputModule, sizeModule2, ] = this.modules return (
{setting.title}
{this.input}
) } } let InputNumberModules class InputNumber extends React.PureComponent { get modules(){ return InputNumberModules || (InputNumberModules = [ BDModules.get(e => e.removeKeybind)[0], BDModules.get(e => e.marginBottom20)[0], BDModules.get(e => e.defaultMarginh5)[0], BDModules.get(e => e.colorStandard)[0], BDModules.get(e => e.size32)[0], BDModules.get(e => e._horizontal)[0], BDModules.get(e => e.inputMini)[0], BDModules.get(e => e.size16 && e.size20)[0], BDModules.get(e => e.colorTransparent)[0], ]) } constructor(props){ super(props) let setting = this.props.setting this.state = { data: this.props.manager.state.data[setting.id] } this.input = { value = value.replace(/[^\d]+/g, "") if(value == this.state.data){ input.setValue(value) return } if(!this.lastEdited || this.lastEdited < Date.now() - 500){ this.props.manager.onChange(this, value) this.lastEdited = Date.now() }else if(!this.isTiming){ this.isTiming = setTimeout(() => { this.props.manager.onChange(this, this.state.data) this.isTiming = null this.lastEdited = Date.now() }, 500); } this.setState({ data: value }) }} type="text"/> } render(){ let setting = this.props.setting let [ rowModule, marginModule, marginModule2, colorModule, sizeModule, flexModule, ] = this.modules return (
{setting.title}
{this.input} {setting.id === "timestamps.start" ? { DiscordNative.clipboard.copy(Date.now()+"") }} color="brand">Copy current timestamp : null}
) } } let InputChoiceModules class InputChoice extends React.PureComponent { constructor(props){ super(props) let setting = this.props.setting this.state = { data: this.props.manager.state.data[setting.id] ? "asset-"+this.props.manager.state.data[setting.id] : "none" } this.props.manager.updateWhenFetched(this) } onChange(data){ let value = data.value if(!this.lastEdited || this.lastEdited < Date.now() - 500){ this.props.manager.onChange(this, value === "none" ? null : value.replace("asset-", "")) this.lastEdited = Date.now() }else if(!this.isTiming){ this.isTiming = setTimeout(() => { this.props.manager.onChange(this, this.state.data === "none" ? null : this.state.data.replace("asset-", "")) this.isTiming = null this.lastEdited = Date.now() }, 500); } this.setState({ data: value }) this.forceUpdate() } get modules(){ return InputChoiceModules || (InputChoiceModules = [ BDModules.get(e => e.removeKeybind)[0], BDModules.get(e => e.marginBottom20)[0], BDModules.get(e => e.defaultMarginh5)[0], BDModules.get(e => e.colorStandard)[0], BDModules.get(e => e.size32)[0], BDModules.get(e => e._horizontal)[0] ]) } render(){ let setting = this.props.setting let [ rowModule, marginModule, marginModule2, colorModule, sizeModule, flexModule ] = this.modules let options = this.props.manager.state.assets.map(e => { return { value: "asset-"+e.id, label: e.name } }) options.unshift({ value: "none", label: "No assets" }) return (
{setting.title}
{/*