chore: Only export global variable for mods, not the class, b=(no-bug), c=mods

This commit is contained in:
Mr. M 2025-05-27 20:17:06 +02:00
parent 0278aea4f7
commit bd72aebd98
No known key found for this signature in database
GPG key ID: 6292C4C8F8652B18

View file

@ -2,7 +2,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
class ZenMods extends ZenPreloadedFeature { {
class ZenMods extends ZenPreloadedFeature {
// private properties start // private properties start
#kZenStylesheetModHeader = '/* Zen Mods - Generated by ZenMods.'; #kZenStylesheetModHeader = '/* Zen Mods - Generated by ZenMods.';
#kZenStylesheetModHeaderBody = `* DO NOT EDIT THIS FILE DIRECTLY! #kZenStylesheetModHeaderBody = `* DO NOT EDIT THIS FILE DIRECTLY!
@ -201,7 +202,9 @@ class ZenMods extends ZenPreloadedFeature {
for (const { property } of preferences.filter(({ type }) => type !== 'checkbox')) { for (const { property } of preferences.filter(({ type }) => type !== 'checkbox')) {
const sanitizedProperty = property?.replaceAll(/\./g, '-'); const sanitizedProperty = property?.replaceAll(/\./g, '-');
browser.document.querySelector(':root').style.removeProperty(`--${sanitizedProperty}`); browser.document
.querySelector(':root')
.style.removeProperty(`--${sanitizedProperty}`);
} }
continue; continue;
@ -512,7 +515,11 @@ class ZenMods extends ZenPreloadedFeature {
} }
Services.prefs.addObserver(this.updatePref, this.#rebuildModsStylesheet.bind(this), false); Services.prefs.addObserver(this.updatePref, this.#rebuildModsStylesheet.bind(this), false);
Services.prefs.addObserver('zen.themes.disable-all', this.#handleDisableMods.bind(this), false); Services.prefs.addObserver(
'zen.themes.disable-all',
this.#handleDisableMods.bind(this),
false
);
} }
#setNewMilestoneIfNeeded() { #setNewMilestoneIfNeeded() {
@ -549,7 +556,10 @@ class ZenMods extends ZenPreloadedFeature {
} }
if ( if (
!this.#compareVersions(possibleNewModVersion.version, currentMod.version ?? '0.0.0') && !this.#compareVersions(
possibleNewModVersion.version,
currentMod.version ?? '0.0.0'
) &&
possibleNewModVersion.version != currentMod.version possibleNewModVersion.version != currentMod.version
) { ) {
console.log( console.log(
@ -643,7 +653,10 @@ class ZenMods extends ZenPreloadedFeature {
await this.#downloadUrlToFile(mod.readme, PathUtils.join(modPath, 'readme.md')); await this.#downloadUrlToFile(mod.readme, PathUtils.join(modPath, 'readme.md'));
if (mod.preferences) { if (mod.preferences) {
await this.#downloadUrlToFile(mod.preferences, PathUtils.join(modPath, 'preferences.json')); await this.#downloadUrlToFile(
mod.preferences,
PathUtils.join(modPath, 'preferences.json')
);
} }
} catch (e) { } catch (e) {
console.error('[ZenMods]: Error installing mod', mod.id, e); console.error('[ZenMods]: Error installing mod', mod.id, e);
@ -696,16 +709,15 @@ class ZenMods extends ZenPreloadedFeature {
async isModInstalled(modId) { async isModInstalled(modId) {
const mods = await this.getMods(); const mods = await this.getMods();
return Boolean(mods?.[modId]); return Boolean(mods?.[modId]);
} }
// public properties end // public properties end
} }
window.gZenMods = new ZenMods(); window.gZenMods = new ZenMods();
gZenActorsManager.addJSWindowActor('ZenModsMarketplace', { gZenActorsManager.addJSWindowActor('ZenModsMarketplace', {
parent: { parent: {
esModuleURI: 'resource:///actors/ZenModsMarketplaceParent.sys.mjs', esModuleURI: 'resource:///actors/ZenModsMarketplaceParent.sys.mjs',
}, },
@ -719,4 +731,5 @@ gZenActorsManager.addJSWindowActor('ZenModsMarketplace', {
...Services.prefs.getStringPref('zen.injections.match-urls').split(','), ...Services.prefs.getStringPref('zen.injections.match-urls').split(','),
'about:preferences', 'about:preferences',
], ],
}); });
}