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;
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章