【问题标题】:Close, Minimize and Maximize buttons on ElectronElectron 上的关闭、最小化和最大化按钮
【发布时间】:2016-10-04 03:48:17
【问题描述】:

我目前正在使用电子 1.0,但我找不到使用远程模块的方法,我尝试的每一个教程,它们都不起作用,我只是给我一个错误“找不到模块'远程' ”。

这是函数所在的 index.js(在我的 html 文件上调用的外部 .js 文件)中的 sn-p:

 (function () {

 var remote = require('remote');
 var BrowserWindow = remote.require('browser-window');

 function init() {
      document.getElementById("min-btn").addEventListener("click", function (e) {
           var window = BrowserWindow.getFocusedWindow();
           window.minimize();
      });

      document.getElementById("max-btn").addEventListener("click", function (e) {
           var window = BrowserWindow.getFocusedWindow();
           window.maximize();
      });

      document.getElementById("close-btn").addEventListener("click", function (e) {
           var window = BrowserWindow.getFocusedWindow();
           window.close();
      });
 };

 document.onreadystatechange = function () {
      if (document.readyState == "complete") {
           init();
      }
 };

})();

这是我的 main.js 文件:

 const electron = require('electron') 
 const app = electron.app
 const BrowserWindow = electron.BrowserWindow

 let mainWindow

 function createWindow () {
    mainWindow = new BrowserWindow({width: 800, height: 600, frame: false,          title:"Gestão Prefeitura", center: true})
   mainWindow.loadURL(`file://${__dirname}/index.html`)
   mainWindow.webContents.openDevTools()
   mainWindow.on('closed', function () {
   mainWindow = null
 })
}

app.on('ready', createWindow)

 app.on('window-all-closed', function () {
 if (process.platform !== 'darwin') { 
 app.quit()
 }
})

app.on('activate', function () {
if (mainWindow === null) {
         createWindow()
      }
    })

【问题讨论】:

    标签: javascript electron


    【解决方案1】:

    您需要内置 Electron 模块的方式在 Electron v1.0.0 中发生了变化,现在它们都通过 electron 模块公开。此外,remote 模块现在具有对应于主进程模块的属性。所以,而不是:

    var remote = require('remote');
    var BrowserWindow = remote.require('browser-window');
    

    你应该写:

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

    【讨论】:

      猜你喜欢
      • 2016-03-04
      • 1970-01-01
      • 2018-04-02
      • 2011-03-13
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      相关资源
      最近更新 更多