Search code examples
electronelectron-builderelectron-forgesnapcraft

Electron app Failed to get ipaddress when exported as Snap


I am trying to make a snap for my little application “OpenSpeedTest-Server” This is a simple network performance estimation tool. It is working fine on Windows, Mac and Linux (DEB). When i Export the same in Snap, Application unable to get the client device ip address.

i try “confinement”: “classic”, and plugs network observe etc. but nothing worked.

I added “@davidwinter/electron-forge-maker-snap” DevDependency manually and exporting it as snap actually working.

The only problem is application cannot get device ip address.

enter image description here

My Electron Forge package.json

{
  "name": "OpenSpeedTest-Server",
  "productName": "OpenSpeedTest-Server",
  "version": "2.1.0",
  "description": "Network Speed Test Server - by OpenSpeedTest",
  "main": "src/index.js",
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make",
    "publish": "electron-forge publish",
    "lint": "echo \"No linting configured\""
  },
  "keywords": [],
  "author": {
    "name": "OpenSpeedTest",
    "email": "[email protected]"
  },
  "license": "MIT",
  "config": {
    "confinement": "devmode",
    "forge": {
      "packagerConfig": {
        "icon": "src/icon.png"
      },
      "makers": [
        {
          "name": "@davidwinter/electron-forge-maker-snap",
          "config": {
            "name": "OpenSpeedTest_Server",
            "categories": [
              "Utility"
            ]
          }
        },
        {
          "name": "@electron-forge/maker-zip",
          "platforms": [
            "darwin"
          ]
        },
        {
          "name": "@electron-forge/maker-deb",
          "config": {}
        },
        {
          "name": "@electron-forge/maker-rpm",
          "config": {}
        }
      ]
    }
  },
  "dependencies": {
    "@davidwinter/electron-forge-maker-snap": "^2.0.4",
    "cors": "^2.8.5",
    "electron-squirrel-startup": "^1.0.0",
    "express": "^4.17.1",
    "internal-ip": "^6.2.0",
    "tcp-port-used": "^1.0.2"
  },
  "devDependencies": {
    "@electron-forge/cli": "^6.0.0-beta.57",
    "@electron-forge/maker-deb": "^6.0.0-beta.57",
    "@electron-forge/maker-rpm": "^6.0.0-beta.57",
    "@electron-forge/maker-squirrel": "^6.0.0-beta.57",
    "@electron-forge/maker-zip": "^6.0.0-beta.57",
    "electron": "13.1.2"
  }
}

Solution

  • {
    “name”: “@davidwinter/electron-forge-maker-snap”,
    “config”: {
    “name”: “OpenSpeedTest_Server”,
    “categories”: [
    “Utility”
    ],
    “stagePackages”: [
    “default”,
    “iproute2”
    ]
    }
    },
    

    My devDep.

    },
    "dependencies": {
    "cors": "^2.8.5",
    "electron-squirrel-startup": "^1.0.0",
    "express": "^4.17.1",
    "internal-ip": "^6.2.0",
    "tcp-port-used": "^1.0.2"
    },
    

    Internal IP is responsible for getting ip address.

    https://www.npmjs.com/package/internal-ip The module returns the address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, undefined will be returned. The module relies on operating systems tools. On Linux and Android, the ip command must be available, which depending on distribution might not be installed by default. It is usually provided by the iproute2 package. .v4.sync() and .v6.sync() are not supported in browsers and just return undefined.

    so we need to add iproute2 in stagePackages for get this to work on snap.