【问题标题】:Cannot find name 'BrowserWindow'找不到名称“浏览器窗口”
【发布时间】:2018-10-06 00:36:49
【问题描述】:

在 electron.service.ts 的文件夹提供程序中,我有代码:

import { Injectable } from '@angular/core';

// If you import a module but never use any of the imported values other than as TypeScript types,
// the resulting javascript file will look as if you never imported the module at all.
import { ipcRenderer, webFrame, remote, BrowserWindow } from 'electron';
import * as childProcess from 'child_process';
import * as fs from 'fs';

@Injectable()
export class ElectronService {

  ipcRenderer: typeof ipcRenderer;
  webFrame: typeof webFrame;
  remote: typeof remote;
  childProcess: typeof childProcess;
  win: BrowserWindow;
  fs: typeof fs;

  constructor() {
    // Conditional imports
    if (this.isElectron()) {
      this.ipcRenderer = window.require('electron').ipcRenderer;
      this.webFrame = window.require('electron').webFrame;
      this.remote = window.require('electron').remote;
      this.win = window.require('electron').remote.getCurrentWindow();

      this.childProcess = window.require('child_process');
      this.fs = window.require('fs');
    }
  }

  isElectron = () => {
    return window && window.process && window.process.type;
  }

}

在组件中我有方法:

import { ElectronService } from '../../providers/electron.service';

toggleFullScreen() {
    const flag = !this.electron.win.isFullScreen();
    this.electron.win.show();
    this.electron.win.setFullScreen(flag);
    this.storeService.isFullScreen = this.electron.win.isFullScreen();
  }

当我在我的项目中写作时

win: BrowserWindow; 

我收到错误找不到名称“BrowserWindow”。怎么了?我做了 从“电子”导入 { ipcRenderer, webFrame, remote, BrowserWindow }; 我不能改写

win: typeof BrowserWindow;

因为在方法 toggleFullScreen() 中无法使用方法 isFullScreen()、show()、setFullScreen()。 应用程序在开发模式下运行良好,但我有错误,我无法构建 exe 文件。怎么解决?

【问题讨论】:

    标签: javascript angular electron


    【解决方案1】:

    这是我熟悉的

    const {BrowserWindow} = require('electron')
    let win = new BrowserWindow({width: 800, height: 600})
    

    编辑 :我在网上看到类型指定为

    win: Electron.BrowserWindow
    

    【讨论】:

    • 非常感谢,这段代码win: Electron.BrowserWindow帮助了我,我没有错误,我可以建立一个exe文件:)
    • 很高兴我能帮上忙。
    猜你喜欢
    • 2022-09-29
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 2019-12-02
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多