Add Windows desktop app menu (#28420)
This commit is contained in:
@@ -12,6 +12,7 @@ import { usePlatform } from "@/context/platform"
|
||||
import { useCommand } from "@/context/command"
|
||||
import { useLanguage } from "@/context/language"
|
||||
import { useSettings } from "@/context/settings"
|
||||
import { WindowsAppMenu } from "./windows-app-menu"
|
||||
import { applyPath, backPath, forwardPath } from "./titlebar-history"
|
||||
|
||||
type TauriDesktopWindow = {
|
||||
@@ -191,6 +192,9 @@ export function Titlebar() {
|
||||
"pl-2": !mac(),
|
||||
}}
|
||||
>
|
||||
<Show when={windows()}>
|
||||
<WindowsAppMenu command={command} platform={platform} />
|
||||
</Show>
|
||||
<Show when={mac()}>
|
||||
<div class="h-full shrink-0" style={{ width: `${72 / zoom()}px` }} />
|
||||
<div class="xl:hidden w-10 shrink-0 flex items-center justify-center">
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import { Show, type JSX } from "solid-js"
|
||||
import { DropdownMenu } from "@opencode-ai/ui/dropdown-menu"
|
||||
import { Icon } from "@opencode-ai/ui/icon"
|
||||
import { IconButton } from "@opencode-ai/ui/icon-button"
|
||||
|
||||
import { useCommand } from "@/context/command"
|
||||
import { DESKTOP_MENU, desktopMenuVisible, type DesktopMenuAction, type DesktopMenuEntry } from "@/desktop-menu"
|
||||
import { usePlatform } from "@/context/platform"
|
||||
|
||||
export function WindowsAppMenu(props: { command: ReturnType<typeof useCommand>; platform: ReturnType<typeof usePlatform> }) {
|
||||
let lastFocused: HTMLElement | undefined
|
||||
|
||||
const rememberFocus = () => {
|
||||
const active = document.activeElement
|
||||
lastFocused = active instanceof HTMLElement ? active : undefined
|
||||
}
|
||||
const commandDisabled = (id: string) => {
|
||||
const option = props.command.options.find((option) => option.id === id)
|
||||
if (!option) return true
|
||||
return option.disabled ?? false
|
||||
}
|
||||
const runCommand = (id: string) => {
|
||||
if (commandDisabled(id)) return
|
||||
props.command.trigger(id)
|
||||
}
|
||||
const runAction = (action: DesktopMenuAction) => {
|
||||
if (action.startsWith("edit.") && lastFocused?.isConnected) lastFocused.focus({ preventScroll: true })
|
||||
void props.platform.runDesktopMenuAction?.(action)
|
||||
}
|
||||
const runEntry = (entry: DesktopMenuEntry) => {
|
||||
if (entry.type === "separator") return
|
||||
if (entry.command) {
|
||||
runCommand(entry.command)
|
||||
return
|
||||
}
|
||||
if (entry.action) {
|
||||
runAction(entry.action)
|
||||
return
|
||||
}
|
||||
if (entry.href) props.platform.openLink(entry.href)
|
||||
}
|
||||
|
||||
return (
|
||||
<DropdownMenu gutter={4} modal={false} placement="bottom-start">
|
||||
<DropdownMenu.Trigger
|
||||
as={IconButton}
|
||||
icon="menu"
|
||||
variant="ghost"
|
||||
class="titlebar-icon rounded-md shrink-0"
|
||||
aria-label="OpenCode menu"
|
||||
onPointerDown={rememberFocus}
|
||||
onKeyDown={rememberFocus}
|
||||
/>
|
||||
<DropdownMenu.Portal>
|
||||
<DropdownMenu.Content class="desktop-app-menu">
|
||||
<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}>
|
||||
{menu.items?.filter((entry) => desktopMenuVisible(entry, "windows")).map((entry) =>
|
||||
entry.type === "separator" ? (
|
||||
<DropdownMenu.Separator />
|
||||
) : (
|
||||
<DesktopMenuItem
|
||||
label={entry.label ?? ""}
|
||||
keybind={entry.command ? props.command.keybind(entry.command) : entry.accelerator?.windows}
|
||||
disabled={entry.command ? commandDisabled(entry.command) : false}
|
||||
onSelect={() => runEntry(entry)}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
</DesktopMenuSubmenu>
|
||||
))}
|
||||
</DropdownMenu.Group>
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu.Portal>
|
||||
</DropdownMenu>
|
||||
)
|
||||
}
|
||||
|
||||
function DesktopMenuSubmenu(props: { label: string; children: JSX.Element }) {
|
||||
return (
|
||||
<DropdownMenu.Sub>
|
||||
<DropdownMenu.SubTrigger>
|
||||
<span data-slot="dropdown-menu-item-label">{props.label}</span>
|
||||
<span data-slot="desktop-app-menu-chevron">
|
||||
<Icon name="chevron-right" size="small" />
|
||||
</span>
|
||||
</DropdownMenu.SubTrigger>
|
||||
<DropdownMenu.Portal>
|
||||
<DropdownMenu.SubContent class="desktop-app-menu">{props.children}</DropdownMenu.SubContent>
|
||||
</DropdownMenu.Portal>
|
||||
</DropdownMenu.Sub>
|
||||
)
|
||||
}
|
||||
|
||||
function DesktopMenuItem(props: { label: string; keybind?: string; disabled?: boolean; onSelect: () => void }) {
|
||||
return (
|
||||
<DropdownMenu.Item disabled={props.disabled} onSelect={props.onSelect}>
|
||||
<DropdownMenu.ItemLabel>{props.label}</DropdownMenu.ItemLabel>
|
||||
<Show when={props.keybind}>
|
||||
<span data-slot="desktop-app-menu-keybind">{props.keybind}</span>
|
||||
</Show>
|
||||
</DropdownMenu.Item>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +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 { ServerConnection } from "./server"
|
||||
|
||||
type PickerPaths = string | string[] | null
|
||||
@@ -82,6 +83,9 @@ export type Platform = {
|
||||
/** Webview zoom level (desktop only) */
|
||||
webviewZoom?: Accessor<number>
|
||||
|
||||
/** Run a desktop-only menu action from the app chrome */
|
||||
runDesktopMenuAction?(action: DesktopMenuAction): Promise<void> | void
|
||||
|
||||
/** Check if an editor app exists (desktop only) */
|
||||
checkAppExists?(appName: string): Promise<boolean>
|
||||
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
export type DesktopMenuPlatform = "macos" | "windows"
|
||||
|
||||
export type DesktopMenuAction =
|
||||
| "app.checkForUpdates"
|
||||
| "app.relaunch"
|
||||
| "edit.undo"
|
||||
| "edit.redo"
|
||||
| "edit.cut"
|
||||
| "edit.copy"
|
||||
| "edit.paste"
|
||||
| "edit.delete"
|
||||
| "edit.selectAll"
|
||||
| "view.reload"
|
||||
| "view.toggleDevTools"
|
||||
| "view.resetZoom"
|
||||
| "view.zoomIn"
|
||||
| "view.zoomOut"
|
||||
| "view.toggleFullscreen"
|
||||
| "window.new"
|
||||
| "window.close"
|
||||
| "window.minimize"
|
||||
| "window.toggleMaximize"
|
||||
|
||||
export type DesktopMenuRole =
|
||||
| "about"
|
||||
| "close"
|
||||
| "copy"
|
||||
| "cut"
|
||||
| "hide"
|
||||
| "hideOthers"
|
||||
| "paste"
|
||||
| "quit"
|
||||
| "redo"
|
||||
| "reload"
|
||||
| "resetZoom"
|
||||
| "selectAll"
|
||||
| "toggleDevTools"
|
||||
| "togglefullscreen"
|
||||
| "undo"
|
||||
| "unhide"
|
||||
| "windowMenu"
|
||||
| "zoomIn"
|
||||
| "zoomOut"
|
||||
|
||||
export type DesktopMenuItem = {
|
||||
type: "item"
|
||||
label?: string
|
||||
command?: string
|
||||
action?: DesktopMenuAction
|
||||
role?: DesktopMenuRole
|
||||
href?: string
|
||||
accelerator?: Partial<Record<DesktopMenuPlatform, string>>
|
||||
enabled?: "updater"
|
||||
platforms?: DesktopMenuPlatform[]
|
||||
}
|
||||
|
||||
export type DesktopMenuSeparator = {
|
||||
type: "separator"
|
||||
platforms?: DesktopMenuPlatform[]
|
||||
}
|
||||
|
||||
export type DesktopMenuEntry = DesktopMenuItem | DesktopMenuSeparator
|
||||
|
||||
export type DesktopMenu = {
|
||||
id: string
|
||||
label: string
|
||||
role?: DesktopMenuRole
|
||||
items?: DesktopMenuEntry[]
|
||||
platforms?: DesktopMenuPlatform[]
|
||||
}
|
||||
|
||||
export const DESKTOP_MENU: DesktopMenu[] = [
|
||||
{
|
||||
id: "app",
|
||||
label: "OpenCode",
|
||||
platforms: ["macos"],
|
||||
items: [
|
||||
{ type: "item", role: "about" },
|
||||
{ type: "item", label: "Check for Updates...", action: "app.checkForUpdates", enabled: "updater" },
|
||||
{ type: "item", label: "Settings", command: "settings.open", accelerator: { macos: "Cmd+," } },
|
||||
{ type: "item", label: "Reload Webview", action: "view.reload" },
|
||||
{ type: "item", label: "Restart", action: "app.relaunch" },
|
||||
{ type: "separator" },
|
||||
{ type: "item", role: "hide" },
|
||||
{ type: "item", role: "hideOthers" },
|
||||
{ type: "item", role: "unhide" },
|
||||
{ type: "separator" },
|
||||
{ type: "item", role: "quit" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "file",
|
||||
label: "File",
|
||||
items: [
|
||||
{
|
||||
type: "item",
|
||||
label: "New Session",
|
||||
command: "session.new",
|
||||
accelerator: { macos: "Shift+Cmd+S" },
|
||||
},
|
||||
{ type: "item", label: "Open Project...", command: "project.open", accelerator: { macos: "Cmd+O" } },
|
||||
{
|
||||
type: "item",
|
||||
label: "Settings",
|
||||
command: "settings.open",
|
||||
accelerator: { windows: "Ctrl+," },
|
||||
platforms: ["windows"],
|
||||
},
|
||||
{
|
||||
type: "item",
|
||||
label: "New Window",
|
||||
action: "window.new",
|
||||
accelerator: { macos: "Cmd+Shift+N", windows: "Ctrl+Shift+N" },
|
||||
},
|
||||
{ type: "separator" },
|
||||
{ type: "item", label: "Close Window", action: "window.close", role: "close" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "edit",
|
||||
label: "Edit",
|
||||
items: [
|
||||
{ type: "item", label: "Undo", action: "edit.undo", role: "undo", accelerator: { windows: "Ctrl+Z" } },
|
||||
{ type: "item", label: "Redo", action: "edit.redo", role: "redo", accelerator: { windows: "Ctrl+Y" } },
|
||||
{ type: "separator" },
|
||||
{ type: "item", label: "Cut", action: "edit.cut", role: "cut", accelerator: { windows: "Ctrl+X" } },
|
||||
{ type: "item", label: "Copy", action: "edit.copy", role: "copy", accelerator: { windows: "Ctrl+C" } },
|
||||
{ type: "item", label: "Paste", action: "edit.paste", role: "paste", accelerator: { windows: "Ctrl+V" } },
|
||||
{ type: "item", label: "Delete", action: "edit.delete" },
|
||||
{
|
||||
type: "item",
|
||||
label: "Select All",
|
||||
action: "edit.selectAll",
|
||||
role: "selectAll",
|
||||
accelerator: { windows: "Ctrl+A" },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "view",
|
||||
label: "View",
|
||||
items: [
|
||||
{ type: "item", label: "Toggle Sidebar", command: "sidebar.toggle", accelerator: { macos: "Cmd+B" } },
|
||||
{ type: "item", label: "Toggle Terminal", command: "terminal.toggle", accelerator: { macos: "Ctrl+`" } },
|
||||
{ type: "item", label: "Toggle File Tree", command: "fileTree.toggle" },
|
||||
{ type: "separator" },
|
||||
{ type: "item", label: "Reload", action: "view.reload", role: "reload" },
|
||||
{ type: "item", label: "Toggle Developer Tools", action: "view.toggleDevTools", role: "toggleDevTools" },
|
||||
{ type: "separator" },
|
||||
{
|
||||
type: "item",
|
||||
label: "Actual Size",
|
||||
action: "view.resetZoom",
|
||||
role: "resetZoom",
|
||||
accelerator: { windows: "Ctrl+0" },
|
||||
},
|
||||
{ type: "item", label: "Zoom In", action: "view.zoomIn", role: "zoomIn", accelerator: { windows: "Ctrl++" } },
|
||||
{ type: "item", label: "Zoom Out", action: "view.zoomOut", role: "zoomOut", accelerator: { windows: "Ctrl+-" } },
|
||||
{ type: "separator" },
|
||||
{ type: "item", label: "Toggle Full Screen", action: "view.toggleFullscreen", role: "togglefullscreen" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "go",
|
||||
label: "Go",
|
||||
items: [
|
||||
{ type: "item", label: "Back", command: "common.goBack", accelerator: { macos: "Cmd+[" } },
|
||||
{ type: "item", label: "Forward", command: "common.goForward", accelerator: { macos: "Cmd+]" } },
|
||||
{ type: "separator" },
|
||||
{ type: "item", label: "Previous Session", command: "session.previous", accelerator: { macos: "Option+Up" } },
|
||||
{ type: "item", label: "Next Session", command: "session.next", accelerator: { macos: "Option+Down" } },
|
||||
{ type: "separator" },
|
||||
{
|
||||
type: "item",
|
||||
label: "Previous Project",
|
||||
command: "project.previous",
|
||||
accelerator: { macos: "Cmd+Option+Up" },
|
||||
},
|
||||
{
|
||||
type: "item",
|
||||
label: "Next Project",
|
||||
command: "project.next",
|
||||
accelerator: { macos: "Cmd+Option+Down" },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "window",
|
||||
label: "Window",
|
||||
role: "windowMenu",
|
||||
items: [
|
||||
{ type: "item", label: "Minimize", action: "window.minimize" },
|
||||
{ type: "item", label: "Maximize", action: "window.toggleMaximize" },
|
||||
{ type: "separator" },
|
||||
{ type: "item", label: "Close Window", action: "window.close" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "help",
|
||||
label: "Help",
|
||||
items: [
|
||||
{ type: "item", label: "OpenCode Documentation", href: "https://opencode.ai/docs" },
|
||||
{ type: "item", label: "Support Forum", href: "https://discord.com/invite/opencode" },
|
||||
{ type: "separator" },
|
||||
{ type: "item", label: "Share Feedback", href: "https://github.com/anomalyco/opencode/issues/new?template=feature_request.yml" },
|
||||
{ type: "item", label: "Report a Bug", href: "https://github.com/anomalyco/opencode/issues/new?template=bug_report.yml" },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export function desktopMenuVisible(item: { platforms?: DesktopMenuPlatform[] }, platform: DesktopMenuPlatform) {
|
||||
return !item.platforms || item.platforms.includes(platform)
|
||||
}
|
||||
@@ -53,6 +53,63 @@
|
||||
container-name: getting-started;
|
||||
}
|
||||
|
||||
[data-component="dropdown-menu-content"].desktop-app-menu,
|
||||
[data-component="dropdown-menu-sub-content"].desktop-app-menu {
|
||||
min-width: 160px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
[data-component="dropdown-menu-content"].desktop-app-menu {
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
[data-component="dropdown-menu-sub-content"].desktop-app-menu {
|
||||
width: max-content;
|
||||
min-width: 240px;
|
||||
max-width: min(320px, calc(100vw - 24px));
|
||||
}
|
||||
|
||||
[data-component="dropdown-menu-content"].desktop-app-menu [data-slot="dropdown-menu-group-label"] {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 28px;
|
||||
padding: 0 12px;
|
||||
font-size: var(--font-size-x-small);
|
||||
font-weight: var(--font-weight-medium);
|
||||
line-height: 1;
|
||||
color: var(--text-weak);
|
||||
}
|
||||
|
||||
[data-component="dropdown-menu-content"].desktop-app-menu [data-slot="dropdown-menu-item"],
|
||||
[data-component="dropdown-menu-content"].desktop-app-menu [data-slot="dropdown-menu-sub-trigger"],
|
||||
[data-component="dropdown-menu-sub-content"].desktop-app-menu [data-slot="dropdown-menu-item"],
|
||||
[data-component="dropdown-menu-sub-content"].desktop-app-menu [data-slot="dropdown-menu-sub-trigger"] {
|
||||
min-height: 28px;
|
||||
padding: 0 12px;
|
||||
gap: 8px;
|
||||
font-weight: var(--font-weight-regular);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
[data-component="dropdown-menu-content"].desktop-app-menu [data-slot="dropdown-menu-item-label"],
|
||||
[data-component="dropdown-menu-sub-content"].desktop-app-menu [data-slot="dropdown-menu-item-label"] {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
[data-slot="desktop-app-menu-keybind"] {
|
||||
margin-left: auto;
|
||||
color: var(--text-weak);
|
||||
font-size: var(--font-size-x-small);
|
||||
font-weight: var(--font-weight-regular);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
[data-slot="desktop-app-menu-chevron"] {
|
||||
display: flex;
|
||||
margin-left: auto;
|
||||
color: var(--icon-base);
|
||||
}
|
||||
|
||||
[data-component="getting-started-actions"] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
Reference in New Issue
Block a user