电子应用程序窗口在为Mac分发时不会获得焦点

时间:2018-04-23 16:15:15

标签: electron electron-builder electron-packager

这对我来说很奇怪。我有一个Electron应用程序,当我在本地运行时工作正常。但是,当我npm run dist创建本机版本时,生成的应用程序在单击它时无法获得焦点。我点击窗口中的文本字段,然后出现一个闪烁的光标,当我输入击键时,它们会转到我以前的窗口(例如Finder)。这只发生在Mac(Windows工作正常),当我使用打包版本时。

非常令人困惑的事情:)

我的package.json看起来像这样(清理了一些名称和URL):

{
  "name": "Myapp",
  "productName": "MyApp",
  "version": "0.0.44",
  "description": "MyApp",
  "license": "",
  "repository": "",
  "main": "./main.js",
  "author": {
    "name": "MyApp Ltd.",
    "email": "c@c.com",
    "url": "www.c.com"
  },
  "engines": {
    "node": ">=4"
  },
  "electronVersion": "1.8.3",
  "scripts": {
    "test": "mocha",
    "start": "electron .",
    "pack": "build --dir",
    "dist": "build"
  },
  "build": {
    "appId": "MyApp",
    "win": {
      "target": "squirrel",
      "icon": "assets/icons/Windows_Icon.ico"
    },
    "squirrelWindows": {
      "loadingGif": "assets/img/installing.gif",
      "iconUrl": "https:/fake-url.com/icon.ico",
      "msi": false
    },
    "dmg": {
      "window": {
        "x": 200,
        "y": 200,
        "width": 537,
        "height": 374
      },
      "icon": "assets/icons/Mac_Icon.icns",
      "background": "assets/img/dmg-background.png"
    },
    "mac": {
      "icon": "assets/icons/Mac_Icon.icns",
      "extendInfo": {
        "LSBackgroundOnly": 1
      }
    }
  },
  "dependencies": {
    "azure-event-hubs": "0.0.4",
    "babel-polyfill": "^6.20.0",
    "bootstrap": "^3.3.7",
    "chokidar": "^1.6.1",
    "download": "^5.0.2",
    "electron-debug": "^0.3.0",
    "electron-is-dev": "^0.3.0",
    "electron-json-storage": "^3.0.4",
    "electron-log": "^2.2.6",
    "electron-positioner": "^3.0.0",
    "electron-squirrel-startup": "^1.0.0",
    "follow-redirects": "^1.2.3",
    "glob": "^7.1.1",
    "howler": "^2.0.3",
    "jquery": "^3.2.1",
    "nan": "^2.1.0",
    "nconf": "^0.7.2",
    "node-schedule": "^1.2.5",
    "opener": "^1.4.3",
    "pusher-js": "^4.1.0",
    "sqlite3": "^3.1.8",
    "unirest": "^0.5.1"
  },
  "devDependencies": {
    "chai": "^4.0.2",
    "chai-as-promised": "^6.0.0",
    "electron": "^1.8.3",
    "electron-builder": "^20.8.0",
    "electron-builder-squirrel-windows": "^20.9.0",
    "electron-installer-dmg": "^0.2.1",
    "electron-packager": "^5.1.1",
    "mocha": "^3.2.0",
    "spectron": "^3.0.0",
    "xo": "^0.10.0"
  },
  "xo": {
    "esnext": true,
    "envs": [
      "node",
      "browser"
    ]
  }
}

1 个答案:

答案 0 :(得分:1)

Mac中的LSBackgroundOnly选项显然具有这种效果,因为它将应用程序指定为后台应用程序,并且可能没有事件传递给它。一旦我将其设置为false,问题就解决了。