electron launcher
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.5 KiB

2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
  1. const { BrowserWindow,Menu,globalShortcut, ipcMain, desktopCapturer } = require('electron')
  2. const path = require('path')
  3. const { MANUAL_CREATED_FLAG } = require('../../constant')
  4. const {sinceTimeEnd} = require('../../SinceTimeTool')
  5. // 引入初始化remote模块
  6. const remote = require('@electron/remote/main')
  7. remote.initialize()
  8. function createWindow(url,options,node=false) {
  9. Menu.setApplicationMenu(null);
  10. const win = new BrowserWindow({
  11. // width: 870,
  12. // height: 530,
  13. webPreferences: {
  14. // webSecurity: false,
  15. nodeIntegration: node,
  16. webSecurity: false,
  17. contextIsolation: false,
  18. enableRemoteModule:true,
  19. nodeIntegration: node,
  20. preload: path.join(__dirname, 'preload.js')
  21. },
  22. ...options
  23. })
  24. win[MANUAL_CREATED_FLAG] = true
  25. console.log('openWindow', url)
  26. win.loadURL(url);
  27. sinceTimeEnd('loadURL')
  28. // 清除缓存
  29. // const ses = win.webContents.session
  30. // ses.clearCache()
  31. // 启用remote模块
  32. remote.enable(win.webContents)
  33. // 注册快捷键
  34. win.on('focus', () => {
  35. globalShortcut.register('CommandOrControl+Alt+F', function () {
  36. win && win.webContents.toggleDevTools();
  37. })
  38. });
  39. win.on('blur', () => {
  40. globalShortcut.unregisterAll() // 注销键盘事件
  41. })
  42. // win.webContents.openDevTools() // Open the DevTools.
  43. return win
  44. }
  45. module.exports = { createWindow }