Reputation: 631
In folder providers in electron.service.ts I have code:
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;
}
}
In component I have method:
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();
}
When I write in my project
win: BrowserWindow;
I get error Cannot find name 'BrowserWindow'. What is wrong? I did import { ipcRenderer, webFrame, remote, BrowserWindow } from 'electron'; I can't rewrite instead
win: typeof BrowserWindow;
because in method toggleFullScreen() will not be to able method isFullScreen(), show(),setFullScreen().
App work good in develop mode, but I have error and I can't build exe file. How fix that?
Upvotes: 1
Views: 634
Reputation: 3624
This is what I am familiar with
const {BrowserWindow} = require('electron')
let win = new BrowserWindow({width: 800, height: 600})
Edit : I have seen online where the type is specified as
win: Electron.BrowserWindow
Upvotes: 1