mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Replace the plaintext pairing exchange with a nonce and HMAC proof plus AES-256-GCM encrypted credentials, bumping links to v2. Track session ownership per linked server so activity, session picker, transcript, MCP and skills views work against remote servers. Share encrypted secret access, event routing and URL helpers across backend, shared and CLI.
71 lines
3.0 KiB
TypeScript
71 lines
3.0 KiB
TypeScript
import { useCallback, useMemo } from 'react'
|
|
import { useLocation, useNavigate } from 'react-router-dom'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { ASSISTANT_REPO_ID } from '@opencode-manager/shared/utils'
|
|
import { getRepo } from '@/api/repos'
|
|
import { buildToolItems, toolKeyOf } from '@/components/navigation/moreDrawerItems'
|
|
import { useShortcutActions } from '@/contexts/KeyboardShortcutsContext'
|
|
import { dialogSearch } from '@/hooks/useDialogParam'
|
|
import { useCreateSession } from '@/hooks/useOpenCode'
|
|
import { useMobile } from '@/hooks/useMobile'
|
|
import { useSettingsDialog } from '@/hooks/useSettingsDialog'
|
|
import { useUrlParams } from '@/hooks/useUrlParams'
|
|
import { toggleToolDialogParams, toggleToolPanelParams, type PanelTool } from '@/hooks/useToolPanel'
|
|
import { isLocalOpenCodeServer, useRouteOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
|
|
import { getAssistantPath, getRepoPath, getSessionPath, isAssistantPath, parseRepoRoute } from '@/lib/navigation'
|
|
|
|
/**
|
|
* Registers the app-wide shortcut actions: the settings dialog, the route tool panels, and repo-scoped session
|
|
* creation. Page layers can override any of these by registering the same action name.
|
|
*/
|
|
export function useGlobalShortcutActions(): void {
|
|
const { pathname } = useLocation()
|
|
const navigate = useNavigate()
|
|
const { updateParams } = useUrlParams()
|
|
const { open: openSettings } = useSettingsDialog()
|
|
const isMobile = useMobile()
|
|
const isRemoteRoute = !isLocalOpenCodeServer(useRouteOpenCodeServerId())
|
|
|
|
const repoId = isAssistantPath(pathname) ? ASSISTANT_REPO_ID : parseRepoRoute(pathname).repoId
|
|
|
|
const { data: repo } = useQuery({
|
|
queryKey: ['repo', repoId],
|
|
queryFn: () => getRepo(repoId as number),
|
|
enabled: repoId !== null,
|
|
})
|
|
|
|
const createSession = useCreateSession(repo?.fullPath, (session) => {
|
|
if (repoId === null) return
|
|
navigate(getSessionPath(repoId, session.id))
|
|
})
|
|
|
|
const toolItems = useMemo(() => buildToolItems(pathname), [pathname])
|
|
const hasFilesTool = toolItems.some((item) => toolKeyOf(item) === 'files')
|
|
|
|
const toggleRouteTool = useCallback((tool: PanelTool) => {
|
|
if (isRemoteRoute) return
|
|
if (toolItems.some((item) => toolKeyOf(item) === tool)) {
|
|
updateParams((params) => {
|
|
if (isMobile) toggleToolDialogParams(params, tool)
|
|
else toggleToolPanelParams(params, tool)
|
|
}, 'push')
|
|
return
|
|
}
|
|
if (tool === 'files') return
|
|
const host = repoId !== null ? getRepoPath(repoId) : getAssistantPath()
|
|
navigate(`${host}${dialogSearch(tool)}`)
|
|
}, [toolItems, isMobile, updateParams, navigate, repoId, isRemoteRoute])
|
|
|
|
const newSession = repoId !== null && repo?.fullPath && !createSession.isPending
|
|
? () => createSession.mutate({})
|
|
: undefined
|
|
|
|
useShortcutActions({
|
|
settings: openSettings,
|
|
toggleTerminal: () => toggleRouteTool('terminal'),
|
|
toggleSourceControl: () => toggleRouteTool('sourceControl'),
|
|
toggleSidebar: hasFilesTool ? () => toggleRouteTool('files') : undefined,
|
|
newSession,
|
|
}, 'global')
|
|
}
|