moving open external link functionality into shared lib.

This commit is contained in:
Jason Kulatunga 2023-09-06 22:30:42 -07:00
parent 6691837797
commit 206d9479fc
3 changed files with 22 additions and 15 deletions

View File

@ -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 = (<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;
OpenExternalLink(url, environment.environment_desktop)
}
//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");
}
}
}

View File

@ -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")
})

View File

@ -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");
}
}