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.

46 lines
1.3 KiB

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