/**
 * 加载医生客户端函数
 */
const path=require('path');
const log = require(".."+path.sep+"setting"+path.sep+"set_log").clog;
const electron = require('electron');
const screen = electron.screen;
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const print_monitor=require(".."+path.sep+"setting"+path.sep+"print_monitor");
const finger_monitor=require(".."+path.sep+"setting"+path.sep+"finger_monitor");

let doc={
  createDocWindow:function (apppath,respath,main,url,updateHandle){
    //阻止应用多开
    const gotTheLock = app.requestSingleInstanceLock();
    if (!gotTheLock) {
      app.quit();
    }
    log.info("加载医生客户端窗口...")
    let win = new BrowserWindow({
      width: (screen.getPrimaryDisplay().workAreaSize.width / 4) * 3,
      height: (screen.getPrimaryDisplay().workAreaSize.height / 4) * 3,
      title: "钜星科技便民问诊系统 版本 2.0",
      frame: true,
      show: true,
      icon: respath +path.sep+"static"+path.sep+"images"+path.sep+"justar.ico",
      webPreferences: {
        nodeIntegration: true,
        //禁止远程页面调用electron框架的window.open
        nativeWindowOpen: true,
        //允许跨域请求
        webSecurity: false,
        //允许远程调用
        enableRemoteModule: true,
        //防止require引入失败
        contextIsolation:false
      }
    });
    main.registerDevTool(win);
    win.loadURL(url);
    win.setMenu(null);
    main.taskbarStar(win);
    main.winTop(win);

    //开启指纹登录监听程序
    finger_monitor.runFingerMonitor(respath);

    //开启打印列表页面监听
    print_monitor.openPrinterMonitor(win,apppath,respath,main);

    //监听最后一个窗口被关闭时,退出程序
    win.on("close", (e) => {
      e.preventDefault();
      main.exitSoft(respath);
    });
    updateHandle(win);
  }
}

module.exports=doc;