diff options
| author | Jonas Dellinger <jonas@dellinger.dev> | 2023-06-07 07:35:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-06 22:35:05 -0700 |
| commit | 47bc910a8482d3d2cc882e28e862ca5ad61063b6 (patch) | |
| tree | acc75a2892150df5fd0d151d46d8f75caa062504 /frontend/src/hidden-plugins-service.tsx | |
| parent | 1c6270ccd67f271968a3ab8a30c29f19548765f0 (diff) | |
| download | decky-loader-47bc910a8482d3d2cc882e28e862ca5ad61063b6.tar.gz decky-loader-47bc910a8482d3d2cc882e28e862ca5ad61063b6.zip | |
Add functionality to hide plugins from quick access menu (#468)
Diffstat (limited to 'frontend/src/hidden-plugins-service.tsx')
| -rw-r--r-- | frontend/src/hidden-plugins-service.tsx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/frontend/src/hidden-plugins-service.tsx b/frontend/src/hidden-plugins-service.tsx new file mode 100644 index 00000000..0501c453 --- /dev/null +++ b/frontend/src/hidden-plugins-service.tsx @@ -0,0 +1,34 @@ +import { DeckyState } from './components/DeckyState'; +import { getSetting, setSetting } from './utils/settings'; + +/** + * A Service class for managing the state and actions related to the hidden plugins feature + * + * It's mostly responsible for sending setting updates to the server and keeping the local state in sync. + */ +export class HiddenPluginsService { + constructor(private deckyState: DeckyState) {} + + init() { + getSetting<string[]>('hiddenPlugins', []).then((hiddenPlugins) => { + this.deckyState.setHiddenPlugins(hiddenPlugins); + }); + } + + /** + * Sends the new hidden plugins list to the server and persists it locally in the decky state + * + * @param hiddenPlugins The new list of hidden plugins + */ + async update(hiddenPlugins: string[]) { + await setSetting('hiddenPlugins', hiddenPlugins); + this.deckyState.setHiddenPlugins(hiddenPlugins); + } + + /** + * Refreshes the state of hidden plugins in the local state + */ + async invalidate() { + this.deckyState.setHiddenPlugins(await getSetting('hiddenPlugins', [])); + } +} |
