feat: support deep links

This commit is contained in:
Jovan Krunić
2021-11-17 14:18:27 +01:00
parent 837c69bb21
commit 2e3f6684ef
3 changed files with 28 additions and 2 deletions

View File

@@ -22,6 +22,14 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- NEXT LINE'S HOST TO BE GENERATED (SCHOOL SPECIFIC) -->
<data android:scheme="https" android:host="mobile.app.uni-frankfurt.de" />
</intent-filter>
</activity>
<provider

View File

@@ -24,6 +24,7 @@ import {AppComponent} from './app.component';
import {ConfigProvider} from './modules/config/config.provider';
import {SettingsProvider} from './modules/settings/settings.provider';
import {NGXLogger} from 'ngx-logger';
import {RouterTestingModule} from '@angular/router/testing';
describe('AppComponent', () => {
let platformReadySpy: any;
@@ -54,6 +55,7 @@ describe('AppComponent', () => {
ngxLogger = jasmine.createSpyObj('NGXLogger', ['log', 'error', 'warn']);
TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([])],
declarations: [AppComponent],
providers: [
{provide: Platform, useValue: platformSpy},

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 StApps
* Copyright (C) 2018-2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -12,7 +12,9 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Component} from '@angular/core';
import {Component, NgZone} from '@angular/core';
import {Router} from '@angular/router';
import {App, URLOpenListenerEvent} from '@capacitor/app';
import {SplashScreen} from '@capacitor/splash-screen';
import {Platform} from '@ionic/angular';
import {NGXLogger} from 'ngx-logger';
@@ -47,12 +49,16 @@ export class AppComponent {
* @param settingsProvider TODO
* @param configProvider TODO
* @param logger An angular logger
* @param router The angular router
* @param zone The angular zone
*/
constructor(
private readonly platform: Platform,
private readonly settingsProvider: SettingsProvider,
private readonly configProvider: ConfigProvider,
private readonly logger: NGXLogger,
private readonly router: Router,
private readonly zone: NgZone,
) {
void this.initializeApp();
}
@@ -61,6 +67,16 @@ export class AppComponent {
* TODO
*/
async initializeApp() {
App.addListener('appUrlOpen', (event: URLOpenListenerEvent) => {
this.zone.run(() => {
const slug = event.url.split('.de').pop();
if (slug) {
this.router.navigateByUrl(slug);
}
// If no match, do nothing - let regular routing
// logic take over
});
});
this.platform.ready().then(async () => {
await SplashScreen.hide();