const { app, Menu, shell,ipcMain,BrowserWindow,session,Notification,nativeImage   } = require('electron')

function createWindow () {   
  // // 创建浏览器窗口
  let win = new BrowserWindow({
    width: 1200,
    height: 1200,
    // fullscreen :true,
    webPreferences: {
      nodeIntegration: false,
      preload: app.getAppPath()+'/src/global.js',
    }
  })

  app.MainWindow = win;
  if(Notification.isSupported()){
    // let no = new Notification({title:'吴赐有'});
    // setTimeout(function(){
    //   no.show();
    // },1000);
  }
  console.info('Notification',Notification,Notification.isSupported());
  win.on('closed',()=>{
    console.info('应用关闭');
    app.quit();
  })
  win.loadURL('https://www.vmiaopu.com/login.html');
  // win.loadFile('./src/html/index.html');
  // win.webContents.openDevTools()
  // win.flashFrame(true);
  // 创建菜单
  createMenu();
}

function createMenuv1(){
  const isMac = process.platform === 'darwin'

const template = [
  {
    label: '应用',
    submenu: [
      isMac ? { role: 'close',label:'退出程序'  } : { role: 'quit',label:'退出程序'  }
    ]
  },
  // { role: 'editMenu' }
  {
    label: '编辑',
    submenu: [
      // { type: 'separator' }, // 橫线
      { role: 'cut',label:'剪切' },
      { role: 'copy',label:'复制' },
      { role: 'paste',label:'粘贴' },
    ]
  },
  // { role: 'viewMenu' }
  {
    label: '窗口',
    submenu: [
      { role: 'reload',label:'刷新页面' },
      { role: 'minimize',label:'最小化' },
      // { role: 'zoom',label:'最大化' },
      { role: 'togglefullscreen',label:'进入全屏' }
    ]
  },
  {
    role: '帮助',
    submenu: [
      {
        label: '访问官网',
        click: async () => {
          const { shell } = require('electron')
          await shell.openExternal('https://www.vmiaopu.com')
        }
      }
    ]
  }
]

const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}

function createMenu(){
  createMenuv1();



   const contextMenuTemplate = [
    {
      label: '撤销',
      role: 'undo',
    },
    {
      label: '恢复',
      role: 'redo',
    },
    { role: 'reload',
      label:'刷新'
    },
    {
      type: 'separator',
    },
    {
      label: '剪切',
      role: 'cut',
    },
    {
      label: '复制',
      role: 'copy',
    },
    {
      label: '粘贴',
      role: 'paste',
    },
    {
      type: 'separator',
    },  // 分隔线
    {
      label: '全选',
      role: 'selectall',
    },
    {
      type: 'separator',
    },
    { role: 'zoom',label:'最大化' },
    { role: 'togglefullscreen',label:'进入全屏' }
    // Select All菜单项
  ];
  const contextMenu = Menu.buildFromTemplate(contextMenuTemplate);
  // 监听右键事件

  ipcMain.on('contextmenu', (e) => {
    contextMenu.popup(BrowserWindow.getFocusedWindow());
  });

// let template = [{
//         label: "Application",
//         submenu: [
//             { label: "About Application", selector: "orderFrontStandardAboutPanel:" },
//             { type: "separator" },
//             { label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }}
//         ]}, {
//         label: keysBinding["Edit"],
//         submenu: [
//             { label: keysBinding["Undo"], accelerator: "CmdOrCtrl+Z", selector: "undo:" },
//             { label: keysBinding["Redo"], accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
//             { type: "separator" },
//             { label: keysBinding["Cut"], accelerator: "CmdOrCtrl+X", selector: "cut:" },
//             { label: keysBinding["Copy"], accelerator: "CmdOrCtrl+C", selector: "copy:" },
//             { label: keysBinding["Paste"], accelerator: "CmdOrCtrl+V", selector: "paste:" },
//             { label: keysBinding["Select All"], accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
//         ]}
//     ];
}

app.whenReady().then(createWindow)