aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/contextMenu.ts
blob: 72f927ef41fb77c288996e4481ec6b92cc30c751 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { getCurrentWebContents } from '@electron/remote';
import { ContextMenuBuilder } from './contextMenuBuilder';

const webContents = getCurrentWebContents();

export default async function setupContextMenu(
  isSpellcheckEnabled: () => void,
  getDefaultSpellcheckerLanguage: () => void,
  getSpellcheckerLanguage: () => void,
  getSearchEngine: () => void,
  getClipboardNotifications: () => void,
) {
  const contextMenuBuilder = new ContextMenuBuilder(webContents);

  webContents.on('context-menu', (_e, props) => {
    // TODO?: e.preventDefault();
    contextMenuBuilder.showPopupMenu(
      {
        ...props,
        searchEngine: getSearchEngine(),
        clipboardNotifications: getClipboardNotifications(),
      },
      // @ts-expect-error Expected 1 arguments, but got 4.
      isSpellcheckEnabled(),
      getDefaultSpellcheckerLanguage(),
      getSpellcheckerLanguage(),
    );
  });
}