【问题标题】:remote function returns undefined or null in electron renderer process远程函数在电子渲染器进程中返回未定义或 null
【发布时间】:2018-01-21 23:46:03
【问题描述】:

我目前对 electron.js 及其模块提供的综合机会非常感兴趣。不幸的是,当我尝试启动我的应用程序时,我的渲染器进程(名为“connector.js”)中不断出现相同的错误。

这是错误:

App threw an error during load
TypeError: Cannot match against 'undefined' or 'null'.
    at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\extFunctions\connector\connector.js:2:44)
    at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\extFunctions\connector\connector.js:22:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Eigene Dateien\Desktop\Coding\DesktopApps\EVT\main.js:9:1)

这是我的 connector.js:

const $ = require('jquery');
const {BrowserWindow} = require('electron').remote;

let Remotewin = remote.getFocusedWindow();

$("#minimize").click(function(){
  Remotewin.minimize();
});

$("#maximize").click(function(){
  if(!Remotewin.isMaximized()){
    Remotewin.maximize();
  }else{
    Remotewin.unmaximize();
  }
});

$("#close").click(function(){
  Remotewin.close();
});

您可以清楚地看到,我想在窗口的顶部框架中创建自己的菜单栏,但是这个错误似乎破坏了功能。我已经搜索了一半的互联网和 stackoverflow,但我找到的每个答案都涉及他们无法直接影响的 webpack 和/或电子错误。

这就是为什么我要明确指出,我在这个项目中没有使用 webpack。我添加的唯一外部模块是 jquery,您可以在代码中看到。

所以我的问题;您是否在这种情况下遇到过此错误,您甚至可能知道解决方案吗?或者您可以参考有类似问题的人吗?

提前谢谢你,J0nny

【问题讨论】:

    标签: javascript node.js electron


    【解决方案1】:

    由于getFocusedWindow()BrowserWindow的静态方法,

    let Remotewin = remote.getFocusedWindow();
    

    应该是:

    let Remotewin = BrowserWindow.getFocusedWindow();
    

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 1970-01-01
      • 2021-04-26
      • 2022-07-22
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 2019-04-30
      相关资源
      最近更新 更多