导出为 Snap 时,Electron 应用程序无法获取 IP 地址
Electron app Failed to get ipaddress when exported as Snap
我正在尝试为我的小应用程序制作快照“OpenSpeedTest-Server”这是一个简单的网络性能评估工具。
它在 Windows、Mac 和 Linux (DEB) 上运行良好。当我在 Snap 中导出相同内容时,应用程序无法获取客户端设备的 IP 地址。
我尝试了“限制”:“经典”,并插入网络观察等,但没有任何效果。
我手动添加了“@davidwinter/electron-forge-maker-snap”DevDependency 并将其导出为实际工作的 snap。
唯一的问题是应用程序无法获取设备 ip 地址。
我的电子熔炉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": {
"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"
}
}
{
“name”: “@davidwinter/electron-forge-maker-snap”,
“config”: {
“name”: “OpenSpeedTest_Server”,
“categories”: [
“Utility”
],
“stagePackages”: [
“default”,
“iproute2”
]
}
},
我的开发部门。
},
"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"
},
内网IP负责获取ip地址
https://www.npmjs.com/package/internal-ip
模块 return 是面向互联网接口的地址,由默认网关确定。当由于任何原因无法确定地址时,undefined 将被 returned。
该模块依赖于操作系统工具。在 Linux 和 Android 上,ip 命令必须可用,这取决于发行版,默认情况下可能不会安装。它通常由 iproute2 包提供。 .v4.sync() 和 .v6.sync() 在浏览器中不受支持,只是 return 未定义。
所以我们需要在 stagePackages 中添加 iproute2 才能让它在 snap 上工作。
我正在尝试为我的小应用程序制作快照“OpenSpeedTest-Server”这是一个简单的网络性能评估工具。 它在 Windows、Mac 和 Linux (DEB) 上运行良好。当我在 Snap 中导出相同内容时,应用程序无法获取客户端设备的 IP 地址。
我尝试了“限制”:“经典”,并插入网络观察等,但没有任何效果。
我手动添加了“@davidwinter/electron-forge-maker-snap”DevDependency 并将其导出为实际工作的 snap。
唯一的问题是应用程序无法获取设备 ip 地址。
我的电子熔炉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": {
"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"
}
}
{
“name”: “@davidwinter/electron-forge-maker-snap”,
“config”: {
“name”: “OpenSpeedTest_Server”,
“categories”: [
“Utility”
],
“stagePackages”: [
“default”,
“iproute2”
]
}
},
我的开发部门。
},
"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"
},
内网IP负责获取ip地址
https://www.npmjs.com/package/internal-ip 模块 return 是面向互联网接口的地址,由默认网关确定。当由于任何原因无法确定地址时,undefined 将被 returned。 该模块依赖于操作系统工具。在 Linux 和 Android 上,ip 命令必须可用,这取决于发行版,默认情况下可能不会安装。它通常由 iproute2 包提供。 .v4.sync() 和 .v6.sync() 在浏览器中不受支持,只是 return 未定义。
所以我们需要在 stagePackages 中添加 iproute2 才能让它在 snap 上工作。