Skip to content

Commit

Permalink
Fix race condition that can lead to a wrongly enabled globe button
Browse files Browse the repository at this point in the history
The button was wrongly enabled, but didn't react on key presses because
the geositeInfo variable was undefined. Merely the button was not
updated to represent the correct disabled state.

This fixes problem no. 1 for Flickr, for further details see the
previous commit log.
  • Loading branch information
marcows committed Jan 19, 2019
1 parent a1ffb35 commit abf8890
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ function setShowmapButtonState(enable)
*/
function updateShowmapButtonState()
{
// geourl handling
// check website address
setShowmapButtonState(!!geourl.parse(tabs.activeTab.url));

// geosite handling
// check website content
tabs.activeTab.attach({
contentScriptFile: geositeScripts,
contentScript: 'self.port.emit("geositeinfo", scanGeosite());'
Expand All @@ -264,12 +264,26 @@ function updateShowmapButtonState()
// If not having direct coordinates, try the indirect way.
if (!geositeInfo.coords && geositeInfo.url)
geositeInfo.coords = geourl.parse(geositeInfo.url);

// Only enable the state, do not disable it, this would lead to
// overwriting a state enabled by geourl.
if (geositeInfo.coords)
setShowmapButtonState(true);
}

/*
* Always enable the button on positive result, but only
* disable it on negative result if the website address check
* was negative as well (do not overwrite its valid state).
* That check is repeated here (instead of simply preventing to
* set the state to false) to avoid inconsistent states in case
* the result changed without being recognized by an event.
*
* Disabling the button has to happen here in any case because
* the previous geosite result could have been a false
* positive, but occur after the last website address check
* because of the asynchronous result message from content
* script.
*/
if ((geositeInfo && geositeInfo.coords) || geourl.parse(tabs.activeTab.url))
setShowmapButtonState(true);
else
setShowmapButtonState(false);
});
}

Expand Down

0 comments on commit abf8890

Please sign in to comment.