summaryrefslogtreecommitdiff
path: root/frontend/src/hidden-plugins-service.tsx
diff options
context:
space:
mode:
authorWeblate <noreply@weblate.org>2023-06-08 14:40:08 +0000
committerWeblate <noreply@weblate.org>2023-06-08 14:40:08 +0000
commit89bbbf6fe4348236f9828a39ddc8f1790cb2f2f4 (patch)
treec175788ffc6917a66db810eb14073c57b750efb3 /frontend/src/hidden-plugins-service.tsx
parentfdc556edeed416843f3e4b9d5c1a9e163dc72d89 (diff)
parent9a05c228a004392df6921a7706f4ae6a62fff2d3 (diff)
downloaddecky-loader-89bbbf6fe4348236f9828a39ddc8f1790cb2f2f4.tar.gz
decky-loader-89bbbf6fe4348236f9828a39ddc8f1790cb2f2f4.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to 'frontend/src/hidden-plugins-service.tsx')
-rw-r--r--frontend/src/hidden-plugins-service.tsx34
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', []));
+ }
+}