diff --git a/options/options.html b/options/options.html index 4af29c825..1eb265e10 100644 --- a/options/options.html +++ b/options/options.html @@ -13,7 +13,7 @@

Trilium desktop instance

-

Web clipper by default tries to find a running desktop instance on ports 37740 - 37749. If you configured your Trilium desktop app to run on a different port, you can specify it here (otherwise keep it empty).

+

Web clipper by default tries to find a running desktop instance on port 37740. If you configured your Trilium desktop app to run on a different port, you can specify it here (otherwise keep it empty).

@@ -64,4 +64,4 @@ - \ No newline at end of file + diff --git a/trilium_server_facade.js b/trilium_server_facade.js index 0daa1d2eb..8b82f1d53 100644 --- a/trilium_server_facade.js +++ b/trilium_server_facade.js @@ -53,34 +53,32 @@ class TriliumServerFacade { async triggerSearchForTrilium() { this.setTriliumSearch({ status: 'searching' }); - const startingPort = await this.getStartingPort(); + try { + const port = await this.getPort(); - for (let testedPort = startingPort; testedPort < startingPort + 10; testedPort++) { - try { - console.debug('Trying port ' + testedPort); + console.debug('Trying port ' + port); - const resp = await fetch(`http://127.0.0.1:${testedPort}/api/clipper/handshake`); + const resp = await fetch(`http://127.0.0.1:${port}/api/clipper/handshake`); - const text = await resp.text(); + const text = await resp.text(); - console.log("Received response:", text); + console.log("Received response:", text); - const json = JSON.parse(text); + const json = JSON.parse(text); - if (json.appName === 'trilium') { - this.setTriliumSearchWithVersionCheck(json, { - status: 'found-desktop', - port: testedPort, - url: 'http://127.0.0.1:' + testedPort - }); + if (json.appName === 'trilium') { + this.setTriliumSearchWithVersionCheck(json, { + status: 'found-desktop', + port: port, + url: 'http://127.0.0.1:' + port + }); - return; - } - } - catch (error) { - // continue + return; } } + catch (error) { + // continue + } const {triliumServerUrl} = await browser.storage.sync.get("triliumServerUrl"); const {authToken} = await browser.storage.sync.get("authToken"); @@ -136,7 +134,7 @@ class TriliumServerFacade { }); } - async getStartingPort() { + async getPort() { const {triliumDesktopPort} = await browser.storage.sync.get("triliumDesktopPort"); if (triliumDesktopPort) {