javascript - 找不到名称“浏览器窗口”
问题描述
在 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”。怎么了?我确实从 'electron' 导入 { ipcRenderer, webFrame, remote, BrowserWindow }; 我不能改写
win: typeof BrowserWindow;
因为在方法 toggleFullScreen() 中将无法使用方法 isFullScreen()、show()、setFullScreen()。应用程序在开发模式下运行良好,但出现错误,无法构建 exe 文件。如何解决?
解决方案
这是我熟悉的
const {BrowserWindow} = require('electron')
let win = new BrowserWindow({width: 800, height: 600})
编辑:我在网上看到类型被指定为
win: Electron.BrowserWindow
推荐阅读
- c++ - 用 C++ 构建一个不需要类实例化的库
- vue.js - Vue 3 中的可挂起组件是什么?
- react-native - 如何在 React Native 中重置 Picker 的选定值
- amazon-web-services - AWS ECS 集群自动扩展与服务自动扩展
- npm - 减少 Vuetify 的包大小
- java - Java Sockets - 从服务器发送对象并将其接收/显示给客户端
- javascript - readline 传递了回调 on.close 执行顺序
- react-navigation - 在 react-navigation 的嵌套堆栈导航中。它不会向上滚动
- php - PHP echo 在源代码中实现在哪里?
- javascript - Javascript 确认重定向无法正常工作