63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { StrictMode } from 'react'
|
|
import { createRoot } from 'react-dom/client'
|
|
import { TooltipProvider } from '@/components/ui/tooltip'
|
|
import './index.css'
|
|
import App from './App.tsx'
|
|
import {
|
|
APP_COMMAND_EVENT_NAME,
|
|
isAppCommandId,
|
|
isNativeMenuCommandId,
|
|
} from './hooks/appCommandDispatcher'
|
|
|
|
declare global {
|
|
interface Window {
|
|
__laputaTest?: {
|
|
dispatchAppCommand: (id: string) => void
|
|
dispatchBrowserMenuCommand?: (id: string) => void
|
|
triggerMenuCommand?: (id: string) => Promise<unknown>
|
|
}
|
|
}
|
|
}
|
|
|
|
// Disable native WebKit context menu in Tauri (WKWebView intercepts right-click
|
|
// at native level before React's synthetic events can call preventDefault).
|
|
// Capture phase fires first → prevents native menu; React bubble phase still fires
|
|
// → our custom context menus (e.g. sidebar right-click) work correctly.
|
|
if ('__TAURI__' in window || '__TAURI_INTERNALS__' in window) {
|
|
document.addEventListener('contextmenu', (e) => e.preventDefault(), true)
|
|
}
|
|
|
|
window.__laputaTest = {
|
|
dispatchAppCommand(id: string) {
|
|
if (!isAppCommandId(id)) {
|
|
throw new Error(`Unknown app command: ${id}`)
|
|
}
|
|
window.dispatchEvent(new CustomEvent(APP_COMMAND_EVENT_NAME, { detail: id }))
|
|
},
|
|
async triggerMenuCommand(id: string) {
|
|
if (!isNativeMenuCommandId(id)) {
|
|
throw new Error(`Unknown native menu command: ${id}`)
|
|
}
|
|
|
|
if ('__TAURI__' in window || '__TAURI_INTERNALS__' in window) {
|
|
const { invoke } = await import('@tauri-apps/api/core')
|
|
return invoke('trigger_menu_command', { id })
|
|
}
|
|
|
|
if (!window.__laputaTest?.dispatchBrowserMenuCommand) {
|
|
throw new Error('Laputa test bridge is missing dispatchBrowserMenuCommand')
|
|
}
|
|
|
|
window.__laputaTest.dispatchBrowserMenuCommand(id)
|
|
return undefined
|
|
},
|
|
}
|
|
|
|
createRoot(document.getElementById('root')!).render(
|
|
<StrictMode>
|
|
<TooltipProvider>
|
|
<App />
|
|
</TooltipProvider>
|
|
</StrictMode>,
|
|
)
|