From bffd181f517c2505a14f68beb160e557c4382ca6 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 21 Nov 2021 16:38:56 +0000 Subject: [PATCH] Tools: Fixed Android build --- packages/app-cli/app/ResourceServer.js | 2 +- packages/lib/net-utils.ts | 4 +--- packages/lib/onedrive-api-node-utils.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/app-cli/app/ResourceServer.js b/packages/app-cli/app/ResourceServer.js index ac6e2ed19..7d424bb7f 100644 --- a/packages/app-cli/app/ResourceServer.js +++ b/packages/app-cli/app/ResourceServer.js @@ -36,7 +36,7 @@ class ResourceServer { } async start() { - this.port_ = await findAvailablePort([9167, 9267, 8167, 8267]); + this.port_ = await findAvailablePort(require('tcp-port-used'), [9167, 9267, 8167, 8267]); if (!this.port_) { this.logger().error('Could not find available port to start resource server. Please report the error at https://github.com/laurent22/joplin'); return; diff --git a/packages/lib/net-utils.ts b/packages/lib/net-utils.ts index 4a32e1f47..03613d487 100644 --- a/packages/lib/net-utils.ts +++ b/packages/lib/net-utils.ts @@ -10,9 +10,7 @@ export async function ip() { return ip.ip; } -export async function findAvailablePort(possiblePorts: number[], extraRandomPortsToTry = 20) { - const tcpPortUsed = require('tcp-port-used'); - +export async function findAvailablePort(tcpPortUsed: any, possiblePorts: number[], extraRandomPortsToTry = 20) { for (let i = 0; i < extraRandomPortsToTry; i++) { possiblePorts.push(Math.floor(8000 + Math.random() * 2000)); } diff --git a/packages/lib/onedrive-api-node-utils.js b/packages/lib/onedrive-api-node-utils.js index 588c18218..2ca123af1 100644 --- a/packages/lib/onedrive-api-node-utils.js +++ b/packages/lib/onedrive-api-node-utils.js @@ -42,7 +42,7 @@ class OneDriveApiNodeUtils { this.api().setAuth(null); - const port = await findAvailablePort(this.possibleOAuthDancePorts(), 0); + const port = await findAvailablePort(require('tcp-port-used'), this.possibleOAuthDancePorts(), 0); if (!port) throw new Error(_('All potential ports are in use - please report the issue at %s', 'https://github.com/laurent22/joplin')); const authCodeUrl = this.api().authCodeUrl(`http://localhost:${port}`);