summaryrefslogtreecommitdiff
path: root/frontend/src/utils/hooks/useSetting.ts
diff options
context:
space:
mode:
authorTrainDoctor <traindoctor@protonmail.com>2022-09-01 13:46:49 -0700
committerGitHub <noreply@github.com>2022-09-01 13:46:49 -0700
commiteb439574becb9a82c283d513a98440d7c8efbafe (patch)
treeb2c0b16065f31cb2123c17622a6fe42a71cebf08 /frontend/src/utils/hooks/useSetting.ts
parent16a6e9b6a929dea4ad4607368e4e0c515ed15b61 (diff)
downloaddecky-loader-eb439574becb9a82c283d513a98440d7c8efbafe.tar.gz
decky-loader-eb439574becb9a82c283d513a98440d7c8efbafe.zip
Addition of proper branch slection (#168)
* This is a bit better, but branch selection still isn't working -_- * I'm the king of oversight * Selecting different branch checks for updates * Stable doesn't detect old versions, which indicates it doesn't work * Start adding deckyState for plugin updating * Few tweaks * Disable nightly selection * Update decky-frontend-lib and move useSetting set setting to async
Diffstat (limited to 'frontend/src/utils/hooks/useSetting.ts')
-rw-r--r--frontend/src/utils/hooks/useSetting.ts25
1 files changed, 11 insertions, 14 deletions
diff --git a/frontend/src/utils/hooks/useSetting.ts b/frontend/src/utils/hooks/useSetting.ts
index 2425ed16..f950bf6a 100644
--- a/frontend/src/utils/hooks/useSetting.ts
+++ b/frontend/src/utils/hooks/useSetting.ts
@@ -10,9 +10,8 @@ interface SetSettingArgs<T> {
value: T;
}
-export function useSetting<T>(key: string, def: T): [value: T | null, setValue: (value: T) => void] {
+export function useSetting<T>(key: string, def: T): [value: T | null, setValue: (value: T) => Promise<void>] {
const [value, setValue] = useState(def);
- const [ready, setReady] = useState<boolean>(false);
useEffect(() => {
(async () => {
@@ -20,20 +19,18 @@ export function useSetting<T>(key: string, def: T): [value: T | null, setValue:
key,
default: def,
} as GetSettingArgs<T>)) as { result: T };
- setReady(true);
setValue(res.result);
})();
}, []);
- useEffect(() => {
- if (ready)
- (async () => {
- await window.DeckyPluginLoader.callServerMethod('set_setting', {
- key,
- value,
- } as SetSettingArgs<T>);
- })();
- }, [value]);
-
- return [value, setValue];
+ return [
+ value,
+ async (val: T) => {
+ setValue(val);
+ await window.DeckyPluginLoader.callServerMethod('set_setting', {
+ key,
+ value: val,
+ } as SetSettingArgs<T>);
+ },
+ ];
}