diff --git a/src/components/external-plugin.js b/src/components/external-plugin.js index 8af19bc44c..f77bd778b1 100644 --- a/src/components/external-plugin.js +++ b/src/components/external-plugin.js @@ -9,7 +9,9 @@ const ExternalPlugin = ({ support, imageUrl, installed, - count + internalName, + count, + update }) => (
@@ -45,7 +47,21 @@ const ExternalPlugin = ({ {numberWithCommas(count)}{' '} {count > 1 ? 'active installs' : 'active install'} {' '} - {installed && installed} + {installed ? ( + + ) : ( + + )}

)}

diff --git a/src/modules/config.js b/src/modules/config.js index 676d539d8d..57aa92f5f8 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -15,7 +15,13 @@ const configNameFilters = [ ] // Actions -export const { fetchConfig, setConfig, changeAccount } = createActions( +export const { + fetchConfig, + updateConfig, + setConfig, + addModifiedKey, + changeAccount +} = createActions( { FETCH_CONFIG: () => async (dispatch, getState) => { const version = getLatestRelease(getState()) @@ -51,9 +57,37 @@ export const { fetchConfig, setConfig, changeAccount } = createActions( } return config + }, + UPDATE_CONFIG: (key, value) => async (dispatch, getState) => { + const version = getLatestRelease(getState()) + const uuid = getState().account.uuid + + if (!uuid) { + return {} + } + + if (value.length > 0) { + await runeliteApi(`runelite-${version}/config/${key}`, { + method: 'PUT', + headers: { + 'RUNELITE-AUTH': uuid + }, + body: value + }) + } else { + await runeliteApi(`runelite-${version}/config/${key}`, { + method: 'DELETE', + headers: { + 'RUNELITE-AUTH': uuid + } + }) + } + + dispatch(addModifiedKey(key)) } }, 'SET_CONFIG', + 'ADD_MODIFIED_KEY', 'CHANGE_ACCOUNT' ) @@ -67,10 +101,15 @@ export default handleActions( [changeAccount]: (state, { payload }) => ({ ...state, selectedAccount: payload + }), + [addModifiedKey]: (state, { payload }) => ({ + ...state, + modifiedKeys: [...new Set(state.modifiedKeys.concat([payload]))] }) }, { config: {}, + modifiedKeys: [], selectedAccount: '' } ) @@ -78,6 +117,7 @@ export default handleActions( // Selectors export const getConfig = state => state.config.config export const getSelectedAccount = state => state.config.selectedAccount +export const getModifiedKeys = state => state.config.modifiedKeys export const getAccounts = createSelector(getConfig, config => { const names = new Set() diff --git a/src/routes/plugin-hub.js b/src/routes/plugin-hub.js index 0379d93cad..3d2f89397f 100644 --- a/src/routes/plugin-hub.js +++ b/src/routes/plugin-hub.js @@ -17,7 +17,12 @@ import { setPluginSorting } from '../modules/plugin-hub' import SearchBar from '../components/search-bar' -import { fetchConfig } from '../modules/config' +import { + fetchConfig, + getExternalPlugins, + getModifiedKeys, + updateConfig +} from '../modules/config' import Choice from '../components/choice' import { numberWithCommas } from '../util' @@ -33,21 +38,44 @@ const handleChange = (event, setPluginFilter) => name: event.target.value }) +const handleUpdate = (updateConfig, fetchConfig, externalPlugins) => async ( + installed, + pluginName +) => { + if (installed) { + externalPlugins = externalPlugins.filter(i => i !== pluginName) + } else { + externalPlugins.push(pluginName) + } + + await updateConfig('runelite.externalPlugins', externalPlugins.join(',')) + await fetchConfig() +} + const PluginHub = ({ author, externalPlugins, + configExternalPlugins, pluginFilter, pluginSorting, setPluginFilter, - setPluginSorting + setPluginSorting, + updateConfig, + fetchConfig, + modifiedKeys }) => { - externalPlugins = externalPlugins.filter(plugin => + externalPlugins = [...externalPlugins].filter(plugin => author ? plugin.author === author : true ) const pluginCount = externalPlugins.length const installedPluginCount = externalPlugins.filter(p => p.installed).length const totalCount = externalPlugins.reduce((a, b) => a + b.count, 0) + const updateFunction = handleUpdate( + updateConfig, + fetchConfig, + configExternalPlugins + ) return ( @@ -110,9 +138,27 @@ const PluginHub = ({ />

+ {modifiedKeys.includes('runelite.externalPlugins') && ( +
+ + Warning + {' '} + Installing and uninstalling plugins through this interface + requires client restart. +
+ )}
{externalPlugins.map(plugin => ( - + ))}
@@ -124,8 +170,10 @@ const PluginHub = ({ const mapStateToProps = (state, props) => ({ ...props, externalPlugins: getSortedExternalPlugins(state), + configExternalPlugins: getExternalPlugins(state), pluginFilter: getPluginFilter(state), - pluginSorting: getPluginSorting(state) + pluginSorting: getPluginSorting(state), + modifiedKeys: getModifiedKeys(state) }) const mapDispatchToProps = dispatch => @@ -136,7 +184,8 @@ const mapDispatchToProps = dispatch => fetchExternalPlugins, fetchPluginHubStats, setPluginFilter, - setPluginSorting + setPluginSorting, + updateConfig }, dispatch ) diff --git a/src/store.js b/src/store.js index a407b27fbf..eb9983f0a1 100644 --- a/src/store.js +++ b/src/store.js @@ -16,7 +16,12 @@ export default callback => { // Add logger if (isDebug) { - middlewares.push(require('redux-logger').default) + const { createLogger } = require('redux-logger') + middlewares.push( + createLogger({ + diff: true + }) + ) } // Create reducer