Skip to content

Commit

Permalink
update beta translation toggle to dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Apr 10, 2024
1 parent 5182dbe commit eae8614
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
10 changes: 7 additions & 3 deletions src/backend/pythonMethods/pluginSettingsMethods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toast } from "../../python";
import { storeRead, toast } from "../../python";
import { server, globalState } from "../pythonRoot";
import { booleanStoreRead } from "./storeUtils";
import { booleanStoreRead, stringStoreRead } from "./storeUtils";

export function enableServer() {
return server!.callPluginMethod("enable_server", {});
Expand All @@ -25,7 +25,7 @@ export async function getWatchState() {
}

export async function getBetaTranslationsState() {
return booleanStoreRead("beta_translations");
return stringStoreRead("beta_translations");
}

export function toggleWatchState(bool: boolean, onlyThisSession: boolean = false) {
Expand All @@ -50,3 +50,7 @@ export function getHiddenMotd() {
key: "hiddenMotd",
});
}

export function fetchClassMappings() {
return server!.callPluginMethod<{}>("fetch_class_mappings", {});
}
20 changes: 20 additions & 0 deletions src/backend/pythonMethods/storeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,27 @@ export async function booleanStoreWrite(key: string, value: boolean) {
key,
val: value ? "1" : "0",
});
if (!deckyRes.success) {
toast(`Error setting ${key}`, deckyRes.result);
}
}

export async function stringStoreRead(key: string) {
const deckyRes = await server!.callPluginMethod<{ key: string }, string>("store_read", {
key,
});
if (!deckyRes.success) {
toast(`Error fetching ${key}`, deckyRes.result);
return "";
}
return deckyRes.result;
}
export async function stringStoreWrite(key: string, value: string) {
const deckyRes = await server!.callPluginMethod<{ key: string; val: string }>("store_write", {
key,
val: value,
});
if (!deckyRes.success) {
toast(`Error setting ${key}`, deckyRes.result);
}
}
35 changes: 21 additions & 14 deletions src/pages/settings/PluginSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Focusable, ToggleField } from "decky-frontend-lib";
import { DropdownItem, Focusable, ToggleField } from "decky-frontend-lib";
import { useMemo, useState, useEffect } from "react";
import { useCssLoaderState } from "../../state";
import { toast } from "../../python";
Expand All @@ -9,15 +9,16 @@ import {
enableServer,
toggleWatchState,
getBetaTranslationsState,
fetchClassMappings,
} from "../../backend/pythonMethods/pluginSettingsMethods";
import { booleanStoreWrite } from "../../backend/pythonMethods/storeUtils";
import { booleanStoreWrite, stringStoreWrite } from "../../backend/pythonMethods/storeUtils";
import { disableUnminifyMode, enableUnminifyMode } from "../../deckyPatches/UnminifyMode";

export function PluginSettings() {
const { navPatchInstance, unminifyModeOn, setGlobalState } = useCssLoaderState();
const [serverOn, setServerOn] = useState<boolean>(false);
const [watchOn, setWatchOn] = useState<boolean>(false);
const [betaTranslationsOn, setBetaTranslationsOn] = useState<boolean>(false);
const [betaTranslationsOn, setBetaTranslationsOn] = useState<string>("-1");

const navPatchEnabled = useMemo(() => !!navPatchInstance, [navPatchInstance]);

Expand All @@ -31,6 +32,10 @@ export function PluginSettings() {
}
async function fetchBetaTranslationsState() {
const value = await getBetaTranslationsState();
if (![!"0", "1", "-1"].includes(value)) {
setBetaTranslationsOn("-1");
return;
}
setBetaTranslationsOn(value);
}

Expand Down Expand Up @@ -60,23 +65,25 @@ export function PluginSettings() {
await fetchServerState();
}

async function setBetaTranslations(enabled: boolean) {
await booleanStoreWrite("beta_translations", enabled);
async function setBetaTranslations(value: string) {
await stringStoreWrite("beta_translations", value);
await fetchClassMappings();
await fetchBetaTranslationsState();
toast(
"Beta translations " + (enabled ? "enabled" : "disabled") + ".",
"Please restart your Deck to apply changes."
);
}

return (
<div>
<Focusable>
<ToggleField
checked={betaTranslationsOn}
label="Enable Beta Branch CSS Translations"
description="Enable this if you use Steam beta, as this will tell CSS Loader to use beta classnames"
onChange={setBetaTranslations}
<DropdownItem
rgOptions={[
{ data: "-1", label: "Auto-Detect" },
{ data: "0", label: "Force Stable" },
{ data: "1", label: "Force Beta" },
]}
selectedOption={betaTranslationsOn}
label="SteamOS Branch"
description="Choose the version of SteamOS you are on. This allows us to provide the correct translations for your system."
onChange={(data) => setBetaTranslations(data.data)}
/>
</Focusable>
<Focusable>
Expand Down

0 comments on commit eae8614

Please sign in to comment.