Skip to content

Commit

Permalink
moving open external link functionality into shared lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Sep 7, 2023
1 parent 6691837 commit 206d947
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
16 changes: 3 additions & 13 deletions frontend/src/app/directives/external-link.directive.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,19 +38,8 @@ export class ExternalLinkDirective {
onClick(event: MouseEvent) {
event.preventDefault();

let url: string = (<any>event.currentTarget).getAttribute("href") || (<any>event.target).getAttribute("href");
let url: string = (<any> event.currentTarget).getAttribute("href") || (<any> 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)
}

}
7 changes: 5 additions & 2 deletions frontend/src/app/services/lighthouse.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
})
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/lib/utils/external_link.ts
Original file line number Diff line number Diff line change
@@ -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");
}

}

0 comments on commit 206d947

Please sign in to comment.