Skip to content

Commit 75e92c9

Browse files
committed
add dump mappings
1 parent 11fbbc9 commit 75e92c9

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/backend/services/backend-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ export class Backend {
114114
async getMappings() {
115115
return Backend.repository.call<[], object>("get_webpack_mappings", []);
116116
}
117+
async saveMappings(string: string) {
118+
return Backend.repository.call<[string], void>("save_mappings", [string]);
119+
}
117120

118121
toast(title: string, body?: string) {
119122
Backend.repository.toast(title, body);

src/decky-patches/decky-patch-store.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Patch } from "@decky/ui";
1+
import { classModuleMap, Patch } from "@decky/ui";
22
import type { Backend } from "@cssloader/backend";
33
import { createStore, useStore } from "zustand";
44
import { disableNavPatch, enableNavPatch } from "./nav-patch";
@@ -16,6 +16,7 @@ interface DeckyPatchStoreActions {
1616
deactivate: () => Promise<void>;
1717
setNavPatchState: (value: boolean, shouldToast?: boolean) => void;
1818
setUnminifyModeState: (value: boolean, shouldToast?: boolean) => Promise<void>;
19+
dumpMappings: () => Promise<void>;
1920
}
2021

2122
export interface IDeckyPatchState extends DeckyPatchStoreActions, DeckyPatchStoreValues {}
@@ -70,6 +71,15 @@ const createDeckyPatchStore = (backend: Backend) =>
7071
}
7172
shouldToast && backend.toast("Unminify Mode", enabled ? "Enabled" : "Disabled");
7273
},
74+
dumpMappings: async () => {
75+
try {
76+
const map = classModuleMap;
77+
const jsonStr = JSON.stringify(Object.fromEntries(map));
78+
await backend.saveMappings(jsonStr);
79+
} catch (error) {
80+
console.error("ERROR SAVING MAPPINGS", error);
81+
}
82+
},
7383
}));
7484

7585
const deckyPatchState = createDeckyPatchStore(backend);

src/modules/settings/plugin/PluginSettingsPage.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { useCSSLoaderActions, useCSSLoaderValues } from "@/backend";
22
import { useDeckyPatchStateActions, useDeckyPatchStateValues } from "@/decky-patches";
3-
import { DropdownItem, Focusable, ToggleField } from "@decky/ui";
3+
import { ButtonItem, DropdownItem, Focusable, ToggleField } from "@decky/ui";
44

55
export function PluginSettingsPage() {
66
const { serverState, watchState, translationsBranch } = useCSSLoaderValues();
77
const { setServerState, setWatchState, setTranslationBranch } = useCSSLoaderActions();
88

99
const { unminifyModeOn, navPatchInstance } = useDeckyPatchStateValues();
10-
const { setNavPatchState, setUnminifyModeState } = useDeckyPatchStateActions();
10+
const { setNavPatchState, setUnminifyModeState, dumpMappings } = useDeckyPatchStateActions();
1111
return (
1212
<Focusable>
1313
<Focusable>
@@ -57,6 +57,9 @@ export function PluginSettingsPage() {
5757
onChange={(value) => setUnminifyModeState(value, true)}
5858
/>
5959
</Focusable>
60+
<Focusable>
61+
<ButtonItem label="Dump Mappings" onClick={dumpMappings} />
62+
</Focusable>
6063
</Focusable>
6164
);
6265
}

0 commit comments

Comments
 (0)