0
点赞
收藏
分享

微信扫一扫

Electron三个基本配置 版本“^13.0.0“(在vue3中)

李雨喵 2022-03-19 阅读 42

Electron官方文档 - 不科学上网可能进不去icon-default.png?t=M276https://www.electronjs.org/zh/docs/

0、配置文件在根目录的background.ts或js中

1、最大最小宽度、打开控制台快捷键、隐藏头部菜单(直接写在对应函数中)

import { app, protocol, BrowserWindow, Menu, globalShortcut } from 'electron'
async function createWindow() {
  // Create the browser window.
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    minWidth: 600,
    minHeight: 200,
    maxHeight: 900,
    maxWidth: 1200,
    // titleBarStyle: 'hidden',
    // transparent: true, // 透明窗口
    webPreferences: {

      // Use pluginOptions.nodeIntegration, leave this alone
      // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
      nodeIntegration: (process.env
        .ELECTRON_NODE_INTEGRATION as unknown) as boolean,
      contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
      // nodeIntegration: true,
      enableRemoteModule: true,
    }
  })
  Menu.setApplicationMenu(null); // 取消上面menu菜单  cancel menu
  if (process.env.WEBPACK_DEV_SERVER_URL) {
    // Load the url of the dev server if in development mode
    await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string)
    if (!process.env.IS_TEST) win.webContents.openDevTools()
  } else {
    createProtocol('app')
    // Load the index.html when not in development
    win.loadURL('app://./index.html')
  }

  // 设置打开控制台的快捷键
  if (isDevelopment && !process.env.IS_TEST) {
    // electron新增全局快捷键操作 (alt + commend/control + i)
    globalShortcut.register('Alt+CommandOrControl+I', () => {
      win.webContents.openDevTools()
      console.log('打开控制台 open devTools')
    })
  }
}
举报

相关推荐

0 条评论