Skip to content

Commit ba4b8e2

Browse files
iamdavidhillHona
andauthored
feat(app): toggle debug tools from dev badge (anomalyco#36689)
Co-authored-by: LukeParkerDev <10430890+Hona@users.noreply.github.com>
1 parent 7985c20 commit ba4b8e2

3 files changed

Lines changed: 42 additions & 10 deletions

File tree

packages/app/src/components/titlebar.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function useTitlebarRightMount() {
6767
return mount
6868
}
6969

70-
export function Titlebar(props: { update?: TitlebarUpdate }) {
70+
export function Titlebar(props: { update?: TitlebarUpdate; debugTools?: { visible: boolean; toggle: () => void } }) {
7171
const layout = useLayout()
7272
const platform = usePlatform()
7373
const command = useCommand()
@@ -462,7 +462,7 @@ export function Titlebar(props: { update?: TitlebarUpdate }) {
462462
"md:pl-4": !mac(),
463463
}}
464464
>
465-
<ChannelIndicator />
465+
<ChannelIndicator debugTools={props.debugTools} />
466466
<Show when={windows() || linux()}>
467467
<WindowsAppMenu command={command} platform={platform} variant="v2" />
468468
</Show>
@@ -660,9 +660,9 @@ export function Titlebar(props: { update?: TitlebarUpdate }) {
660660
</div>
661661
</Show>
662662
<div id="opencode-titlebar-left" class="flex items-center gap-3 min-w-0 px-2" />
663-
<ChannelIndicator />
664663
</div>
665664
</div>
665+
<ChannelIndicator debugTools={props.debugTools} />
666666
</div>
667667
</div>
668668

@@ -747,12 +747,27 @@ function TitlebarUpdateIconButton(props: { state: TitlebarUpdatePillState }) {
747747
)
748748
}
749749

750-
function ChannelIndicator() {
750+
function ChannelIndicator(props: { debugTools?: { visible: boolean; toggle: () => void } }) {
751+
const channel = import.meta.env.VITE_OPENCODE_CHANNEL
752+
if (channel === "dev" && props.debugTools) {
753+
return (
754+
<button
755+
type="button"
756+
class="bg-icon-interactive-base text-[#FFF] font-medium px-2 rounded-sm uppercase font-mono cursor-pointer"
757+
onClick={props.debugTools.toggle}
758+
aria-label="Toggle debug tools"
759+
aria-pressed={props.debugTools.visible}
760+
>
761+
DEV
762+
</button>
763+
)
764+
}
765+
751766
return (
752767
<>
753-
{["beta", "dev"].includes(import.meta.env.VITE_OPENCODE_CHANNEL) && (
768+
{["beta", "dev"].includes(channel) && (
754769
<div class="bg-icon-interactive-base text-[#FFF] font-medium px-2 rounded-sm uppercase font-mono">
755-
{import.meta.env.VITE_OPENCODE_CHANNEL.toUpperCase()}
770+
{channel.toUpperCase()}
756771
</div>
757772
)}
758773
</>

packages/app/src/pages/layout-new.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createEffect, Suspense, type ParentProps } from "solid-js"
2+
import { createStore } from "solid-js/store"
23
import { useNavigate } from "@solidjs/router"
34
import { DebugBar } from "@/components/debug-bar"
45
import { TabsInfoPopup } from "@/components/help-button"
@@ -11,6 +12,7 @@ export default function NewLayout(props: ParentProps) {
1112
const platform = usePlatform()
1213
const navigate = useNavigate()
1314
setNavigate(navigate)
15+
const [state, setState] = createStore({ debugTools: true })
1416

1517
createEffect(() => setV2Toast(true))
1618

@@ -32,11 +34,18 @@ export default function NewLayout(props: ParentProps) {
3234
"padding-bottom": "env(safe-area-inset-bottom, 0px)",
3335
}}
3436
>
35-
<Titlebar update={update} />
37+
<Titlebar
38+
update={update}
39+
debugTools={
40+
import.meta.env.DEV
41+
? { visible: state.debugTools, toggle: () => setState("debugTools", (value) => !value) }
42+
: undefined
43+
}
44+
/>
3645
<main class="flex-1 min-h-0 min-w-0 overflow-x-hidden flex flex-col items-start contain-strict">
3746
<Suspense>{props.children}</Suspense>
3847
</main>
39-
{import.meta.env.DEV && <DebugBar inline />}
48+
{import.meta.env.DEV && state.debugTools && <DebugBar inline />}
4049
<TabsInfoPopup />
4150
<ToastRegion v2 />
4251
</div>

packages/app/src/pages/layout.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export default function LegacyLayout(props: ParentProps) {
156156
sizing: false,
157157
peek: undefined as string | undefined,
158158
peeked: false,
159+
debugTools: true,
159160
})
160161

161162
const updateVersion = () => {
@@ -2248,7 +2249,14 @@ export default function LegacyLayout(props: ParentProps) {
22482249
return (
22492250
<div class="relative bg-background-base flex-1 min-h-0 min-w-0 flex flex-col select-none [&_input]:select-text [&_textarea]:select-text [&_[contenteditable]]:select-text">
22502251
{autoselecting() ?? ""}
2251-
<Titlebar update={titlebarUpdate} />
2252+
<Titlebar
2253+
update={titlebarUpdate}
2254+
debugTools={
2255+
import.meta.env.DEV && import.meta.env.VITE_DISABLE_DEBUG_BAR !== "1"
2256+
? { visible: state.debugTools, toggle: () => setState("debugTools", (value) => !value) }
2257+
: undefined
2258+
}
2259+
/>
22522260
<Show when={updateVersion() !== undefined}>
22532261
<UpdateAvailableToast version={updateVersion() ?? ""} install={installUpdate} language={language} />
22542262
</Show>
@@ -2393,7 +2401,7 @@ export default function LegacyLayout(props: ParentProps) {
23932401
</div>
23942402
</div>
23952403
</div>
2396-
{import.meta.env.DEV && import.meta.env.VITE_DISABLE_DEBUG_BAR !== "1" && <DebugBar />}
2404+
{import.meta.env.DEV && import.meta.env.VITE_DISABLE_DEBUG_BAR !== "1" && state.debugTools && <DebugBar />}
23972405
</div>
23982406
<TabsInfoPopup />
23992407
<ToastRegion v2={false} />

0 commit comments

Comments
 (0)