diff --git a/src/core/services/config.ts b/src/core/services/config.ts index a76ec716b..012e7c7bd 100644 --- a/src/core/services/config.ts +++ b/src/core/services/config.ts @@ -23,7 +23,7 @@ import { CoreEvents } from '@singletons/events'; import { CoreDatabaseTable } from '@classes/database/database-table'; import { asyncInstance } from '../utils/async-instance'; import { CorePromisedValue } from '@classes/promised-value'; -import { CoreUtils } from './utils/utils'; +import { CoreBrowser } from '@singletons/browser'; declare module '@singletons/events' { @@ -195,11 +195,11 @@ export class CoreConfigProvider { * Load development config overrides. */ protected loadDevelopmentConfig(): void { - if (!CoreConstants.enableDevTools() || !CoreUtils.hasCookie('MoodleAppConfig')) { + if (!CoreConstants.enableDevTools() || !CoreBrowser.hasCookie('MoodleAppConfig')) { return; } - this.patchEnvironment(JSON.parse(CoreUtils.getCookie('MoodleAppConfig') ?? '{}')); + this.patchEnvironment(JSON.parse(CoreBrowser.getCookie('MoodleAppConfig') ?? '{}')); } /** diff --git a/src/core/services/db.ts b/src/core/services/db.ts index de01fd469..26721e2a7 100644 --- a/src/core/services/db.ts +++ b/src/core/services/db.ts @@ -16,9 +16,9 @@ import { Injectable } from '@angular/core'; import { SQLiteDB } from '@classes/sqlitedb'; import { SQLiteDBMock } from '@features/emulator/classes/sqlitedb'; +import { CoreBrowser } from '@singletons/browser'; import { makeSingleton, SQLite, Platform } from '@singletons'; import { CoreAppProvider } from './app'; -import { CoreUtils } from './utils/utils'; /** * This service allows interacting with the local database to store and retrieve data. @@ -36,7 +36,7 @@ export class CoreDbProvider { * @returns Whether queries should be logged. */ loggingEnabled(): boolean { - return CoreUtils.hasCookie('MoodleAppDBLoggingEnabled') || CoreAppProvider.isAutomated(); + return CoreBrowser.hasCookie('MoodleAppDBLoggingEnabled') || CoreAppProvider.isAutomated(); } /** diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index 08150ed3f..ef080cc23 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -1765,34 +1765,6 @@ export class CoreUtilsProvider { return CoreApp.isIOS() && openFileAction == OpenFileAction.OPEN_WITH; } - /** - * Check whether the given cookie is set. - * - * @param name Cookie name. - * @returns Whether the cookie is set. - */ - hasCookie(name: string): boolean { - return new RegExp(`(\\s|;|^)${name}=`).test(document.cookie ?? ''); - } - - /** - * Read a cookie. - * - * @param name Cookie name. - * @return Cookie value. - */ - getCookie(name: string): string | null { - const cookies = (document.cookie ?? '').split(';').reduce((cookies, cookie) => { - const [name, value] = cookie.trim().split('='); - - cookies[name] = value; - - return cookies; - }, {}); - - return cookies[name] ?? null; - } - } export const CoreUtils = makeSingleton(CoreUtilsProvider); diff --git a/src/core/singletons/browser.ts b/src/core/singletons/browser.ts new file mode 100644 index 000000000..9ba90176b --- /dev/null +++ b/src/core/singletons/browser.ts @@ -0,0 +1,48 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * Helpers to interact with Browser APIs. + */ +export class CoreBrowser { + + /** + * Check whether the given cookie is set. + * + * @param name Cookie name. + * @returns Whether the cookie is set. + */ + static hasCookie(name: string): boolean { + return new RegExp(`(\\s|;|^)${name}=`).test(document.cookie ?? ''); + } + + /** + * Read a cookie. + * + * @param name Cookie name. + * @return Cookie value. + */ + static getCookie(name: string): string | null { + const cookies = (document.cookie ?? '').split(';').reduce((cookies, cookie) => { + const [name, value] = cookie.trim().split('='); + + cookies[name] = value; + + return cookies; + }, {}); + + return cookies[name] ?? null; + } + +} diff --git a/src/core/singletons/logger.ts b/src/core/singletons/logger.ts index be7209703..27c61fe23 100644 --- a/src/core/singletons/logger.ts +++ b/src/core/singletons/logger.ts @@ -17,6 +17,7 @@ import moment from 'moment'; import { CoreConstants } from '@/core/constants'; import { CoreTime } from './time'; +import { CoreBrowser } from '@singletons/browser'; /** * Method to warn that logs are disabled, called only once. @@ -67,7 +68,10 @@ export class CoreLogger { */ static getInstance(className: string): CoreLogger { // Disable log on production and testing. - if (CoreConstants.BUILD.isProduction || CoreConstants.BUILD.isTesting) { + if ( + !CoreBrowser.hasCookie('MoodleAppLoggingEnabled') && + (CoreConstants.BUILD.isProduction || CoreConstants.BUILD.isTesting) + ) { if (CoreConstants.BUILD.isProduction) { warnLogsDisabled(); }