javascript - 如何在 Electron 15 中导入菜单

我需要为我的 render.js 文件导入菜单。但是要么 Remote 未定义,要么我得到一些错误。

使用以下代码我得到这个错误: 未捕获的类型错误:无法读取未定义的属性(读取“成员”)

我还使用 .enable(webContents) 方法尝试了 Electron 文档中的一些内容,但我也无法使其正常工作。

这样做的方法是什么?

Index.js:

const { app, BrowserWindow } = require('electron');
const path = require('path');

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
  app.quit();
}

const createWindow = () => {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
    }
  });

render.js:

const { desktopCapturer } = require('electron');
const { Menu } = require('@electron/remote')
console.log(Menu);

最佳答案

如 npm @electron/remote 文档中所述

@electron/remote/main must be initialized in the main process before it can be used from the renderer:

// in the main process:
require('@electron/remote/main').initialize()

https://stackoverflow.com/questions/69697396/

相关文章:

spring-boot - 应用程序通过 Spring Boot Run 而不是通过 Intelli

html - 是否可以使用纯 CSS 为仅包含一个元素的列表设置样式,而不是为包含多个元素的列表设置

haskell - 不同类型的重载/多态函数

r - 在 download.file 中关闭 SSL 验证

r - 如何调整饼图上的 ggrepel 标签?

java - 将 Enum 类名本身作为 String 获取的最佳方法

java - org.gradle.api.internal.tasks.testing.TestS

typescript - 类型错误 : EventEmitter is not a construc

r - 使用 dplyr 获取术语列表、分组依据和汇总值

typescript - 如何从Nuxt 3服务器获取路由参数