From 29ed8045672cee7d2b3c167c9727f928ecb339c6 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 16 Jun 2021 11:54:26 +0200 Subject: [PATCH] MOBILE-3320 http: Fix user agent initialization --- .../initializers/initialize-user-agent.ts | 26 +++++++++++++++++++ src/core/services/ws.ts | 15 +---------- 2 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 src/core/initializers/initialize-user-agent.ts diff --git a/src/core/initializers/initialize-user-agent.ts b/src/core/initializers/initialize-user-agent.ts new file mode 100644 index 000000000..085341f36 --- /dev/null +++ b/src/core/initializers/initialize-user-agent.ts @@ -0,0 +1,26 @@ +// (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. + +import { CoreApp } from '@services/app'; +import { NativeHttp, Platform } from '@singletons'; + +export default async function(): Promise { + if (!CoreApp.isMobile()) { + return; + } + + await Platform.ready(); + + NativeHttp.setHeader('*', 'User-Agent', navigator.userAgent); +} diff --git a/src/core/services/ws.ts b/src/core/services/ws.ts index 00c71a694..92067a6e9 100644 --- a/src/core/services/ws.ts +++ b/src/core/services/ws.ts @@ -30,7 +30,7 @@ import { CoreUtils, PromiseDefer } from '@services/utils/utils'; import { CoreConstants } from '@/core/constants'; import { CoreError } from '@classes/errors/error'; import { CoreInterceptor } from '@classes/interceptor'; -import { makeSingleton, Translate, FileTransfer, Http, Platform, NativeHttp } from '@singletons'; +import { makeSingleton, Translate, FileTransfer, Http, NativeHttp } from '@singletons'; import { CoreArray } from '@singletons/array'; import { CoreLogger } from '@singletons/logger'; import { CoreWSError } from '@classes/errors/wserror'; @@ -53,19 +53,6 @@ export class CoreWSProvider { constructor() { this.logger = CoreLogger.getInstance('CoreWSProvider'); - - this.init(); - } - - /** - * Initialize some data. - */ - protected async init(): Promise { - await Platform.ready(); - - if (CoreApp.isMobile()) { - NativeHttp.setHeader('*', 'User-Agent', navigator.userAgent); - } } /**