Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/app/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { ErrorPage } from "./pages/error"
import { useCheckServerHealth } from "./utils/server-health"
import { legacySessionHref, legacySessionServer, requireServerKey, sessionHref } from "./utils/session-route"
import { createSessionLineage } from "@/pages/session/session-lineage"
import { translateDesktopMenu } from "@/desktop-menu"

import { SessionPage, SessionRouteErrorBoundary, TargetSessionRouteContent } from "@/pages/session"
import { NewHome, LegacyHome } from "@/pages/home"
Expand Down Expand Up @@ -236,6 +237,18 @@ function UiI18nBridge(props: ParentProps) {
return <I18nProvider value={{ locale: language.intl, t: language.t }}>{props.children}</I18nProvider>
}

function DesktopMenuSync() {
const language = useLanguage()
const platform = usePlatform()

createEffect(() => {
if (!platform.setDesktopMenuLabels) return
void platform.setDesktopMenuLabels(translateDesktopMenu(language.t))
})

return null
}

declare global {
interface Window {
__OPENCODE__?: {
Expand Down Expand Up @@ -370,6 +383,7 @@ export function AppBaseProviders(props: ParentProps<{ locale?: Locale }>) {
}}
>
<LanguageProvider locale={props.locale}>
<DesktopMenuSync />
<UiI18nBridge>
<ErrorBoundary
fallback={(error) => {
Expand Down
21 changes: 16 additions & 5 deletions packages/app/src/components/windows-app-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@ import { IconButtonV2 } from "@opencode-ai/ui/v2/icon-button-v2"
import { Icon as IconV2 } from "@opencode-ai/ui/v2/icon"

import { useCommand } from "@/context/command"
import { DESKTOP_MENU, desktopMenuVisible, type DesktopMenuAction, type DesktopMenuEntry } from "@/desktop-menu"
import {
DESKTOP_MENU,
DESKTOP_MENU_ARIA_LABEL,
desktopMenuVisible,
type DesktopMenuAction,
type DesktopMenuEntry,
type DesktopMenuLabelKey,
} from "@/desktop-menu"
import { usePlatform } from "@/context/platform"
import { useLanguage } from "@/context/language"

export function WindowsAppMenu(props: {
command: ReturnType<typeof useCommand>
platform: ReturnType<typeof usePlatform>
variant?: "legacy" | "v2"
}) {
const language = useLanguage()
const label = (item: { label?: string; labelKey?: DesktopMenuLabelKey }) =>
item.labelKey ? language.t(item.labelKey) : item.label
let lastFocused: HTMLElement | undefined

const rememberFocus = () => {
Expand Down Expand Up @@ -58,7 +69,7 @@ export function WindowsAppMenu(props: {
variant="ghost-muted"
size="large"
icon={<IconV2 name="menu" />}
aria-label="OpenCode menu"
aria-label={language.t(DESKTOP_MENU_ARIA_LABEL)}
onPointerDown={rememberFocus}
onKeyDown={rememberFocus}
/>
Expand All @@ -69,7 +80,7 @@ export function WindowsAppMenu(props: {
icon="menu"
variant="ghost"
class="titlebar-icon rounded-md shrink-0"
aria-label="OpenCode menu"
aria-label={language.t(DESKTOP_MENU_ARIA_LABEL)}
onPointerDown={rememberFocus}
onKeyDown={rememberFocus}
/>
Expand All @@ -79,15 +90,15 @@ export function WindowsAppMenu(props: {
<DropdownMenu.Group>
<DropdownMenu.GroupLabel class="desktop-app-menu-heading">OpenCode</DropdownMenu.GroupLabel>
{DESKTOP_MENU.filter((menu) => desktopMenuVisible(menu, "windows")).map((menu) => (
<DesktopMenuSubmenu label={menu.label}>
<DesktopMenuSubmenu label={label(menu) ?? ""}>
{menu.items
?.filter((entry) => desktopMenuVisible(entry, "windows"))
.map((entry) =>
entry.type === "separator" ? (
<DropdownMenu.Separator />
) : (
<DesktopMenuItem
label={entry.label ?? ""}
label={label(entry) ?? ""}
keybind={entry.command ? props.command.keybind(entry.command) : entry.accelerator?.windows}
disabled={entry.command ? commandDisabled(entry.command) : false}
onSelect={() => runEntry(entry)}
Expand Down
5 changes: 4 additions & 1 deletion packages/app/src/context/platform.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSimpleContext } from "@opencode-ai/ui/context"
import type { AsyncStorage, SyncStorage } from "@solid-primitives/storage"
import type { Accessor } from "solid-js"
import type { DesktopMenuAction } from "../desktop-menu"
import type { DesktopMenuAction, DesktopMenuLabels } from "../desktop-menu"
import { ServerConnection } from "./server"
import type { WslServersPlatform } from "../wsl/types"
import type { UpdaterPlatform } from "../updater"
Expand Down Expand Up @@ -106,6 +106,9 @@ type PlatformBase = {
/** Run a desktop-only menu action from the app chrome */
runDesktopMenuAction?(action: DesktopMenuAction): Promise<void> | void

/** Update translated labels in the native desktop application menu */
setDesktopMenuLabels?(labels: DesktopMenuLabels): Promise<void> | void

/** Check if an editor app exists (desktop only) */
checkAppExists?(appName: string): Promise<boolean>

Expand Down
Loading
Loading