Skip to content

Commit a6be3b0

Browse files
authored
Enable objdiff tab by default & add diff tab option (#1778)
* Enable objdiff tab by default & add diff tab option * biome format --fix
1 parent 64bf5ea commit a6be3b0

File tree

7 files changed

+86
-44
lines changed

7 files changed

+86
-44
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ FRONTEND_USE_IMAGE_PROXY=true
1010
FRONTEND_PWA=off
1111
SESSION_COOKIE_AGE=7776000
1212
PYTHONPATH=backend
13-
OBJDIFF_BASE=https://diff.decomp.dev/
13+
OBJDIFF_BASE=https://diff.decomp.me/
1414
#OBJDIFF_BASE=http://localhost:3000/

frontend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ENV NEXT_PUBLIC_SENTRY_DSN=${NEXT_PUBLIC_SENTRY_DSN}
3939
ARG GITHUB_CLIENT_ID=9c5d3c7ca624a23b7c1c
4040
ENV GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
4141

42-
ARG OBJDIFF_BASE=https://diff.decomp.dev/
42+
ARG OBJDIFF_BASE=https://diff.decomp.me/
4343
ENV OBJDIFF_BASE=${OBJDIFF_BASE}
4444

4545
# allows for cache busting even if only backend changed

frontend/src/app/(navfooter)/settings/editor/EditorSettings.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
useLanguageServerEnabled,
1111
useVimModeEnabled,
1212
useThreeWayDiffBase,
13-
useObjdiffClientEnabled,
13+
useDefaultDiffTab,
14+
DefaultDiffTab,
1415
} from "@/lib/settings";
1516

1617
import Checkbox from "../Checkbox";
@@ -28,8 +29,7 @@ export default function EditorSettings() {
2829
useLanguageServerEnabled();
2930
const [vimModeEnabled, setVimModeEnabled] = useVimModeEnabled();
3031
const [threeWayDiffBase, setThreeWayDiffBase] = useThreeWayDiffBase();
31-
const [objdiffClientEnabled, setObjdiffClientEnabled] =
32-
useObjdiffClientEnabled();
32+
const [defaultDiffTab, setDefaultDiffTab] = useDefaultDiffTab();
3333

3434
const [downloadingLanguageServer, setDownloadingLanguageServer] =
3535
useState(false);
@@ -77,6 +77,15 @@ export default function EditorSettings() {
7777
},
7878
};
7979

80+
const defaultDiffTabOptions = {
81+
[DefaultDiffTab.ASM_DIFFER]: {
82+
label: "asm-differ",
83+
},
84+
[DefaultDiffTab.OBJDIFF]: {
85+
label: "objdiff",
86+
},
87+
};
88+
8089
return (
8190
<>
8291
<Section title="Automatic compilation">
@@ -113,6 +122,19 @@ export default function EditorSettings() {
113122
options={threeWayDiffOptions}
114123
/>
115124
</Section>
125+
<Section title="Default diff tab">
126+
<div className="text-gray-11">
127+
Choose which diff tool should be shown by default when
128+
viewing a scratch.
129+
</div>
130+
<RadioList
131+
value={defaultDiffTab}
132+
onChange={(value: string) => {
133+
setDefaultDiffTab(value as DefaultDiffTab);
134+
}}
135+
options={defaultDiffTabOptions}
136+
/>
137+
</Section>
116138
<Section title="Match progress bar">
117139
<Checkbox
118140
checked={matchProgressBarEnabled}
@@ -143,14 +165,6 @@ export default function EditorSettings() {
143165
description="Enable vim bindings in the scratch editor"
144166
/>
145167
</Section>
146-
<Section title="Experiments">
147-
<Checkbox
148-
checked={objdiffClientEnabled}
149-
onChange={setObjdiffClientEnabled}
150-
label="Enable objdiff integration [alpha]"
151-
description="Enable objdiff tab in the scratch editor. Still under development."
152-
/>
153-
</Section>
154168
</>
155169
);
156170
}

frontend/src/components/Diff/ObjdiffPanel.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ export default function ObjdiffPanel({
111111
}, [objdiffFrame.current, isDark, colors, codeFont, codeFontSize]);
112112

113113
const url = useMemo(() => {
114-
return `${process.env.OBJDIFF_BASE}?theme=${
115-
isDark ? "decomp-me-dark" : "decomp-me-light"
116-
}`;
114+
const url = new URL(process.env.OBJDIFF_BASE, window.location.href);
115+
url.searchParams.set(
116+
"theme",
117+
isDark ? "decomp-me-dark" : "decomp-me-light",
118+
);
119+
return url.toString();
117120
}, []);
118121

119122
return (

frontend/src/components/Scratch/Scratch.tsx

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import {
1414
useLanguageServerEnabled,
1515
useVimModeEnabled,
1616
useMatchProgressBarEnabled,
17-
useObjdiffClientEnabled,
17+
useDefaultDiffTab,
18+
DefaultDiffTab,
1819
} from "@/lib/settings";
1920

2021
import CompilerOpts from "../compiler/CompilerOpts";
2122
import CustomLayout, {
2223
activateTabInLayout,
2324
type Layout,
25+
visitLayout,
2426
} from "../CustomLayout";
2527
import CompilationPanel from "../Diff/CompilationPanel";
2628
import CodeMirror from "../Editor/CodeMirror";
@@ -121,6 +123,24 @@ function getDefaultLayout(
121123
return "mobile_2row";
122124
}
123125

126+
function cloneValue<T>(layout: T): T {
127+
return JSON.parse(JSON.stringify(layout)) as T;
128+
}
129+
130+
function applyDefaultDiffTab(
131+
layout: Layout,
132+
defaultDiffTab: DefaultDiffTab,
133+
): Layout {
134+
const preferredTab =
135+
defaultDiffTab === DefaultDiffTab.OBJDIFF ? TabId.OBJDIFF : TabId.DIFF;
136+
visitLayout(layout, (node) => {
137+
if (node.kind === "pane" && node.tabs.includes(preferredTab)) {
138+
node.activeTab = preferredTab;
139+
}
140+
});
141+
return layout;
142+
}
143+
124144
export type Props = {
125145
scratch: Readonly<api.Scratch>;
126146
onChange: (scratch: Partial<api.Scratch>) => void;
@@ -150,6 +170,7 @@ export default function Scratch({
150170
const [autoRecompileDelaySetting] = useAutoRecompileDelaySetting();
151171
const [languageServerEnabledSetting] = useLanguageServerEnabled();
152172
const [matchProgressBarEnabledSetting] = useMatchProgressBarEnabled();
173+
const [defaultDiffTab] = useDefaultDiffTab();
153174
const { compilation, isCompiling, isCompilationOld, compile } =
154175
api.useCompilation(
155176
scratch,
@@ -210,15 +231,13 @@ export default function Scratch({
210231
useEffect(() => {
211232
if (decompilationTabEnabled) {
212233
setLayout((layout) => {
213-
const clone = { ...layout };
234+
const clone = cloneValue(layout);
214235
activateTabInLayout(clone, TabId.DECOMPILATION);
215236
return clone;
216237
});
217238
}
218239
}, [decompilationTabEnabled]);
219240

220-
const [objdiffClientEnabled] = useObjdiffClientEnabled();
221-
222241
// If the version of the scratch changes, refresh code editors
223242
useEffect(() => {
224243
incrementValueVersion();
@@ -378,22 +397,20 @@ export default function Scratch({
378397
);
379398
case TabId.OBJDIFF:
380399
return (
381-
objdiffClientEnabled && (
382-
<Tab
383-
key={id}
384-
tabKey={id}
385-
label="objdiff [alpha]"
386-
className={styles.diffTab}
387-
>
388-
{compilation && (
389-
<ObjdiffPanel
390-
scratch={scratch}
391-
compilation={compilation}
392-
buildRunning={isCompiling}
393-
/>
394-
)}
395-
</Tab>
396-
)
400+
<Tab
401+
key={id}
402+
tabKey={id}
403+
label="objdiff"
404+
className={styles.diffTab}
405+
>
406+
{compilation && (
407+
<ObjdiffPanel
408+
scratch={scratch}
409+
compilation={compilation}
410+
buildRunning={isCompiling}
411+
/>
412+
)}
413+
</Tab>
397414
);
398415
case TabId.DECOMPILATION:
399416
return (
@@ -435,7 +452,12 @@ export default function Scratch({
435452

436453
if (layoutName !== preferredLayout) {
437454
setLayoutName(preferredLayout);
438-
setLayout(DEFAULT_LAYOUTS[preferredLayout]);
455+
setLayout(
456+
applyDefaultDiffTab(
457+
cloneValue(DEFAULT_LAYOUTS[preferredLayout]),
458+
defaultDiffTab,
459+
),
460+
);
439461
}
440462
}
441463

frontend/src/lib/api.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import type {
2323
} from "./api/types";
2424
import { scratchUrl } from "./api/urls";
2525
import { ignoreNextWarnBeforeUnload } from "./hooks";
26-
import { useObjdiffClientEnabled } from "./settings";
2726

2827
function onErrorRetry<C>(
2928
error: ResponseError,
@@ -240,7 +239,6 @@ export function useCompilation(
240239
useState<Promise<void>>(null);
241240
const [compilation, setCompilation] = useState<Compilation>(initial);
242241
const [isCompilationOld, setIsCompilationOld] = useState(false);
243-
const [objdiffClientEnabled] = useObjdiffClientEnabled();
244242
const sUrl = scratchUrl(scratch);
245243
const hasInitialized = useRef(false);
246244

@@ -268,7 +266,7 @@ export function useCompilation(
268266
context: savedScratch
269267
? undefinedIfUnchanged(savedScratch, scratch, "context")
270268
: scratch.context,
271-
include_objects: objdiffClientEnabled,
269+
include_objects: true,
272270
})
273271
.then((compilation: Compilation) => {
274272
return compilation;
@@ -297,7 +295,7 @@ export function useCompilation(
297295
setCompileRequestPromise(promise);
298296

299297
return promise;
300-
}, [compileRequestPromise, savedScratch, scratch, objdiffClientEnabled]);
298+
}, [compileRequestPromise, savedScratch, scratch]);
301299

302300
// If the scratch we're looking at changes, we need to recompile
303301
const [url, setUrl] = useState(sUrl);

frontend/src/lib/settings.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export enum ThreeWayDiffBase {
88
PREV = "prev",
99
}
1010

11+
export enum DefaultDiffTab {
12+
ASM_DIFFER = "asm-differ",
13+
OBJDIFF = "objdiff",
14+
}
15+
1116
export const useTheme = createStorageKey<Theme>("theme", "auto");
1217
export const useAutoRecompileSetting = createStorageKey<boolean>(
1318
"autoRecompile",
@@ -47,9 +52,9 @@ export const useThreeWayDiffBase = createStorageKey<ThreeWayDiffBase>(
4752
"threeWayDiffBase",
4853
ThreeWayDiffBase.SAVED,
4954
);
50-
export const useObjdiffClientEnabled = createStorageKey<boolean>(
51-
"objdiffClientEnabled",
52-
false,
55+
export const useDefaultDiffTab = createStorageKey<DefaultDiffTab>(
56+
"defaultDiffTab",
57+
DefaultDiffTab.ASM_DIFFER,
5358
);
5459
export const diffCellBackgroundEnabled = createStorageKey<boolean>(
5560
"diffCellBackgroundEnabled",

0 commit comments

Comments
 (0)