zoukankan      html  css  js  c++  java
  • electron 学习

    index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Document</title>
    </head>
    <body>
      <h1>Hello world !!!!!!!!!!!!!!</h1>
    
    </body>
    <script>
      document.write('node:')
      document.write(process.versions.node)
      document.write('chrome:')
      document.write(process.versions.chrome)
      document.write('electron:')
      document.write(process.versions.electron)
      console.log(process.versions)
    </script>
    </html>
    

      main.js

    const electron = require('electron')
    const path = require('path')
    
    const app = electron.app
    const Menu = electron.Menu
    
    const MenuItem = electron.MenuItem
    
    const BrowserWindow = electron.BrowserWindow
    
    let mainWindow = null
    
    app.on('ready', createWindow)
    
    
    // 当所有的窗口都被关闭时触发。
    // 默认的行为是控制退出程序;但如果你监听了此事件,你可以控制是否退出程序。 
    // 如果用户按下了 Cmd + Q,或者开发者调用了 app.quit(),Electron 会首先关闭所有的窗口然后触发 will-quit 事件,在这种情况下 window-all-closed 事件不会被触发。
    // Quit when all windows are closed.
    app.on('window-all-closed', function() {
      if (process.platform !== 'darwin') {
        app.quit()
      }
    })
    
    app.on('activate', () => {
      // 在macOS上,当单击dock图标并且没有其他窗口打开时,
      // 通常在应用程序中重新创建一个窗口。
      if (win === null) {
        createWindow()
      }
    })
    
    function createWindow() {
      if (mainWindow) {
        mainWindow.show()
        return
      }
      mainWindow = new BrowserWindow({
        backgroundColor: '#999',
         800, 
        height: 600,
        x: 100,
        y: 100,
        icon: path.__dirname + '/src/asset/icon.ico'
        // frame: false
      })
      console.log(process.env.GOOGLE_API_KEY)
      mainWindow.webContents.openDevTools()
      // mainWindow.loadFile('index.html')
      mainWindow.loadURL('file://' + __dirname + '/index.html')
      mainWindow.on('minimize', function() {
        mainWindow.hide()
      })
      mainWindow.on('maximize', function() {
        console.log('maximize')
      })
      mainWindow.on('resize', function() {
        // console.log('resized')
      })
      mainWindow.on('closed', function() {
        mainWindow = null
      })
    }
    

     package.json 

    {
    "name": "demo",
    "version": "1.0.0",
    "description": "",
    "main": "main.js",
    "scripts": {
    "test": "echo "Error: no test specified" && exit 1",
    "dev": "electron ."
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
    "electron": "^2.0.8"
    }
    }
  • 相关阅读:
    input失效后,怎么改变它默认就有的灰色
    弹性盒布局-宽度自动分配-图片自适应
    时钟效果收集
    1秒加1
    tab切换☆☆☆☆☆
    音乐播放的动画效果
    css3-文字旋转
    红黑树
    Ruby2.0后版本的debug工具: byebug
    [转]DSL-让你的 Ruby 代码更优秀
  • 原文地址:https://www.cnblogs.com/lfqcode/p/9534427.html
Copyright © 2011-2022 走看看