From 3111d1c7b2ac4fbc8e66b2fe9cba2335183e34c9 Mon Sep 17 00:00:00 2001 From: rug Date: Mon, 7 Oct 2024 17:38:47 +0200 Subject: [PATCH] Getting google version --- src/Providers/Maps/Google/Version/Version.ts | 30 ++++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Providers/Maps/Google/Version/Version.ts b/src/Providers/Maps/Google/Version/Version.ts index b059e22..78b4385 100644 --- a/src/Providers/Maps/Google/Version/Version.ts +++ b/src/Providers/Maps/Google/Version/Version.ts @@ -1,5 +1,20 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars namespace Provider.Maps.Google.Version { + /** + * Auxiliary function to get the current version of Google Maps loaded on the page. + * + * @return {*} {string} + */ + function GetGoogleMapsVersion(): string { + let version = undefined; + if (window.google && window.google.maps && window.google.maps.version) { + const gmVersion = window.google.maps.version; + const indexMajorMinor = gmVersion.lastIndexOf('.'); + version = gmVersion.substring(0, indexMajorMinor); + } + return version; + } + /** * Get the current version of Google Maps loaded on the page. * @@ -7,19 +22,20 @@ namespace Provider.Maps.Google.Version { * @return {*} {string} */ export function Get(): string { - let currVersion = + let currentVersion = OSFramework.Maps.Helper.LocalStorage.GetItem(Constants.googleMapsLocalStorageVersionKey) || Provider.Maps.Google.Constants.googleMapsVersion; + const googleVersion = GetGoogleMapsVersion(); // If the version that the developer set is still not being used, log a warning message and return the current loaded version. - if (currVersion !== google?.maps?.version) { + if (googleVersion !== undefined && currentVersion !== googleVersion) { OSFramework.Maps.Helper.LogWarningMessage( - `Current version of Google Maps loaded is '${google.maps.version}', but on the next page refresh the version will be '${currVersion}'.` + `Current version of Google Maps loaded is '${googleVersion}', but on the next page refresh the version will be '${currentVersion}'.` ); - currVersion = google.maps.version; + currentVersion = googleVersion; } - return currVersion; + return currentVersion; } /** @@ -34,8 +50,10 @@ namespace Provider.Maps.Google.Version { OSFramework.Maps.Helper.LocalStorage.GetItem(Constants.googleMapsLocalStorageVersionKey) || Constants.googleMapsVersion; + const googleVersion = GetGoogleMapsVersion(); + // If the version that the developer set is different from the current version, and is different from the version loaded, set the return value to true. - const versionChanged = currentVersion !== newVersion && newVersion !== google?.maps?.version; + const versionChanged = currentVersion !== newVersion && newVersion !== googleVersion; OSFramework.Maps.Helper.LocalStorage.SetItem(Constants.googleMapsLocalStorageVersionKey, newVersion);