Skip to content

Commit d2be5b4

Browse files
committed
MOBILE-4910 mainmenu: Add open link method enum
1 parent 8c494dd commit d2be5b4

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

src/core/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ export const enum LMSBadgeStyle {
125125
INFO = 'info',
126126
}
127127

128+
export enum CoreLinkOpenMethod {
129+
APP = 'app',
130+
INAPPBROWSER = 'inappbrowser',
131+
BROWSER = 'browser',
132+
EMBEDDED = 'embedded',
133+
}
134+
128135
/**
129136
* Static class to contain all the core constants.
130137
*/

src/core/directives/external-content.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { CoreLogger } from '@singletons/logger';
3232
import { CoreError } from '@classes/errors/error';
3333
import { CoreSite } from '@classes/sites/site';
3434
import { CoreEventObserver, CoreEvents } from '@singletons/events';
35-
import { DownloadStatus } from '../constants';
35+
import { CoreLinkOpenMethod, DownloadStatus } from '../constants';
3636
import { CoreNetwork } from '@services/network';
3737
import { Translate } from '@singletons';
3838
import { AsyncDirective } from '@classes/async-directive';
@@ -370,7 +370,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
370370
const tagName = this.element.tagName;
371371
const openIn = tagName === 'A' && this.element.getAttribute('data-open-in');
372372

373-
if (openIn === 'app' || openIn === 'browser') {
373+
if (openIn === CoreLinkOpenMethod.APP || openIn === CoreLinkOpenMethod.BROWSER) {
374374
// The file is meant to be opened in browser or InAppBrowser, don't use the downloaded URL because it won't work.
375375
if (!site.isSitePluginFileUrl(url)) {
376376
return url;

src/core/directives/format-text.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { MediaElementController } from '@classes/element-controllers/MediaElemen
5353
import { FrameElement, FrameElementController } from '@classes/element-controllers/FrameElementController';
5454
import { CoreUrl } from '@singletons/url';
5555
import { CoreIcons } from '@singletons/icons';
56-
import { ContextLevel } from '../constants';
56+
import { ContextLevel, CoreLinkOpenMethod } from '../constants';
5757
import { CoreWait } from '@singletons/wait';
5858
import { toBoolean } from '../transforms/boolean';
5959
import { CoreViewer } from '@features/viewer/services/viewer';
@@ -839,7 +839,7 @@ export class CoreFormatTextDirective implements OnDestroy, AsyncDirective {
839839
// Try to convert the URL to absolute if needed.
840840
url = CoreUrl.toAbsoluteURL(site.getURL(), url);
841841
const confirmMessage = element.dataset.appUrlConfirm;
842-
const openInApp = element.dataset.openIn === 'app';
842+
const openInApp = element.dataset.openIn === CoreLinkOpenMethod.APP;
843843
const refreshOnResume = element.dataset.appUrlResumeAction === 'refresh';
844844

845845
if (confirmMessage) {

src/core/directives/link.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { CoreFileHelper } from '@services/file-helper';
1919
import { CoreSites } from '@services/sites';
2020
import { CoreUrl } from '@singletons/url';
2121
import { CoreOpener } from '@singletons/opener';
22-
import { CoreConstants } from '@/core/constants';
22+
import { CoreConstants, CoreLinkOpenMethod } from '@/core/constants';
2323
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
2424
import { CoreCustomURLSchemes } from '@services/urlschemes';
2525
import { DomSanitizer } from '@singletons';
@@ -187,8 +187,8 @@ export class CoreLinkDirective implements OnInit {
187187
protected async openExternalLink(href: string, openIn?: string | null): Promise<void> {
188188
// Priority order is: core-link inApp attribute > forceOpenLinksIn setting > data-open-in HTML attribute.
189189
const openInApp = this.inApp ??
190-
(CoreConstants.CONFIG.forceOpenLinksIn !== 'browser' &&
191-
(CoreConstants.CONFIG.forceOpenLinksIn === 'app' || openIn === 'app'));
190+
(CoreConstants.CONFIG.forceOpenLinksIn !== CoreLinkOpenMethod.BROWSER &&
191+
(CoreConstants.CONFIG.forceOpenLinksIn === CoreLinkOpenMethod.APP || openIn === CoreLinkOpenMethod.APP));
192192

193193
// Check if we need to auto-login.
194194
if (!CoreSites.isLoggedIn()) {

src/core/features/mainmenu/services/mainmenu.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
1616

1717
import { CoreLang, CoreLangFormat, CoreLangLanguage } from '@services/lang';
1818
import { CoreSites } from '@services/sites';
19-
import { CoreConstants } from '@/core/constants';
19+
import { CoreConstants, CoreLinkOpenMethod } from '@/core/constants';
2020
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from './mainmenu-delegate';
2121
import { Device, makeSingleton } from '@singletons';
2222
import { CoreText } from '@singletons/text';
@@ -113,7 +113,7 @@ export class CoreMainMenuProvider {
113113

114114
let position = 0; // Position of each item, to keep the same order as it's configured.
115115

116-
if (!itemsString || typeof itemsString != 'string') {
116+
if (!itemsString || typeof itemsString !== 'string') {
117117
// Setting not valid.
118118
return result;
119119
}
@@ -136,7 +136,9 @@ export class CoreMainMenuProvider {
136136
const id = `${url}#${type}`;
137137
if (!icon) {
138138
// Icon not defined, use default one.
139-
icon = type == 'embedded' ? 'fas-expand' : 'fas-link'; // @todo Find a better icon for embedded.
139+
icon = type == CoreLinkOpenMethod.EMBEDDED
140+
? 'fas-expand' // @todo Find a better icon for embedded.
141+
: 'fas-link';
140142
}
141143

142144
if (!map[id]) {
@@ -283,7 +285,7 @@ export class CoreMainMenuProvider {
283285
* @returns Promise resolved with boolean: whether it's the root of a main menu tab.
284286
*/
285287
async isMainMenuTab(pageName: string): Promise<boolean> {
286-
if (pageName == MAIN_MENU_MORE_PAGE_NAME) {
288+
if (pageName === MAIN_MENU_MORE_PAGE_NAME) {
287289
return true;
288290
}
289291

@@ -330,7 +332,7 @@ export interface CoreMainMenuCustomItem {
330332
/**
331333
* Type of the item: app, inappbrowser, browser or embedded.
332334
*/
333-
type: string;
335+
type: CoreLinkOpenMethod;
334336

335337
/**
336338
* Url of the item.
@@ -360,7 +362,7 @@ export type CoreMainMenuLocalizedCustomItem = Omit<CoreMainMenuCustomItem, 'labe
360362
*/
361363
type CustomMenuItemsMap = Record<string, {
362364
url: string;
363-
type: string;
365+
type: CoreLinkOpenMethod;
364366
position: number;
365367
labels: {
366368
[lang: string]: {

0 commit comments

Comments
 (0)