This repository has been archived by the owner on Feb 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #453, increase timeouts and limit permission checks
This gives a bit more time before we decide a service is unable to play. It also limits the total number of warnings to 3 for each individual service.
- Loading branch information
Showing
4 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
this.limiter = (function() { | ||
const exports = {}; | ||
|
||
exports.shouldDisplayWarning = async function( | ||
warningName, | ||
{ times, frequency } | ||
) { | ||
if (!(times || frequency)) { | ||
throw new Error("Must provide times and/or frequency arguments"); | ||
} | ||
const key = `warning.${warningName}`; | ||
const info = (await browser.storage.local.get(key))[key]; | ||
if (!info) { | ||
// it's never been run before | ||
browser.storage.local.set({ [key]: { times: 1, lastTime: Date.now() } }); | ||
return true; | ||
} | ||
if (times && info.times >= times) { | ||
return false; | ||
} | ||
if (frequency && Date.now() - info.lastTime < frequency) { | ||
return false; | ||
} | ||
browser.storage.local.set({ | ||
[key]: { | ||
times: info.times + 1, | ||
lastTime: Date.now(), | ||
}, | ||
}); | ||
return true; | ||
}; | ||
|
||
return exports; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters