Rewrite of main.js using ExtensionUtils and new PreferencesManager API