Files
DeepTutor/web/components/sidebar/WorkspaceMenu.tsx
Bingxi Zhao (Frank) a4fa63b6e2 feat(desktop): add Open DeepTutor for macOS under apps/desktop
Move the Electron macOS app into the main repository and ship it with every
DeepTutor release.

- apps/desktop: Electron shell that installs a signed bundled runtime and
  hosts the web UI; versioned with the bundled core.
- White app icon with the black DeepTutor mark, generated by
  scripts/make-icon.swift; redesigned start screen and title bar.
- Shell copy in en/zh/de/fr/pl/uk, starting in English and following the
  interface language and theme from DeepTutor Settings, including live changes.
- Web UI labels itself "Open DeepTutor MacOS v<version>" inside the app
  (user-agent marker) and "Open DeepTutor Web v<version>" in a browser.
- Sealing refuses a missing or mismatched signing key instead of silently
  generating a new one.
- desktop-release.yml builds, smoke-tests and attaches the DMG to each
  GitHub Release; Developer ID signing and notarization run when secrets exist.
- tests.yml runs the shell checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 19:20:15 +08:00

141 lines
5.3 KiB
TypeScript

'use client'
import Image from 'next/image'
import Link from 'next/link'
import { useId, useState, type ReactNode } from 'react'
import { Check, ChevronDown, Settings, Settings2 } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { useMenuPopover } from '@/shared/ui/useMenuPopover'
import Tooltip from '@/shared/ui/Tooltip'
import { useWorkspaceChoices } from '@/components/workspaces/useWorkspaceChoices'
import { VersionBadge } from '@/components/sidebar/VersionBadge'
import { clientEditionLabel } from '@/lib/version'
const GLYPH_TINTS = ['#e3655b', '#d9822b', '#c9a227', '#4f9d69', '#3d8fb8', '#6c6fd1', '#a35fc0', '#c25b8a']
/** A stable letter tile for a workspace; the general one wears the logo. */
export function WorkspaceGlyph({ name, general, size = 22 }: { name: string; general: boolean; size?: number }) {
if (general)
return (
<span aria-hidden className="dt-workspace-glyph is-general" style={{ width: size, height: size }}>
<Image src="/brand/color-logo.png" alt="" width={size} height={size} className="h-full w-full object-contain" />
</span>
)
let hash = 0
for (const char of name) hash = (hash * 31 + char.codePointAt(0)!) | 0
return (
<span
aria-hidden
className="dt-workspace-glyph"
style={{ width: size, height: size, background: GLYPH_TINTS[Math.abs(hash) % GLYPH_TINTS.length], fontSize: size * 0.5 }}
>
{[...name.trim()][0]?.toUpperCase() ?? '·'}
</span>
)
}
/** The workspaces as menu items, the current one checked. */
export function WorkspaceChoiceList({ onChoose }: { onChoose?: () => void }) {
const { t } = useTranslation()
const { active, choices, choose } = useWorkspaceChoices()
return (
<>
<div className="dt-menu-label">{t('Workspace')}</div>
{choices.map(row => (
<button
key={row.workspace_id || 'general'}
type="button"
role="menuitem"
aria-current={row.workspace_id === active ? 'page' : undefined}
onClick={() => {
onChoose?.()
choose(row.workspace_id)
}}
className="dt-menu-item"
>
<WorkspaceGlyph name={row.display_name} general={!row.workspace_id} size={20} />
<span className="min-w-0 flex-1 truncate">{row.display_name}</span>
{row.workspace_id === active && <Check size={15} strokeWidth={2} className="shrink-0" />}
</button>
))}
<Link role="menuitem" href="/settings/workspace" prefetch={false} onClick={onChoose} className="dt-menu-item is-quiet">
<Settings2 size={16} strokeWidth={1.6} />
<span>{t('Manage workspaces')}</span>
</Link>
</>
)
}
/**
* The sidebar's header: which workspace this is, and the account-level
* places (workspaces, settings, profile) that used to sit in the footer.
*/
export function WorkspaceMenu({
accountSlot,
onNavigate,
compact = false,
}: {
accountSlot?: ReactNode
onNavigate?: () => void
/** The collapsed rail's form: the workspace's mark alone, opening beside the rail. */
compact?: boolean
}) {
const { t } = useTranslation()
const { active, currentName } = useWorkspaceChoices()
const [open, setOpen] = useState(false)
const rootRef = useMenuPopover<HTMLDivElement>(open, setOpen)
const menuId = useId()
const close = () => {
setOpen(false)
onNavigate?.()
}
return (
<div ref={rootRef} className={`dt-workspace-menu ${compact ? 'is-rail' : ''}`}>
{compact ? (
<Tooltip label={currentName} description={t('Manage workspaces')} side="right" suppressed={open}>
<button
type="button"
aria-haspopup="menu"
aria-expanded={open}
aria-controls={menuId}
aria-label={currentName}
onClick={() => setOpen(value => !value)}
className="dt-workspace-trigger"
>
<WorkspaceGlyph name={currentName} general={!active} />
</button>
</Tooltip>
) : (
<button
type="button"
aria-haspopup="menu"
aria-expanded={open}
aria-controls={menuId}
onClick={() => setOpen(value => !value)}
className="dt-workspace-trigger"
>
<WorkspaceGlyph name={currentName} general={!active} />
<span className="min-w-0 flex-1 truncate text-left">{currentName}</span>
<ChevronDown size={14} strokeWidth={1.8} className="shrink-0 opacity-60" />
</button>
)}
{open && (
<div id={menuId} role="menu" aria-label={t('Manage workspaces')} className="dt-popover dt-workspace-panel">
<WorkspaceChoiceList onChoose={close} />
<div className="dt-menu-divider" />
<Link role="menuitem" href="/settings" prefetch={false} onClick={close} className="dt-menu-item">
<Settings size={16} strokeWidth={1.6} />
<span className="flex-1">{t('Settings')}</span>
</Link>
{accountSlot ? <div className="dt-menu-slot">{accountSlot}</div> : null}
<div className="dt-menu-divider" />
<div className="dt-menu-footer">
<span className="min-w-0 truncate">{clientEditionLabel(process.env.NEXT_PUBLIC_APP_VERSION)}</span>
<VersionBadge onNavigate={close} />
</div>
</div>
)}
</div>
)
}