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