I need to know ID of current active Firefox Persona in order to get the textcolor value from users.pref to be able to display different icons on my widget, because I don’t wont to display blue icon on blue background.
This tutorial shows:
-
How to access Addon Manager from a JetPack script
-
How to get all Addons based on their type [extension, theme, locale, multipackage]
-
How to get Active Persona’s ID
It’s a lot for such short script, isn’t it?
//we need this component
const {Cu} = require("chrome");
//import AddonManager
var AddonManager = Cu.import("resource://gre/modules/AddonManager.jsm")
.AddonManager;
//We need to get all Addons that are with type 'theme'
var types =['theme'];
//get all themes
var currentTheme = AddonManager
.getAddonsByTypes(types,function(addons){
//Firefox always shows active theme as 0 element (not sure, need confirmation)
//get the ID of the active theme/persona
var tid=addons[0].id.toString();
//show it in console
console.log("Current Id:"+ tid);
});
Unfortunatelly textcolor value is not part of the object (yet) and the only way to find it is to check with this id (tid) in prefs.js
Thanks Michael. For jetPack it should be:
Actually, you want textcolor, so .textcolor.
See:
http://mike.kaply.com/2010/07/08/what-is-a-persona/
For all the details about what’s in a Persona.
Actually, you can get the LightweightThemeManager directly.
var lwtm = Cu.import(“resource://gre/modules/LightweightThemeManager.jsm”);
var bgcolor;
if (lwtm.currentTheme) {
bgcolor = lwtm.currentTheme.accentcolor;
}
If you need the id, lwtm.currentTheme.id
Can you get the active theme directly from prefs? anyway this is a great example for calling AddonManager – it shows jetpack is not about web-pages only technology,but can work with core Firefox JS objects.