Buckets:
| import { BrowserWindow, Menu, shell } from "electron" | |
| import type { MenuItemConstructorOptions } from "electron" | |
| import { | |
| DESKTOP_MENU, | |
| desktopMenuVisible, | |
| type DesktopMenuEntry, | |
| type DesktopMenuRole, | |
| } from "@opencode-ai/app/desktop-menu" | |
| import { UPDATER_ENABLED } from "./constants" | |
| import { runDesktopMenuAction } from "./desktop-menu-actions" | |
| type Deps = { | |
| trigger: (id: string) => void | |
| checkForUpdates: () => void | |
| relaunch: () => void | |
| } | |
| export function createMenu(deps: Deps) { | |
| if (process.platform !== "darwin") return | |
| const template = DESKTOP_MENU.filter((menu) => desktopMenuVisible(menu, "macos")).map((menu) => { | |
| if (menu.role) return { role: nativeRole(menu.role) } | |
| return { | |
| label: menu.label, | |
| submenu: menu.items | |
| ?.filter((entry) => desktopMenuVisible(entry, "macos")) | |
| .map((entry) => nativeItem(entry, deps)), | |
| } | |
| }) | |
| Menu.setApplicationMenu(Menu.buildFromTemplate(template)) | |
| } | |
| function nativeItem(entry: DesktopMenuEntry, deps: Deps): MenuItemConstructorOptions { | |
| if (entry.type === "separator") return { type: "separator" } | |
| if (entry.role) return { role: nativeRole(entry.role) } | |
| const item: MenuItemConstructorOptions = { | |
| label: entry.label, | |
| accelerator: entry.accelerator?.macos, | |
| enabled: entry.enabled === "updater" ? UPDATER_ENABLED : undefined, | |
| } | |
| if (entry.command) { | |
| const command = entry.command | |
| item.click = () => deps.trigger(command) | |
| } | |
| if (entry.action) { | |
| const action = entry.action | |
| item.click = () => | |
| runDesktopMenuAction(BrowserWindow.getFocusedWindow(), action, { | |
| checkForUpdates: deps.checkForUpdates, | |
| relaunch: deps.relaunch, | |
| }) | |
| } | |
| if (entry.href) { | |
| const href = entry.href | |
| item.click = () => shell.openExternal(href) | |
| } | |
| return item | |
| } | |
| function nativeRole(role: DesktopMenuRole) { | |
| return role as NonNullable<MenuItemConstructorOptions["role"]> | |
| } | |
Xet Storage Details
- Size:
- 1.93 kB
- Xet hash:
- fd0d519de70b866bd6f6bf3b87fd2127d12538d15ff1dd17b8697ba4ab6d29fd
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.