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

Commit

Permalink
Use requestIdleCallback for migration
Browse files Browse the repository at this point in the history
This will run the migration when the browser is first idle, instead of waiting a specific amount of time
  • Loading branch information
ianb committed Jun 12, 2017
1 parent 2af0267 commit 87a28fd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions addon/webextension/background/startBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ this.startBackground = (function() {
"background/main.js"
];

// Milliseconds to wait before checking for migration possibility
// Maximum milliseconds to wait before checking for migration possibility
const CHECK_MIGRATION_DELAY = 2000;

browser.browserAction.onClicked.addListener((tab) => {
Expand Down Expand Up @@ -73,7 +73,7 @@ this.startBackground = (function() {

// We delay this check (by CHECK_MIGRATION_DELAY) just to avoid piling too
// many things onto browser/add-on startup
setTimeout(() => {
requestIdleCallback(() => {
browser.runtime.sendMessage({funcName: "getOldDeviceInfo"}).then((result) => {
if (result && result.type == "success" && result.value) {
// There is a possible migration to run, so we'll load the entire background
Expand All @@ -93,7 +93,7 @@ this.startBackground = (function() {
console.error("Screenshots error checking for Page Shot migration:", error);
}
});
}, CHECK_MIGRATION_DELAY);
}, {timeout: CHECK_MIGRATION_DELAY});

let loadedPromise;

Expand Down

0 comments on commit 87a28fd

Please # to comment.