browser/tools/mozscreenshots/mozscreenshots/extension/configurations/LightweightThemes.jsm
author Kris Maglione <maglione.k@gmail.com>
Mon, 29 Jan 2018 15:20:18 -0800
changeset 453844 34c999fa006bffe8705cf50c54708aa21a962e62
parent 453830 505fc52bd6080c95bf27458a5753340b326f0fa1
child 453889 c6e0fe339cb1e7c0c029e68be5332e52f53ab6b7
permissions -rw-r--r--
Bug 1431533: Part 5a - Auto-rewrite code to use ChromeUtils import methods. r=florian This was done using the following script: https://bitbucket.org/kmaglione/m-c-rewrites/src/37e3803c7a23385bab5ea077ba8692bcfe1608fc/processors/chromeutils-import.jsm MozReview-Commit-ID: 1Nc3XDu0wGl

/* This Source Code Form is subject to the terms of the Mozilla Public
 * 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/. */

"use strict";

this.EXPORTED_SYMBOLS = ["LightweightThemes"];

const {classes: Cc, interfaces: Ci, utils: Cu} = Components;

ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/Timer.jsm");

this.LightweightThemes = {
  init(libDir) {
    // convert -size 3000x200 canvas:#333 black_theme.png
    let blackImage = libDir.clone();
    blackImage.append("black_theme.png");
    this._blackImageURL = Services.io.newFileURI(blackImage).spec;

    // convert -size 3000x200 canvas:#eee white_theme.png
    let whiteImage = libDir.clone();
    whiteImage.append("white_theme.png");
    this._whiteImageURL = Services.io.newFileURI(whiteImage).spec;
  },

  configurations: {
    noLWT: {
      selectors: ["#navigator-toolbox"],
      async applyConfig() {
        LightweightThemeManager.currentTheme = null;
      },
    },

    darkLWT: {
      selectors: ["#navigator-toolbox"],
      applyConfig() {
        LightweightThemeManager.setLocalTheme({
          id:          "black",
          name:        "black",
          headerURL:   LightweightThemes._blackImageURL,
          textcolor:   "#eeeeee",
          accentcolor: "#111111",
        });

        // Wait for LWT listener
        return new Promise(resolve => {
          setTimeout(() => {
            resolve("darkLWT");
          }, 500);
        });
      },
    },

    lightLWT: {
      selectors: ["#navigator-toolbox"],
      applyConfig() {
        LightweightThemeManager.setLocalTheme({
          id:          "white",
          name:        "white",
          headerURL:   LightweightThemes._whiteImageURL,
          textcolor:   "#111111",
          accentcolor: "#eeeeee",
        });
        // Wait for LWT listener
        return new Promise(resolve => {
          setTimeout(() => {
            resolve("lightLWT");
          }, 500);
        });
      },
    },

    compactLight: {
      selectors: ["#navigator-toolbox"],
      applyConfig() {
        LightweightThemeManager.currentTheme = LightweightThemeManager.getUsedTheme("firefox-compact-light@mozilla.org");
      },
    },

    compactDark: {
      selectors: ["#navigator-toolbox"],
      applyConfig() {
        LightweightThemeManager.currentTheme = LightweightThemeManager.getUsedTheme("firefox-compact-dark@mozilla.org");
      },
    },
  },
};