Skip to content

Commit

Permalink
Improve deep linking logic and add .well-known files as assets (#2131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssylver93 authored Nov 6, 2024
1 parent 2b8ca30 commit cb943b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
2 changes: 2 additions & 0 deletions client/wfnews-war/src/main/angular/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"src/refresh-token.html",
"src/robots.txt",
"src/wfnews-service-worker.js",
"src/.well-known/apple-app-site-association",
"src/.well-known/assetlinks.json",
{
"glob": "**/*",
"input": "src/assets",
Expand Down
42 changes: 27 additions & 15 deletions client/wfnews-war/src/main/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ export class AppComponent implements OnDestroy, OnInit, AfterViewInit {
}

this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(() => {
this.setDefaultMetaTags();
});
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(() => {
this.setDefaultMetaTags();
});
}

setDefaultMetaTags(){
setDefaultMetaTags() {
const imageUrl = this.appConfigService.getConfig().application.baseUrl.toString() + 'assets/images/share-wildfire.png';
this.titleService.setTitle('BC Wildfire Service');

Expand All @@ -294,17 +294,29 @@ export class AppComponent implements OnDestroy, OnInit, AfterViewInit {
initializeDeepLinks() {
// add listener to enable Capacitor deep links functionality
App.addListener('appUrlOpen', (event: URLOpenListenerEvent) => {
console.log('appUrlOpen: initializing: ', JSON.stringify(event));
this.zone.run(() => {
// remove https:// and http:// from baseUrl
const domain = this.appConfigService.getConfig().application.baseUrl.replace(/^https?:\/\//i, '');

// The pathArray is now like ['wildfiresituation.nrs.gov.bc.ca', '/map?longitude=-124.62025&latitude=53.231&activeWildfires=true']
const pathArray = event.url.split(domain);

// Get the last element with pop()
const appPath = pathArray.pop();
if (appPath) {
this.router.navigateByUrl(appPath);
try {
// remove https:// and http:// from baseUrl
const domain = this.appConfigService.getConfig().application.baseUrl.replace(/^https?:\/\//i, '');

// reject if event URL is invalid
if (!event.url.includes(domain) && !domain.includes('localhost')) {
console.log('appUrlOpen: returning from initializeDeepLinks function');
return;
}

// form path from URL's path + query parameters
const url = new URL(event.url);
const path = url.pathname + url.search;

// navigate to deep link
if (path) {
console.log('appUrlOpen appPath: ', path);
this.router.navigateByUrl(path);
}
} catch (error) {
console.error('appUrlOpen: error initializing deep links', error);
}
});
});
Expand Down

0 comments on commit cb943b7

Please sign in to comment.