From 206d9479fc9897c37c4e956d37cd20e2e2fd58e1 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Wed, 6 Sep 2023 22:30:42 -0700 Subject: [PATCH] moving open external link functionality into shared lib. --- .../app/directives/external-link.directive.ts | 16 +++------------- frontend/src/app/services/lighthouse.service.ts | 7 +++++-- frontend/src/lib/utils/external_link.ts | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 frontend/src/lib/utils/external_link.ts diff --git a/frontend/src/app/directives/external-link.directive.ts b/frontend/src/app/directives/external-link.directive.ts index 62c55b6f..e7bea1ae 100644 --- a/frontend/src/app/directives/external-link.directive.ts +++ b/frontend/src/app/directives/external-link.directive.ts @@ -1,5 +1,6 @@ import {Directive, HostBinding, HostListener, Input} from '@angular/core'; import {environment} from '../../environments/environment'; +import {OpenExternalLink} from '../../lib/utils/external_link'; // In desktop mode external links can allow the user to navigate away from the app, without any means to return. // We can prevent this by forcing all external links to open in a new tab @@ -37,19 +38,8 @@ export class ExternalLinkDirective { onClick(event: MouseEvent) { event.preventDefault(); - let url: string = (event.currentTarget).getAttribute("href") || (event.target).getAttribute("href"); + let url: string = ( event.currentTarget).getAttribute("href") || ( event.target).getAttribute("href"); - //check if url starts with https, and if not, prepend it (external links are never relative) - if(!url.startsWith("https://") && !url.startsWith("http://")){ - url = "https://" + url; - } - - //check if wails exists and is defined - if(typeof wails !== "undefined" && environment.environment_desktop){ - wails.CallByName("pkg.AppService.BrowserOpenURL", url) - } else{ - window.open(url, "_blank"); - } + OpenExternalLink(url, environment.environment_desktop) } - } diff --git a/frontend/src/app/services/lighthouse.service.ts b/frontend/src/app/services/lighthouse.service.ts index da260d6f..4cb8ee43 100644 --- a/frontend/src/app/services/lighthouse.service.ts +++ b/frontend/src/app/services/lighthouse.service.ts @@ -12,6 +12,7 @@ import {uuidV4} from '../../lib/utils/uuid'; import {LighthouseSourceSearch} from '../models/lighthouse/lighthouse-source-search'; import {HTTP_CLIENT_TOKEN} from "../dependency-injection"; import {MedicalSourcesFilter} from './medical-sources-filter.service'; +import {OpenExternalLink} from '../../lib/utils/external_link'; export const sourceConnectDesktopTimeout = 24*5000 //wait 2 minutes (5 * 24 = 120) @@ -169,9 +170,11 @@ export class LighthouseService { //if we're in desktop mode, we can open a new window, rather than redirecting the current window (which is an app frame) if(environment.environment_desktop && environment.popup_source_auth){ //@ts-ignore - let openedWindow = window.runtime.BrowserOpenURL(redirectUrlParts.toString()); - this.waitForDesktopCodeOrTimeout(openedWindow, sourceType).subscribe(async (codeData) => { + OpenExternalLink(redirectUrlParts.toString(), environment.environment_desktop) + // let openedWindow = window.runtime.BrowserOpenURL(redirectUrlParts.toString()); + + this.waitForDesktopCodeOrTimeout(null, sourceType).subscribe(async (codeData) => { //TODO: redirect to the callback url with the code. console.log("DONE WAITING FOR CODE") }) diff --git a/frontend/src/lib/utils/external_link.ts b/frontend/src/lib/utils/external_link.ts new file mode 100644 index 00000000..f1a23198 --- /dev/null +++ b/frontend/src/lib/utils/external_link.ts @@ -0,0 +1,14 @@ +export function OpenExternalLink(url: string, desktopMode: boolean){ + //check if url starts with https, and if not, prepend it (external links are never relative) + if(!url.startsWith("https://") && !url.startsWith("http://")){ + url = "https://" + url; + } + + //check if wails exists and is defined + if(typeof wails !== "undefined" && desktopMode){ + wails.CallByName("pkg.AppService.BrowserOpenURL", url) + } else{ + window.open(url, "_blank"); + } + +}