From 4b950ac891c47bab849a324f82a3114348118c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 19 Jul 2024 16:21:12 +0200 Subject: [PATCH] MOBILE-4616 chore: Remove some usages of old Service.instance --- .../features/course/services/course-helper.ts | 3 +- .../settings/pages/deviceinfo/deviceinfo.ts | 64 ++++++++----------- .../settings/services/settings-helper.ts | 7 +- src/core/singletons/window.ts | 2 +- 4 files changed, 32 insertions(+), 44 deletions(-) diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 109ab4dbd..ae96fadb4 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -645,9 +645,8 @@ export class CoreCourseHelperProvider { // Now determine the status of the whole list. let status = statuses[0]; - const filepool = CoreFilepool.instance; for (let i = 1; i < statuses.length; i++) { - status = filepool.determinePackagesStatus(status, statuses[i]); + status = CoreFilepool.determinePackagesStatus(status, statuses[i]); } return status; diff --git a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts index 38b5a45ea..fac179b89 100644 --- a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts +++ b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts @@ -86,9 +86,6 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { protected onlineObserver?: Subscription; constructor() { - const sitesProvider = CoreSites.instance; - const device = Device.instance; - const translate = Translate.instance; const navigator = window.navigator; this.deviceInfo = { @@ -128,7 +125,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { this.deviceOsTranslated = matches[1]; } else { this.deviceInfo.deviceOs = 'unknown'; - this.deviceOsTranslated = translate.instant('core.unknown'); + this.deviceOsTranslated = Translate.instant('core.unknown'); } } } else { @@ -139,39 +136,35 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { this.deviceOsTranslated = matches[1]; } else { this.deviceInfo.deviceOs = 'unknown'; - this.deviceOsTranslated = translate.instant('core.unknown'); + this.deviceOsTranslated = Translate.instant('core.unknown'); } } - if (navigator) { - if (navigator.userAgent) { - this.deviceInfo.userAgent = navigator.userAgent; - } - - if (navigator.language) { - this.deviceInfo.browserLanguage = navigator.language; - } + if (navigator.userAgent) { + this.deviceInfo.userAgent = navigator.userAgent; } - if (device) { - if (device.cordova) { - this.deviceInfo.cordovaVersion = device.cordova; - } - if (device.platform) { - this.deviceInfo.platform = device.platform; - } - if (device.version) { - this.deviceInfo.osVersion = device.version; - } - if (device.model) { - this.deviceInfo.model = device.model; - } - if (device.uuid) { - this.deviceInfo.uuid = device.uuid; - } + if (navigator.language) { + this.deviceInfo.browserLanguage = navigator.language; } - const currentSite = sitesProvider.getCurrentSite(); + if (Device.cordova) { + this.deviceInfo.cordovaVersion = Device.cordova; + } + if (Device.platform) { + this.deviceInfo.platform = Device.platform; + } + if (Device.version) { + this.deviceInfo.osVersion = Device.version; + } + if (Device.model) { + this.deviceInfo.model = Device.model; + } + if (Device.uuid) { + this.deviceInfo.uuid = Device.uuid; + } + + const currentSite = CoreSites.getCurrentSite(); this.deviceInfo.siteId = currentSite?.getId(); this.deviceInfo.siteVersion = currentSite?.getInfo()?.release; @@ -190,14 +183,11 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { * Async part of the constructor. */ protected async asyncInit(): Promise { - const sitesProvider = CoreSites.instance; - const fileProvider = CoreFile.instance; - const lang = await CoreLang.getCurrentLanguage(); this.deviceInfo.currentLanguage = lang; this.currentLangName = CoreConstants.CONFIG.languages[lang]; - const currentSite = sitesProvider.getCurrentSite(); + const currentSite = CoreSites.getCurrentSite(); const isSingleFixedSite = await CoreLoginHelper.isSingleFixedSite(); const sites = await CoreLoginHelper.getAvailableSites(); const firstUrl = isSingleFixedSite && sites[0].url; @@ -207,10 +197,10 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { this.displaySiteUrl = !!this.deviceInfo.siteUrl && (currentSite ?? CoreSitesFactory.makeUnauthenticatedSite(this.deviceInfo.siteUrl)).shouldDisplayInformativeLinks(); - if (fileProvider.isAvailable()) { - const basepath = await fileProvider.getBasePath(); + if (CoreFile.isAvailable()) { + const basepath = await CoreFile.getBasePath(); this.deviceInfo.fileSystemRoot = basepath; - this.fsClickable = fileProvider.usesHTMLAPI(); + this.fsClickable = CoreFile.usesHTMLAPI(); } const showDevOptionsOnConfig = await CoreConfig.get('showDevOptions', 0); diff --git a/src/core/features/settings/services/settings-helper.ts b/src/core/features/settings/services/settings-helper.ts index 47444868b..25bc2400a 100644 --- a/src/core/features/settings/services/settings-helper.ts +++ b/src/core/features/settings/services/settings-helper.ts @@ -136,11 +136,10 @@ export class CoreSettingsHelperProvider { // Clear cache tables. const cleanSchemas = CoreSites.getSiteTableSchemasToClear(site); const promises: Promise[] = cleanSchemas.map((name) => site.getDb().deleteRecords(name)); - const filepoolService = CoreFilepool.instance; promises.push(site.deleteFolder().then(() => { - filepoolService.clearAllPackagesStatus(siteId); - filepoolService.clearFilepool(siteId); + CoreFilepool.clearAllPackagesStatus(siteId); + CoreFilepool.clearFilepool(siteId); CoreCourse.clearAllCoursesStatus(siteId); siteInfo.spaceUsage = 0; @@ -149,7 +148,7 @@ export class CoreSettingsHelperProvider { }).catch(async (error) => { if (error && error.code === FileError.NOT_FOUND_ERR) { // Not found, set size 0. - filepoolService.clearAllPackagesStatus(siteId); + CoreFilepool.clearAllPackagesStatus(siteId); siteInfo.spaceUsage = 0; } else { // Error, recalculate the site usage. diff --git a/src/core/singletons/window.ts b/src/core/singletons/window.ts index c520b9741..c14b8de93 100644 --- a/src/core/singletons/window.ts +++ b/src/core/singletons/window.ts @@ -82,7 +82,7 @@ export class CoreWindow { if (!CoreFileHelper.isOpenableInApp({ filename })) { try { await CoreFileHelper.showConfirmOpenUnsupportedFile(false, { filename }); - } catch (error) { + } catch { return; // Cancelled, stop. } }