зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1772007 - Part 3: Use plain object for lazy getter in browser/themes/. r=desktop-theme-reviewers,dao
Differential Revision: https://phabricator.services.mozilla.com/D148009
This commit is contained in:
Родитель
abf807a67a
Коммит
4fc80cb4ac
|
@ -9,7 +9,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
AddonManager: "resource://gre/modules/AddonManager.jsm",
|
||||
BuiltInThemeConfig: "resource:///modules/BuiltInThemeConfig.jsm",
|
||||
});
|
||||
|
@ -18,7 +20,7 @@ const kActiveThemePref = "extensions.activeThemeID";
|
|||
const kRetainedThemesPref = "browser.theme.retainedExpiredThemes";
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
lazy,
|
||||
"retainedThemes",
|
||||
kRetainedThemesPref,
|
||||
null,
|
||||
|
@ -45,7 +47,7 @@ class _BuiltInThemes {
|
|||
* The list of themes to be installed. This is exposed on the class so tests
|
||||
* can set custom config files.
|
||||
*/
|
||||
builtInThemeMap = BuiltInThemeConfig;
|
||||
builtInThemeMap = lazy.BuiltInThemeConfig;
|
||||
|
||||
/**
|
||||
* @param {string} id An addon's id string.
|
||||
|
@ -83,7 +85,7 @@ class _BuiltInThemes {
|
|||
let activeBuiltInTheme = this.builtInThemeMap.get(activeThemeID);
|
||||
|
||||
if (activeBuiltInTheme) {
|
||||
AddonManager.maybeInstallBuiltinAddon(
|
||||
lazy.AddonManager.maybeInstallBuiltinAddon(
|
||||
activeThemeID,
|
||||
activeBuiltInTheme.version,
|
||||
`resource://builtin-themes/${activeBuiltInTheme.path}`
|
||||
|
@ -105,11 +107,11 @@ class _BuiltInThemes {
|
|||
for (let [id, themeInfo] of this.builtInThemeMap.entries()) {
|
||||
if (
|
||||
!themeInfo.expiry ||
|
||||
retainedThemes.includes(id) ||
|
||||
lazy.retainedThemes.includes(id) ||
|
||||
new Date(themeInfo.expiry) > now
|
||||
) {
|
||||
installPromises.push(
|
||||
AddonManager.maybeInstallBuiltinAddon(
|
||||
lazy.AddonManager.maybeInstallBuiltinAddon(
|
||||
id,
|
||||
themeInfo.version,
|
||||
themeInfo.path
|
||||
|
@ -150,7 +152,7 @@ class _BuiltInThemes {
|
|||
* the user has the ability to use it after its expiry date.
|
||||
*/
|
||||
isRetainedExpiredTheme(id) {
|
||||
return retainedThemes.includes(id) && this.themeIsExpired(id);
|
||||
return lazy.retainedThemes.includes(id) && this.themeIsExpired(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,7 +169,7 @@ class _BuiltInThemes {
|
|||
const expiredThemes = Array.from(this.builtInThemeMap.entries()).filter(
|
||||
([id, themeInfo]) =>
|
||||
!!themeInfo.expiry &&
|
||||
!retainedThemes.includes(id) &&
|
||||
!lazy.retainedThemes.includes(id) &&
|
||||
new Date(themeInfo.expiry) <= now
|
||||
);
|
||||
for (let [id] of expiredThemes) {
|
||||
|
@ -175,7 +177,7 @@ class _BuiltInThemes {
|
|||
this._retainLimitedTimeTheme(id);
|
||||
} else {
|
||||
try {
|
||||
let addon = await AddonManager.getAddonByID(id);
|
||||
let addon = await lazy.AddonManager.getAddonByID(id);
|
||||
if (addon) {
|
||||
await addon.uninstall();
|
||||
}
|
||||
|
@ -193,11 +195,11 @@ class _BuiltInThemes {
|
|||
* The ID of the theme to retain.
|
||||
*/
|
||||
_retainLimitedTimeTheme(id) {
|
||||
if (!retainedThemes.includes(id)) {
|
||||
retainedThemes.push(id);
|
||||
if (!lazy.retainedThemes.includes(id)) {
|
||||
lazy.retainedThemes.push(id);
|
||||
Services.prefs.setStringPref(
|
||||
kRetainedThemesPref,
|
||||
JSON.stringify(retainedThemes)
|
||||
JSON.stringify(lazy.retainedThemes)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче