Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/frontend-shared/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import AppShell from './components/layout/AppShell'
import { connectionsStore, initConnectionsListener } from './stores/connections'
import { editorStore } from './stores/editor'

// Suppress the webview's native context menu (with "Inspect Element" etc.) in
// production builds. In dev we keep it so we can inspect the DOM. Component-
// level context menus call e.preventDefault() themselves and render their own
// menu via the ContextMenu component, so they keep working either way.
function preventNativeContextMenu(e: MouseEvent) {
e.preventDefault()
}

export default function App() {
let cleanup: (() => void) | undefined

Expand All @@ -14,12 +22,19 @@ export default function App() {
connectionsStore.setOnConnectionLost((connectionId) => {
editorStore.rejectPendingQueriesForConnection(connectionId)
})

if (import.meta.env.PROD) {
document.addEventListener('contextmenu', preventNativeContextMenu)
}
})

onCleanup(() => {
cleanup?.()
connectionsStore.setOnTransactionLost(null)
connectionsStore.setOnConnectionLost(null)
if (import.meta.env.PROD) {
document.removeEventListener('contextmenu', preventNativeContextMenu)
}
})

return <AppShell />
Expand Down
Loading