From e894dbc4e810cbcfca116876c574534b082a623e Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 13 Apr 2021 14:34:30 -0400 Subject: [PATCH 1/3] fix: Trim origin url in desktop --- ui/desktop/app/services/origin.js | 3 ++- ui/desktop/tests/unit/services/origin-test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/desktop/app/services/origin.js b/ui/desktop/app/services/origin.js index 9ca0895f2..c6f6a4580 100644 --- a/ui/desktop/app/services/origin.js +++ b/ui/desktop/app/services/origin.js @@ -66,7 +66,8 @@ export default class OriginService extends Service { // Silently drop trailing slashes if present. // This is important since API paths that will be appended to the origin // will include preceeding slashes already. - origin = origin.replace(/\/*$/, ''); + // Trim whitespaces around origin. + origin = origin.replace(/\/*$/, '').trim(); this.adapter.host = origin; this.rendererOrigin = origin; if (origin !== (await this.mainOrigin)) { diff --git a/ui/desktop/tests/unit/services/origin-test.js b/ui/desktop/tests/unit/services/origin-test.js index cc6cdfa69..88746b92a 100644 --- a/ui/desktop/tests/unit/services/origin-test.js +++ b/ui/desktop/tests/unit/services/origin-test.js @@ -35,4 +35,15 @@ module('Unit | Service | origin', function (hooks) { assert.equal(service.rendererOrigin, window.location.origin); assert.equal(service.adapter.host, window.location.origin); }); + + test('trim spaces from origin on setOrigin', async function (assert) { + assert.expect(4); + sinon.stub(ipcService, 'invoke'); + await service.setOrigin(` ${window.location.origin} `); + assert.equal(service.rendererOrigin, window.location.origin); + assert.equal(service.adapter.host, window.location.origin); + await service.setOrigin(` ${window.location.origin} `); + assert.equal(service.rendererOrigin, window.location.origin); + assert.equal(service.adapter.host, window.location.origin); + }); }); From 1a901b15d2ffafe9e8237734ec54d2f90525e571 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 13 Apr 2021 16:56:21 -0400 Subject: [PATCH 2/3] fix: Trim first to avoid leaving trailing slashes in origin --- ui/desktop/app/services/origin.js | 6 +++--- ui/desktop/tests/unit/services/origin-test.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/desktop/app/services/origin.js b/ui/desktop/app/services/origin.js index c6f6a4580..c3e27c358 100644 --- a/ui/desktop/app/services/origin.js +++ b/ui/desktop/app/services/origin.js @@ -63,11 +63,11 @@ export default class OriginService extends Service { typeof origin === 'string' ); try { - // Silently drop trailing slashes if present. + // Trim whitespaces and silently drop trailing slashes if present. // This is important since API paths that will be appended to the origin // will include preceeding slashes already. - // Trim whitespaces around origin. - origin = origin.replace(/\/*$/, '').trim(); + origin = origin.trim(); + origin = origin.replace(/\/*$/, ''); this.adapter.host = origin; this.rendererOrigin = origin; if (origin !== (await this.mainOrigin)) { diff --git a/ui/desktop/tests/unit/services/origin-test.js b/ui/desktop/tests/unit/services/origin-test.js index 88746b92a..7c759713f 100644 --- a/ui/desktop/tests/unit/services/origin-test.js +++ b/ui/desktop/tests/unit/services/origin-test.js @@ -39,7 +39,7 @@ module('Unit | Service | origin', function (hooks) { test('trim spaces from origin on setOrigin', async function (assert) { assert.expect(4); sinon.stub(ipcService, 'invoke'); - await service.setOrigin(` ${window.location.origin} `); + await service.setOrigin(` ${window.location.origin}/ `); assert.equal(service.rendererOrigin, window.location.origin); assert.equal(service.adapter.host, window.location.origin); await service.setOrigin(` ${window.location.origin} `); From 906a336acb60979878deafa539f5bb4adc05a4e2 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 13 Apr 2021 18:11:07 -0400 Subject: [PATCH 3/3] fix: Undefined type issue when not suppressing update dialog --- ui/desktop/electron-app/src/app-updater.js | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ui/desktop/electron-app/src/app-updater.js b/ui/desktop/electron-app/src/app-updater.js index b758a6eac..a4982834d 100644 --- a/ui/desktop/electron-app/src/app-updater.js +++ b/ui/desktop/electron-app/src/app-updater.js @@ -90,7 +90,7 @@ const downloadAndInstallUpdate = async (version) => { * TODO: download progress in dialog **/ module.exports = { - run: async ({ suppressNoUpdatePrompt }) => { + run: async ({ suppressNoUpdatePrompt } = {}) => { let latestVersion; if (debug) { latestVersion = process.env.APP_UPDATER_LATEST_VERSION_TAG; @@ -104,7 +104,8 @@ module.exports = { } // Update not available - do nothing - if (!suppressNoUpdatePrompt && semver.lte(latestVersion, currentVersion)) { + if (semver.lte(latestVersion, currentVersion)) { + if (suppressNoUpdatePrompt) return; const dialogOpts = { type: 'info', icon: null, @@ -112,21 +113,20 @@ module.exports = { }; dialog.showMessageBox(dialogOpts); - return; + } else { + // Update is available - prompt for download + const dialogOpts = { + type: 'info', + buttons: ['Download', 'Later'], + icon: null, + detail: 'A new version is available for download', + }; + + dialog.showMessageBox(dialogOpts).then((returnValue) => { + if (returnValue.response === 0) { + downloadAndInstallUpdate(latestVersion); + } + }); } - - // Update is available - prompt for download - const dialogOpts = { - type: 'info', - buttons: ['Download', 'Later'], - icon: null, - detail: 'A new version is available for download', - }; - - dialog.showMessageBox(dialogOpts).then((returnValue) => { - if (returnValue.response === 0) { - downloadAndInstallUpdate(latestVersion); - } - }); }, };