Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Fixes for asynchronous writing of useragents.xml in UserAgentSwitcher…
Browse files Browse the repository at this point in the history
…Importer.reset()
  • Loading branch information
keithbowes committed Sep 2, 2017
1 parent 44992e2 commit ac83801
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions chrome/content/useragentswitcher/useragentswitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ var UserAgentSwitcher =
{
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);

UserAgentSwitcherImporter.installUserAgents();
UserAgentSwitcherImporter.import(UserAgentSwitcherImporter.importTypeMenu, UserAgentSwitcherImporter.getUserAgentFileLocation(), true);
if (!UserAgentSwitcherImporter.installUserAgents())
UserAgentSwitcherImporter.import(UserAgentSwitcherImporter.importTypeMenu, UserAgentSwitcherImporter.getUserAgentFileLocation(), true);

// If the observer service is set
if(observerService)
Expand Down
36 changes: 20 additions & 16 deletions chrome/content/useragentswitcher/xml/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,22 +434,25 @@ var UserAgentSwitcherImporter =
}
},

// Installs the user agents
installUserAgents: function()
{
// If the user agent directory does not exist
if(!this.getUserAgentDirectoryLocation().exists())
{
this.createUserAgentDirectory();
}

// If the user agent file does not exist
if(!this.getUserAgentFileLocation().exists())
{
this.createUserAgentFile();
this.reset();
}
},
// Installs the user agents
installUserAgents: function()
{
// If the user agent directory does not exist
if(!this.getUserAgentDirectoryLocation().exists())
{
this.createUserAgentDirectory();
}

// If the user agent file does not exist
if(!this.getUserAgentFileLocation().exists())
{
this.createUserAgentFile();
this.reset();
return true;
}

return false;
},

// Populates a user agent
populateUserAgent: function(userAgent, userAgentElement)
Expand Down Expand Up @@ -575,6 +578,7 @@ var UserAgentSwitcherImporter =
var outputStream = FileUtils.openFileOutputStream(userAgentFile, FileUtils.RDWR | FileUtils.MODE_TRUNCATE | FileUtils.PERMS_FILE);
outputStream.write(request.responseText, request.responseText.length);
outputStream.close();
UserAgentSwitcherImporter.import(UserAgentSwitcherImporter.importTypeMenu, UserAgentSwitcherImporter.getUserAgentFileLocation(), true);
}

request.send();
Expand Down

0 comments on commit ac83801

Please sign in to comment.