mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACA-4715] reduce env variables and provide defaults (#3311)
* use default "sessionTimeForOpenAppDialogDisplay" * improve iPhone prefix url api * improve android prefix url api * session timeout * app store url defaults * enable mobile redirect by default * enable AOS by default * enable content plugins by default * enable folder rules by default * remove obsolete AI flag * remove obsolete APA flag * auto download defaults * cleanup auth vars
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# Open in Mobile Application
|
||||
|
||||
Configuring via `app.config.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"mobileAppSwitch": {
|
||||
"enabled": true,
|
||||
"iphoneUrl": "iosamw://",
|
||||
"androidUrlPart1": "intent:///",
|
||||
"androidUrlPart2": "#Intent;scheme=androidamw;package=com.alfresco.content.app;end",
|
||||
"sessionTimeout": 12,
|
||||
"appStoreUrl": "https://apps.apple.com/us/app/alfresco-mobile-workspace/id1514434480"
|
||||
}
|
||||
}
|
||||
```
|
@@ -45,11 +45,7 @@ describe('AcaMobileAppSwitcherService', () => {
|
||||
});
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
appConfig.config.mobileAppSwitch = {
|
||||
enabled: true,
|
||||
iphoneUrl: 'iosamw://',
|
||||
androidUrlPart1: 'intent:///',
|
||||
androidUrlPart2: '#Intent;scheme=androidamw;package=com.alfresco.content.app;end',
|
||||
sessionTimeForOpenAppDialogDisplay: 12
|
||||
enabled: true
|
||||
};
|
||||
service = TestBed.inject(AcaMobileAppSwitcherService);
|
||||
sessionStorage.clear();
|
||||
@@ -58,15 +54,14 @@ describe('AcaMobileAppSwitcherService', () => {
|
||||
it('should set the redirectUrl to `iphoneUrl`', () => {
|
||||
spyOnProperty(window.navigator, 'userAgent').and.returnValue('iphone');
|
||||
const url: string = window.location.href;
|
||||
const iphoneUrl: string = appConfig.config.mobileAppSwitch.iphoneUrl + url;
|
||||
const iphoneUrl = service.getIPhoneRedirectUrl(url);
|
||||
service.identifyBrowserAndSetRedirectURL();
|
||||
expect(service.redirectUrl).toEqual(iphoneUrl);
|
||||
});
|
||||
|
||||
it('should set the redirectUrl to `androidUrl`', () => {
|
||||
spyOnProperty(window.navigator, 'userAgent').and.returnValue('android');
|
||||
const url: string = window.location.href;
|
||||
const androidUrl: string = appConfig.config.mobileAppSwitch.androidUrlPart1 + url + appConfig.config.mobileAppSwitch.androidUrlPart2;
|
||||
const androidUrl = service.getAndroidRedirectUrl(window.location.href);
|
||||
service.identifyBrowserAndSetRedirectURL();
|
||||
expect(service.redirectUrl).toEqual(androidUrl);
|
||||
});
|
||||
@@ -86,15 +81,13 @@ describe('AcaMobileAppSwitcherService', () => {
|
||||
});
|
||||
|
||||
it('should check if `openInApp` dialog box is getting opened with `iphone` url', () => {
|
||||
const url: string = window.location.href;
|
||||
service.redirectUrl = appConfig.config.mobileAppSwitch.iphoneUrl + url;
|
||||
service.redirectUrl = service.getIPhoneRedirectUrl(window.location.href);
|
||||
service.identifyBrowserAndSetRedirectURL();
|
||||
expect(mockDialogRef.open).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should check if `openInApp` dialog box is getting opened with `android` url', () => {
|
||||
const url: string = window.location.href;
|
||||
service.redirectUrl = appConfig.config.mobileAppSwitch.androidUrlPart1 + url + appConfig.config.mobileAppSwitch.androidUrlPart2;
|
||||
service.redirectUrl = service.getAndroidRedirectUrl(window.location.href);
|
||||
service.identifyBrowserAndSetRedirectURL();
|
||||
expect(mockDialogRef.open).toHaveBeenCalled();
|
||||
});
|
||||
|
@@ -23,29 +23,37 @@
|
||||
*/
|
||||
|
||||
import { AppConfigService } from '@alfresco/adf-core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
|
||||
import { OpenInAppComponent } from '../components/open-in-app/open-in-app.component';
|
||||
|
||||
export interface MobileAppSwitchConfigurationOptions {
|
||||
enabled: string;
|
||||
iphoneUrl: string;
|
||||
androidUrlPart1: string;
|
||||
androidUrlPart2: string;
|
||||
sessionTimeForOpenAppDialogDisplay: string;
|
||||
appStoreUrl: string;
|
||||
}
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AcaMobileAppSwitcherService {
|
||||
private mobileAppSwitchConfig: MobileAppSwitchConfigurationOptions;
|
||||
public redirectUrl: string;
|
||||
public appStoreUrl: string;
|
||||
private dialogRef: MatDialogRef<OpenInAppComponent>;
|
||||
private config = inject(AppConfigService);
|
||||
private dialog = inject(MatDialog);
|
||||
|
||||
constructor(private config: AppConfigService, private dialog: MatDialog) {
|
||||
this.mobileAppSwitchConfig = this.config.get<MobileAppSwitchConfigurationOptions>('mobileAppSwitch');
|
||||
get appStoreUrl(): string {
|
||||
const defaultValue = 'https://apps.apple.com/us/app/alfresco-mobile-workspace/id1514434480';
|
||||
return this.config.get<string>('mobileAppSwitch.appStoreUrl', defaultValue);
|
||||
}
|
||||
|
||||
get sessionTimeout(): number {
|
||||
return this.config.get<number>('mobileAppSwitch.sessionTimeout', 12);
|
||||
}
|
||||
|
||||
getIPhoneRedirectUrl(url: string): string {
|
||||
const prefix = this.config.get<string>('mobileAppSwitch.iphoneUrl', 'iosamw://');
|
||||
return prefix + url;
|
||||
}
|
||||
|
||||
getAndroidRedirectUrl(url: string): string {
|
||||
const prefix = this.config.get<string>('mobileAppSwitch.androidUrlPart1', 'intent:///');
|
||||
const suffix = this.config.get<string>('mobileAppSwitch.androidUrlPart2', '#Intent;scheme=androidamw;package=com.alfresco.content.app;end');
|
||||
return prefix + url + suffix;
|
||||
}
|
||||
|
||||
resolveExistenceOfDialog(): void {
|
||||
@@ -68,9 +76,8 @@ export class AcaMobileAppSwitcherService {
|
||||
const currentTime: number = new Date().getTime();
|
||||
const sessionConvertedTime: number = parseFloat(sessionTime);
|
||||
const timeDifference: number = (currentTime - sessionConvertedTime) / (1000 * 60 * 60);
|
||||
const sessionTimeForOpenAppDialogDisplay: number = parseFloat(this.mobileAppSwitchConfig.sessionTimeForOpenAppDialogDisplay);
|
||||
|
||||
if (timeDifference > sessionTimeForOpenAppDialogDisplay) {
|
||||
if (timeDifference > this.sessionTimeout) {
|
||||
this.clearSessionExpireTime();
|
||||
this.identifyBrowserAndSetRedirectURL();
|
||||
}
|
||||
@@ -87,10 +94,9 @@ export class AcaMobileAppSwitcherService {
|
||||
const currentUrl: string = this.getCurrentUrl();
|
||||
|
||||
if (isIOS === true) {
|
||||
this.redirectUrl = this.mobileAppSwitchConfig.iphoneUrl + currentUrl;
|
||||
this.appStoreUrl = this.mobileAppSwitchConfig.appStoreUrl;
|
||||
this.redirectUrl = this.getIPhoneRedirectUrl(currentUrl);
|
||||
} else if (isAndroid === true) {
|
||||
this.redirectUrl = this.mobileAppSwitchConfig.androidUrlPart1 + currentUrl + this.mobileAppSwitchConfig.androidUrlPart2;
|
||||
this.redirectUrl = this.getAndroidRedirectUrl(currentUrl);
|
||||
}
|
||||
|
||||
if (this.redirectUrl !== undefined && this.redirectUrl !== null) {
|
||||
|
Reference in New Issue
Block a user