Electron获取系统windows对象

// 开发环境:Angular5+Electron

// 遇到问题: 在angular5页面中如何获得windows对象

解决如下:

import { Injectable } from '@angular/core';
import { ipcRenderer  } from 'electron';
import * as childProcess from 'child_process';

// add this
import BrowserWindow = Electron.BrowserWindow;
import Shell = Electron.Shell;

@Injectable()
export class ElectronService {

  ipcRenderer: typeof ipcRenderer;
  childProcess: typeof childProcess;
  // and this
  window: BrowserWindow;
    shell: Shell;

  constructor() {
    if (this.isElectron()) {
      this.ipcRenderer = window.require('electron').ipcRenderer;
      this.childProcess = window.require('child_process');
      // and this too
      this.window = window.require('electron').remote.getCurrentWindow();  
            this.shell = require('electron').shell;
    }
  }

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

你可能感兴趣的:(WEB前端开发,Angular2+,Electron)