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 }) => (
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 (