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

4 thoughts on “Get current active theme in #JetPack

  1. Thanks Michael. For jetPack it should be:

    var lwtm = Cu.import('resource://gre/modules/LightweightThemeManager.jsm').LightweightThemeManager;
    
    
  2. 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

  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.