diff options
| author | Andrew Moore <andrewm.finewolf@gmail.com> | 2024-02-14 23:45:55 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-14 20:45:55 -0800 |
| commit | 7d6b8805dfc3b38515bf9752d85bce8f2c992179 (patch) | |
| tree | 1f2d369c9ab25fe24738c4c8d228ed98244cc5c5 /frontend/src/frozen-plugins-service.tsx | |
| parent | 0dce3a8cbe5c1c26c26530a3879f0c2d2d50f9af (diff) | |
| download | decky-loader-7d6b8805dfc3b38515bf9752d85bce8f2c992179.tar.gz decky-loader-7d6b8805dfc3b38515bf9752d85bce8f2c992179.zip | |
[Feature] Freeze updates for devs (#582)v2.11.0-pre3
Diffstat (limited to 'frontend/src/frozen-plugins-service.tsx')
| -rw-r--r-- | frontend/src/frozen-plugins-service.tsx | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/frontend/src/frozen-plugins-service.tsx b/frontend/src/frozen-plugins-service.tsx new file mode 100644 index 00000000..fa43a99e --- /dev/null +++ b/frontend/src/frozen-plugins-service.tsx @@ -0,0 +1,49 @@ +import { DeckyState } from './components/DeckyState'; +import { PluginUpdateMapping } from './store'; +import { getSetting, setSetting } from './utils/settings'; + +/** + * A Service class for managing the state and actions related to the frozen plugins feature. + * + * It's mostly responsible for sending setting updates to the server and keeping the local state in sync. + */ +export class FrozenPluginService { + constructor(private deckyState: DeckyState) {} + + init() { + getSetting<string[]>('frozenPlugins', []).then((frozenPlugins) => { + this.deckyState.setFrozenPlugins(frozenPlugins); + }); + } + + /** + * Sends the new frozen plugins list to the server and persists it locally in the decky state + * + * @param frozenPlugins The new list of frozen plugins + */ + async update(frozenPlugins: string[]) { + await setSetting('frozenPlugins', frozenPlugins); + this.deckyState.setFrozenPlugins(frozenPlugins); + + // Remove pending updates for frozen plugins + const updates = this.deckyState.publicState().updates; + + if (updates) { + const filteredUpdates = new Map() as PluginUpdateMapping; + updates.forEach((v, k) => { + if (!frozenPlugins.includes(k)) { + filteredUpdates.set(k, v); + } + }); + + this.deckyState.setUpdates(filteredUpdates); + } + } + + /** + * Refreshes the state of frozen plugins in the local state + */ + async invalidate() { + this.deckyState.setFrozenPlugins(await getSetting('frozenPlugins', [])); + } +} |
