Skip to content

Commit

Permalink
Getting google version
Browse files Browse the repository at this point in the history
  • Loading branch information
rugoncalves committed Oct 7, 2024
1 parent 06ee030 commit 3111d1c
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/Providers/Maps/Google/Version/Version.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
// 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.
*
* @export
* @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;
}

/**
Expand All @@ -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);

Expand Down

0 comments on commit 3111d1c

Please sign in to comment.