Electron app Failed to get ipaddress when exported as Flatpak

Jul 18, 2021
O

I am trying to make a Flatpak for my little application “OpenSpeedTest-Server”

This is a simple network performance estimation tool. It is working fine on Windows, Mac and Linux (DEB).

1) When i Export the same in Flatpak, Application unable to get the client device ip address.

2) Also i am not able to put a custom icon for my Flatpak.

I used electronforge.

Here is my 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": "support@openspeedtest.com"
  },
  "license": "MIT",
  "config": {
    "forge": {
      "packagerConfig": {
        "icon": "src/icon.png"
      },
      "makers": [
       {
      "name": "@electron-forge/maker-flatpak",
      "config": {
        "name": "OpenSpeedTest_Server",
        "options": {
          "categories": [
            "Utility"
          ],
          "icon": "src/icon.png"
        }
      }
    },
        {
          "name": "@electron-forge/maker-zip",
          "platforms": [
            "darwin"
          ]
        },
        {
          "name": "@electron-forge/maker-deb",
          "config": {}
        },
        {
          "name": "@electron-forge/maker-rpm",
          "config": {}
        }
      ]
    }
  },
  "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"
  },
  "devDependencies": {
    "@davidwinter/electron-forge-maker-snap": "^2.0.4",
    "@electron-forge/cli": "^6.0.0-beta.57",
    "@electron-forge/maker-deb": "^6.0.0-beta.57",
    "@electron-forge/maker-flatpak": "^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"
  }
}

How can i solve this issue?

H

there is no network access during the build phase of flatpak.

O
Replying to #2

Then how can i test this app? and why custom icon is not showing?

H
Replying to #3

You can test manually that it works, ie install it.

O
Replying to #4

I Install using the following command

sudo flatpak install /myFlatpak

It is getting installed. But when i open the app it is showing like the image i posted. No ip address.
also app have no custom icon.

H
Replying to #5

did you give the --share=network permission?

O
Replying to #6

When install right?
sudo flatpak install ‘/home/vishnu/Desktop/app/out/make/flatpak/x86_64/io.atom.electron.OpenSpeedTest-Server_stable_x86_64.flatpak’ --share=network
[sudo] password for vishnu:
error: Unknown option --share=network

Shows unknown option

O

H
Replying to #8

EIther it’s set in the manifest, or you set it when running. The latter being for testing / overriding.

man flatpak-run for details

https://docs.flatpak.org/en/latest/sandbox-permissions-reference.html

O
Replying to #9

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.

ip command might be the issue?

H
Replying to #10

some of these utilities might not be in the sandbox and might need to be added to the manifest.

O
Replying to #11

Yes that was the issue with snap, i added

“stagePackages”: [
“default”,
“iproute2”
]
and issue with snap resolved.
how can i add iproute2 to my flatpak?
“sandbox and might need to be added to the manifest.”
Yes, but how?

O
Replying to #11
 "modules": [
              {
                "name": "zypak",
                "sources": [
                  {
                    "type": "git",
                    "url": "https://github.com/refi64/zypak",
                    "tag": "v2021.02"
                  }
                ]
              },
              {
                "name": "iproute2",
                "sources": [
                  {
                    "type": "git",
                    "url": "https://github.com/shemminger/iproute2.git",
                    "tag": "v5.9.0"
                  }
                ]
              }
            ]
          }
        },

Making for target: flatpak - On platform: linux - For arch: x64 @malept/flatpak-bundler 1> make[1]: Nothing to be done for ‘all’.

  • @malept/flatpak-bundler +2ms*
  • @malept/flatpak-bundler 1> *
  • @malept/flatpak-bundler man*
  • @malept/flatpak-bundler +0ms*
  • @malept/flatpak-bundler 1> make[2]: Nothing to be done for ‘all’.*
  • @malept/flatpak-bundler +6ms*
  • @malept/flatpak-bundler 1> make[2]: Nothing to be done for ‘all’.*
  • @malept/flatpak-bundler +2ms*
  • @malept/flatpak-bundler 1> make[2]: Nothing to be done for ‘all’.*
  • @malept/flatpak-bundler +2ms*
  • @malept/flatpak-bundler 1> install -m 0755 -d /sbin*
  • @malept/flatpak-bundler +3ms*
  • @malept/flatpak-bundler 1> install -m 0755 -d /etc/iproute2*
  • @malept/flatpak-bundler +1ms*
  • @malept/flatpak-bundler 1> install -m 0755 -d /var/lib/arpd*
  • @malept/flatpak-bundler +2ms*
  • @malept/flatpak-bundler 1> install -m 0755 -d /usr/include/iproute2*
  • @malept/flatpak-bundler +1ms*
  • @malept/flatpak-bundler 2> install: cannot change permissions of ‘/usr/include/iproute2’: No such file or directory*
  • @malept/flatpak-bundler +2ms*
  • @malept/flatpak-bundler 2> make: *** [Makefile:90: install] Error 1*
  • @malept/flatpak-bundler +0ms*
  • @malept/flatpak-bundler 2> Error: module iproute2: Child process exited with code 2*
  • @malept/flatpak-bundler +0ms*
    :heavy_multiplication_x: Making for target: flatpak - On platform: linux - For arch: x64

An unhandled error has occurred inside Forge:
An error occured while making for target: flatpak
flatpak-builder failed with status code 1
Error: flatpak-builder failed with status code 1

  • at ChildProcess. (/home/vishnu/Desktop/app/node_modules/@malept/flatpak-bundler/index.js:71:16)*
  • at ChildProcess.emit (events.js:375:28)*
  • at ChildProcess.emit (domain.js:470:12)*
  • at maybeClose (internal/child_process.js:1055:16)*
  • at Socket. (internal/child_process.js:441:11)*
  • at Socket.emit (events.js:375:28)*
  • at Socket.emit (domain.js:470:12)*
  • at Pipe. (net.js:675:12)*
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! OpenSpeedTest-Server@2.1.0 make: electron-forge make
    npm ERR! Exit status 1
    *npm ERR! *
    npm ERR! Failed at the OpenSpeedTest-Server@2.1.0 make script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/vishnu/.npm/_logs/2021-07-19T09_43_05_943Z-debug.log

shows error install: cannot change permissions of ‘/usr/include/iproute2’: No such file or directory

O

Finally i got it working. got help from reddit

"makers": [
        {
          "name": "@electron-forge/maker-flatpak",
          "config": {
            "name": "OpenSpeedTest_Server",
            "options": {
              "categories": [
                "Utility"
              ],
              "icon": {
                "512x512": "src/android-chrome-512x512.png"
              }
            },
            "modules": [
              {
                "name": "zypak",
                "sources": [
                  {
                    "type": "git",
                    "url": "https://github.com/refi64/zypak",
                    "tag": "v2021.02"
                  }
                ]
              },
              {
                "name": "iproute2",
                "make-install-args": [
                  "PREFIX=/app",
                  "CONFDIR=/app/share/iproute2",
                  "SBINDIR=/app/bin"
                ],
                "sources": [
                  {
                    "type": "archive",
                    "url": "https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-5.7.0.tar.xz",
                    "sha256": "725dc7ba94aae54c6f8d4223ca055d9fb4fe89d6994b1c03bfb4411c4dd10f21"
                  }
                ],
                "cleanup": [
                  "/include",
                  "/share/bash-completion",
                  "/share/man"
                ]
              }
            ]
          }
        },