0
点赞
收藏
分享

微信扫一扫

electron v1.x、v2.x 写法

_刘彦辉 2022-02-12 阅读 60
const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')


function createWindow () {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })
  mainWindow.loadURL(url.format({undefined,
    pathname: path.join(__dirname, 'index.html'),
    
    protocol: 'file:',
    
    slashes: true
    
    }))
  // and load the index.html of the app.

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()
}

app.on("ready",()=>{
  createWindow()

  app.on('activate', function () {
    // On macOS it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})
举报

相关推荐

0 条评论