const { Application } = require('ee-core');
const { app, globalShortcut } = require('electron')
const EE = require('ee-core/ee');
// 是否用户关闭
global.isUserExit = false;
const { app: electronApp } = require("electron");

class Index extends Application {

  constructor() {
    super();
    // this === eeApp;
  }

  /**
   * core app have been loaded
   */
  async ready () {
    // do some things
    electronApp.commandLine.appendSwitch('enable-webgl');
    electronApp.commandLine.appendSwitch("disable-web-security");
  }

  /**
   * electron app ready
   */
  async electronAppReady () {
    // do some things
  }

  /**
   * main window have been loaded
   */
  async windowReady () {
    // todo: 注册一个全局快捷键退出
    globalShortcut.register('CommandOrControl+Shift+Z', () => {
      console.log("Shift+Alt+Z+M is click")
      // const { CoreApp } = EE;
      // CoreApp.appQuit();
      global.isUserExit = true;
      app.quit();
      // const channel = 'shortcut-key';
      // this.electron.mainWindow.webContents.send(channel, "Shift+Alt+Z+M");
    })
    // do some things
    // 延迟加载，无白屏
    const winOpt = this.config.windowsOption;
    if (winOpt.show == false) {
      const win = this.electron.mainWindow;
      win.once('ready-to-show', () => {
        win.show();
        win.focus();
      })
    }

    
  }

  /**
   * before app close
   */  
  async beforeClose () {
    // do some things
     console.log(" index.js beforeClose")
  }
}

Index.toString = () => '[class Index]';
module.exports = Index;