随笔 - 26  文章 - 0  评论 - 0  阅读 - 12435

主进程窗口全屏显示,设置无边框,取消菜单狼,导致点击事件失去作用 electron vue

复制代码
async function createWindow() {
  // 注入小段css文件
  // mainWindow.webContents.insertCSS(" body,html { -webkit-app-region: drag !important;}")
  // body,html { -webkit-app-region: drag; } 
  // path获取本机mac地址
  var path = require('path')
  // Create the browser window.
  Menu.setApplicationMenu(null) // null值取消顶部菜单栏
  const win = new BrowserWindow({
    width: 1920,
    height: 1080,
    // 隐藏导航栏
    // autoHideMenuBar: true,
    // 全屏显示
    // fullscreenable: true,
    // fullscreen: true,
    // simpleFullscreen: true,
    // 无边框窗口
    frame:false,
    // transparent: true,
    webPreferences: {
      webSecurity:false,

      // 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,
      contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,

      nodeIntegration: true,
      contextIsolation: false,


      // preload: path.join(__dirname, 'preload.js'),
    }
  })

  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)
    if (!process.env.IS_TEST) win.webContents.openDevTools()
  } else {
    createProtocol('app')
    // Load the index.html when not in development
    win.loadURL('app://./index.html')
  }
}
复制代码

 

隐藏菜单栏,再加一项

复制代码
app.on('ready', async () => {
  // 这段没啥用
  if (isDevelopment && !process.env.IS_TEST) {
    // Install Vue Devtools
    try {
      await installExtension(VUEJS_DEVTOOLS)
    } catch (e) {
      console.error('Vue Devtools failed to install:', e.toString())
    }
  }
  createWindow()
  // 隐藏菜单栏
  const {
        Menu
    } = require('electron');
    Menu.setApplicationMenu(null);
  // 隐藏mac菜单栏
    // hide menu for Mac 
    if (process.platform !== 'darwin') {
        app.dock.hide();
    }
})
复制代码

 

posted on   阿术阿术  阅读(280)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示