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.

55 lines
1.7 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. // contextIsolation: false,
  16. // enableRemoteModule:true,
  17. nodeIntegration: node,
  18. // webviewTag: true,
  19. // devTools: true,
  20. // preload: path.join(__dirname, 'preload.js')
  21. webSecurity: false,
  22. contextIsolation: false,
  23. enableRemoteModule:true,
  24. nodeIntegration: node,
  25. preload: path.join(__dirname, 'preload.js')
  26. },
  27. ...options
  28. })
  29. win[MANUAL_CREATED_FLAG] = true
  30. console.log('openWindow', url)
  31. win.loadURL(url);
  32. sinceTimeEnd('loadURL')
  33. // 清除缓存
  34. // const ses = win.webContents.session
  35. // ses.clearCache()
  36. // 启用remote模块
  37. remote.enable(win.webContents)
  38. // 注册快捷键
  39. win.on('focus', () => {
  40. globalShortcut.register('CommandOrControl+Alt+F', function () {
  41. win && win.webContents.toggleDevTools();
  42. })
  43. });
  44. win.on('blur', () => {
  45. globalShortcut.unregisterAll() // 注销键盘事件
  46. })
  47. // win.webContents.openDevTools() // Open the DevTools.
  48. return win
  49. }
  50. module.exports = { createWindow }