Esempio n. 1
0
 play: Task.async(function* () {
   let busy;
   switch (AppManager.selectedProject.type) {
     case "packaged":
       let autosave =
         Services.prefs.getBoolPref("devtools.webide.autosaveFiles");
       if (autosave && UI.projecteditor) {
         yield UI.projecteditor.saveAllFiles();
       }
       busy = UI.busyWithProgressUntil(AppManager.installAndRunProject(),
                                       "installing and running app");
       break;
     case "hosted":
       busy = UI.busyUntil(AppManager.installAndRunProject(),
                           "installing and running app");
       break;
     case "runtimeApp":
       busy = UI.busyUntil(AppManager.launchOrReloadRuntimeApp(), "launching / reloading app");
       break;
     case "tab":
       busy = UI.busyUntil(AppManager.reloadTab(), "reloading tab");
       break;
   }
   if (!busy) {
     return promise.reject();
   }
   UI.onAction("play");
   return busy;
 }),
Esempio n. 2
0
 destroy: function() {
   window.removeEventListener("focus", this.onfocus, true);
   AppManager.off("app-manager-update", this.appManagerUpdate);
   AppManager.destroy();
   this.updateConnectionTelemetry();
   this._telemetry.toolClosed("webide");
 },
Esempio n. 3
0
  init: function () {
    this._telemetry = new Telemetry();
    this._telemetry.toolOpened("webide");

    AppManager.init();

    this.appManagerUpdate = this.appManagerUpdate.bind(this);
    AppManager.on("app-manager-update", this.appManagerUpdate);

    Cmds.showProjectPanel();
    Cmds.showRuntimePanel();

    this.updateCommands();

    this.onfocus = this.onfocus.bind(this);
    window.addEventListener("focus", this.onfocus, true);

    AppProjects.load().then(() => {
      this.autoSelectProject();
    }, e => {
      console.error(e);
      this.reportError("error_appProjectsLoadFailed");
    });

    // Auto install the ADB Addon Helper and Tools Adapters. Only once.
    // If the user decides to uninstall any of this addon, we won't install it again.
    let autoinstallADBHelper = Services.prefs.getBoolPref("devtools.webide.autoinstallADBHelper");
    let autoinstallFxdtAdapters = Services.prefs.getBoolPref("devtools.webide.autoinstallFxdtAdapters");
    if (autoinstallADBHelper) {
      GetAvailableAddons().then(addons => {
        addons.adb.install();
      }, console.error);
    }
    if (autoinstallFxdtAdapters) {
      GetAvailableAddons().then(addons => {
        addons.adapters.install();
      }, console.error);
    }
    Services.prefs.setBoolPref("devtools.webide.autoinstallADBHelper", false);
    Services.prefs.setBoolPref("devtools.webide.autoinstallFxdtAdapters", false);

    if (Services.prefs.getBoolPref("devtools.webide.widget.autoinstall") &&
        !Services.prefs.getBoolPref("devtools.webide.widget.enabled")) {
      Services.prefs.setBoolPref("devtools.webide.widget.enabled", true);
      gDevToolsBrowser.moveWebIDEWidgetInNavbar();
    }

    this.setupDeck();

    this.contentViewer = window.QueryInterface(Ci.nsIInterfaceRequestor)
                               .getInterface(Ci.nsIWebNavigation)
                               .QueryInterface(Ci.nsIDocShell)
                               .contentViewer;
    this.contentViewer.fullZoom = Services.prefs.getCharPref("devtools.webide.zoom");

    gDevToolsBrowser.isWebIDEInitialized.resolve();

    this.configureSimulator = this.configureSimulator.bind(this);
    Simulators.on("configure", this.configureSimulator);
  },
Esempio n. 4
0
  destroy: function() {
    window.removeEventListener("focus", this.onfocus, true);
    AppManager.off("app-manager-update", this.appManagerUpdate);
    AppManager.destroy();
    this.updateConnectionTelemetry();

    // webide is not connected with a toolbox so we pass -1 as the
    // toolbox session id.
    this._telemetry.toolClosed("webide", -1, this);
  },
Esempio n. 5
0
  init: function() {
    this._telemetry = new Telemetry();

    // webide is not connected with a toolbox so we pass -1 as the
    // toolbox session id.
    this._telemetry.toolOpened("webide", -1, this);

    this.notificationBox = new window.MozElements.NotificationBox(element => {
      document.getElementById("containerbox")
              .insertAdjacentElement("afterbegin", element);
    });
    AppManager.init();

    this.appManagerUpdate = this.appManagerUpdate.bind(this);
    AppManager.on("app-manager-update", this.appManagerUpdate);

    Cmds.showProjectPanel();
    Cmds.showRuntimePanel();

    this.updateCommands();

    this.onfocus = this.onfocus.bind(this);
    window.addEventListener("focus", this.onfocus, true);

    AppProjects.load().then(() => {
      this.autoSelectProject();
    }, e => {
      console.error(e);
      this.reportError("error_appProjectsLoadFailed");
    });

    // Auto install the ADB Addon Helper. Only once.
    // If the user decides to uninstall any of this addon, we won't install it again.
    const autoinstallADBExtension = Services.prefs.getBoolPref("devtools.webide.autoinstallADBExtension");
    if (autoinstallADBExtension) {
      adbAddon.install("webide");
    }

    // Remove deprecated remote debugging extensions.
    adbAddon.uninstallUnsupportedExtensions();

    Services.prefs.setBoolPref("devtools.webide.autoinstallADBExtension", false);

    this.setupDeck();

    this.contentViewer = window.docShell.contentViewer;
    this.contentViewer.fullZoom = Services.prefs.getCharPref("devtools.webide.zoom");

    gDevToolsBrowser.isWebIDEInitialized.resolve();
  },
Esempio n. 6
0
module.exports = ProjectList = function (win, parentWindow) {
  EventEmitter.decorate(this);
  this._doc = win.document;
  this._UI = parentWindow.UI;
  this._parentWindow = parentWindow;
  this._telemetry = new Telemetry();
  this._panelNodeEl = "div";

  this.onWebIDEUpdate = this.onWebIDEUpdate.bind(this);
  this._UI.on("webide-update", this.onWebIDEUpdate);

  AppManager.init();
  this.appManagerUpdate = this.appManagerUpdate.bind(this);
  AppManager.on("app-manager-update", this.appManagerUpdate);
};
Esempio n. 7
0
 refreshTabs: function () {
   if (AppManager.connected) {
     return AppManager.listTabs().then(() => {
       this.updateTabs();
     }).catch(console.error);
   }
 },
Esempio n. 8
0
module.exports = RuntimeList = function (window, parentWindow) {
  EventEmitter.decorate(this);
  this._doc = window.document;
  this._UI = parentWindow.UI;
  this._Cmds = parentWindow.Cmds;
  this._parentWindow = parentWindow;
  this._panelNodeEl = "button";
  this._panelBoxEl = "div";

  this.onWebIDEUpdate = this.onWebIDEUpdate.bind(this);
  this._UI.on("webide-update", this.onWebIDEUpdate);

  AppManager.init();
  this.appManagerUpdate = this.appManagerUpdate.bind(this);
  AppManager.on("app-manager-update", this.appManagerUpdate);
};
Esempio n. 9
0
      AppProjects.load().then(() => {
        let projects = AppProjects.projects;
        for (let i = 0; i < projects.length; i++) {
          let project = projects[i];
          let panelItemNode = doc.createElement(this._panelNodeEl);
          panelItemNode.className = "panel-item";
          projectsNode.appendChild(panelItemNode);
          if (!project.validationStatus) {
            // The result of the validation process (storing names, icons, …) is not stored in
            // the IndexedDB database when App Manager v1 is used.
            // We need to run the validation again and update the name and icon of the app.
            AppManager.validateAndUpdateProject(project).then(() => {
              this._renderProjectItem({
                panel: panelItemNode,
                name: project.name,
                icon: project.icon
              });
            });
          } else {
            this._renderProjectItem({
              panel: panelItemNode,
              name: project.name || AppManager.DEFAULT_PROJECT_NAME,
              icon: project.icon || AppManager.DEFAULT_PROJECT_ICON
            });
          }
          panelItemNode.addEventListener("click", () => {
            AppManager.selectedProject = project;
          }, true);
        }

        resolve();
      }, reject);
Esempio n. 10
0
  createToolbox: function () {
    // If |this.toolboxPromise| exists, there is already a live toolbox
    if (this.toolboxPromise) {
      return this.toolboxPromise;
    }

    let iframe = document.createElement("iframe");
    iframe.id = "toolbox";

    // Compute a uid on the iframe in order to identify toolbox iframe
    // when receiving toolbox-close event
    iframe.uid = new Date().getTime();

    let height = Services.prefs.getIntPref("devtools.toolbox.footer.height");
    iframe.height = height;

    let promise = this.toolboxPromise = AppManager.getTarget().then(target => {
      return this._showToolbox(target, iframe);
    }).then(toolbox => {
      // Destroy the toolbox on WebIDE side before
      // toolbox.destroy's promise resolves.
      toolbox.once("destroyed", this._onToolboxClosed.bind(this, promise, iframe));
      return toolbox;
    }, console.error);

    return this.busyUntil(this.toolboxPromise, "opening toolbox");
  },
Esempio n. 11
0
 destroy: function () {
   this._doc = null;
   AppManager.off("app-manager-update", this.appManagerUpdate);
   this._UI.off("webide-update", this.onWebIDEUpdate);
   this._UI = null;
   this._parentWindow = null;
   this._panelNodeEl = null;
 }
Esempio n. 12
0
  autoStartProject: Task.async(function* () {
    let project = AppManager.selectedProject;

    if (!project) {
      return;
    }
    if (!(project.type == "runtimeApp" ||
          project.type == "mainProcess" ||
          project.type == "tab")) {
      return; // For something that is not an editable app, we're done.
    }

    // Do not force opening apps that are already running, as they may have
    // some activity being opened and don't want to dismiss them.
    if (project.type == "runtimeApp" && !AppManager.isProjectRunning()) {
      yield UI.busyUntil(AppManager.launchRuntimeApp(), "running app");
    }
  }),
Esempio n. 13
0
    return new Promise((resolve, reject) => {
      let doc = this._doc;
      let projectsNode = doc.querySelector("#project-panel-projects");

      while (projectsNode.hasChildNodes()) {
        projectsNode.firstChild.remove();
      }

      AppProjects.load().then(() => {
        let projects = AppProjects.projects;
        for (let i = 0; i < projects.length; i++) {
          let project = projects[i];
          let panelItemNode = doc.createElement(this._panelNodeEl);
          panelItemNode.className = "panel-item";
          projectsNode.appendChild(panelItemNode);
          if (!project.validationStatus) {
            // The result of the validation process (storing names, icons, …) is not stored in
            // the IndexedDB database when App Manager v1 is used.
            // We need to run the validation again and update the name and icon of the app.
            AppManager.validateAndUpdateProject(project).then(() => {
              this._renderProjectItem({
                panel: panelItemNode,
                name: project.name,
                icon: project.icon
              });
            });
          } else {
            this._renderProjectItem({
              panel: panelItemNode,
              name: project.name || AppManager.DEFAULT_PROJECT_NAME,
              icon: project.icon || AppManager.DEFAULT_PROJECT_ICON
            });
          }
          panelItemNode.addEventListener("click", () => {
            AppManager.selectedProject = project;
          }, true);
        }

        resolve();
      }, reject);

      // List remote apps and the main process, if they exist
      this.updateApps();

      // Build the tab list right now, so it's fast...
      this.updateTabs();

      // But re-list them and rebuild, in case any tabs navigated since the last
      // time they were listed.
      if (AppManager.connected) {
        AppManager.listTabs().then(() => {
          this.updateTabs();
        }).catch(console.error);
      }
    });
Esempio n. 14
0
 AppManager.validateAndUpdateProject(project).then(() => {
   if (project.manifest) {
     project.manifest.name = projectName;
     AppManager.writeManifest(project).then(() => {
       AppManager.validateAndUpdateProject(project).then(
         () => {window.close()}, bail)
     }, bail)
   } else {
     bail("Manifest not found");
   }
 }, bail)
Esempio n. 15
0
window.addEventListener("load", function() {
  AppManager.on("app-manager-update", OnAppManagerUpdate);
  document.getElementById("close").onclick = CloseUI;
  document.getElementById("device-fields").onchange = UpdateField;
  document.getElementById("device-fields").onclick = CheckReset;
  document.getElementById("search-bar").onkeyup = document.getElementById("search-bar").onclick = SearchField;
  document.getElementById("custom-value").onclick = UpdateNewField;
  document.getElementById("custom-value-type").onchange = ClearNewFields;
  document.getElementById("add-custom-field").onkeyup = CheckNewFieldSubmit;
  BuildUI();
}, {capture: true, once: true});
Esempio n. 16
0
window.addEventListener("load", function() {
  document.querySelector("#close").onclick = CloseUI;
  document.querySelector("#devtools-check button").onclick = EnableCertApps;
  document.querySelector("#adb-check button").onclick = RootADB;
  document.querySelector("#unrestricted-privileges").onclick = function() {
    window.parent.UI.openInBrowser(UNRESTRICTED_HELP_URL);
  };
  AppManager.on("app-manager-update", OnAppManagerUpdate);
  BuildUI();
  CheckLockState();
}, {capture: true, once: true});
Esempio n. 17
0
  init: function() {
    this._telemetry = new Telemetry();
    this._telemetry.toolOpened("webide");

    AppManager.init();

    this.appManagerUpdate = this.appManagerUpdate.bind(this);
    AppManager.on("app-manager-update", this.appManagerUpdate);

    Cmds.showProjectPanel();
    Cmds.showRuntimePanel();

    this.updateCommands();

    this.onfocus = this.onfocus.bind(this);
    window.addEventListener("focus", this.onfocus, true);

    AppProjects.load().then(() => {
      this.autoSelectProject();
    }, e => {
      console.error(e);
      this.reportError("error_appProjectsLoadFailed");
    });

    // Auto install the ADB Addon Helper. Only once.
    // If the user decides to uninstall any of this addon, we won't install it again.
    const autoinstallADBHelper = Services.prefs.getBoolPref("devtools.webide.autoinstallADBHelper");
    if (autoinstallADBHelper) {
      const addons = GetAvailableAddons();
      addons.adb.install();
    }

    Services.prefs.setBoolPref("devtools.webide.autoinstallADBHelper", false);

    this.setupDeck();

    this.contentViewer = window.docShell.contentViewer;
    this.contentViewer.fullZoom = Services.prefs.getCharPref("devtools.webide.zoom");

    gDevToolsBrowser.isWebIDEInitialized.resolve();
  },
Esempio n. 18
0
 onfocus: function() {
   // Because we can't track the activity in the folder project,
   // we need to validate the project regularly. Let's assume that
   // if a modification happened, it happened when the window was
   // not focused.
   if (AppManager.selectedProject &&
       AppManager.selectedProject.type != "mainProcess" &&
       AppManager.selectedProject.type != "runtimeApp" &&
       AppManager.selectedProject.type != "tab") {
     AppManager.validateAndUpdateProject(AppManager.selectedProject);
   }
 },
Esempio n. 19
0
 AppProjects.addPackaged(folder).then((project) => {
   window.arguments[0].location = project.location;
   AppManager.validateAndUpdateProject(project).then(() => {
     if (project.manifest) {
       project.manifest.name = projectName;
       AppManager.writeManifest(project).then(() => {
         AppManager.validateAndUpdateProject(project).then(
           () => {window.close()}, bail)
       }, bail)
     } else {
       bail("Manifest not found");
     }
   }, bail)
 }, bail)
Esempio n. 20
0
  autoSelectProject: function () {
    if (AppManager.selectedProject) {
      return;
    }
    let shouldRestore = Services.prefs.getBoolPref("devtools.webide.restoreLastProject");
    if (!shouldRestore) {
      return;
    }
    let pref = Services.prefs.getCharPref("devtools.webide.lastSelectedProject");
    if (!pref) {
      return;
    }
    let m = pref.match(/^(\w+):(.*)$/);
    if (!m) {
      return;
    }
    let [_, type, project] = m;

    if (type == "local") {
      let lastProject = AppProjects.get(project);
      if (lastProject) {
        AppManager.selectedProject = lastProject;
      }
    }

    // For other project types, we need to be connected to the runtime
    if (!AppManager.connected) {
      return;
    }

    if (type == "mainProcess" && AppManager.isMainProcessDebuggable()) {
      AppManager.selectedProject = {
        type: "mainProcess",
        name: Strings.GetStringFromName("mainProcess_label"),
        icon: AppManager.DEFAULT_PROJECT_ICON
      };
    } else if (type == "runtimeApp") {
      let app = AppManager.apps.get(project);
      if (app) {
        AppManager.selectedProject = {
          type: "runtimeApp",
          app: app.manifest,
          icon: app.iconURL,
          name: app.manifest.name
        };
      }
    }
  },
Esempio n. 21
0
 connectToRuntime: function (runtime) {
   let name = runtime.name;
   let promise = AppManager.connectToRuntime(runtime);
   promise.then(() => this.initConnectionTelemetry())
          .catch(() => {
            // Empty rejection handler to silence uncaught rejection warnings
            // |busyUntil| will listen for rejections.
            // Bug 1121100 may find a better way to silence these.
          });
   promise = this.busyUntil(promise, "Connecting to " + name);
   // Stop busy timeout for runtimes that take unknown or long amounts of time
   // to connect.
   if (runtime.prolongedConnection) {
     this.cancelBusyTimeout();
   }
   return promise;
 },
Esempio n. 22
0
  onfocus: function () {
    // Because we can't track the activity in the folder project,
    // we need to validate the project regularly. Let's assume that
    // if a modification happened, it happened when the window was
    // not focused.
    if (AppManager.selectedProject &&
        AppManager.selectedProject.type != "mainProcess" &&
        AppManager.selectedProject.type != "runtimeApp" &&
        AppManager.selectedProject.type != "tab") {
      AppManager.validateAndUpdateProject(AppManager.selectedProject);
    }

    // Hook to display promotional Developer Edition doorhanger. Only displayed once.
    // Hooked into the `onfocus` event because sometimes does not work
    // when run at the end of `init`. ¯\(°_o)/¯
    showDoorhanger({ window, type: "deveditionpromo", anchor: document.querySelector("#deck") });
  },
Esempio n. 23
0
 unload: function() {
   AppManager.off('app-manager-update', Monitor.onAppManagerUpdate);
   Monitor.disconnectFromRuntime();
   Monitor.disconnectFromWebSocket();
 },
Esempio n. 24
0
 let disconnecting = Task.spawn(function* () {
   yield UI.destroyToolbox();
   yield AppManager.disconnectRuntime();
 });
Esempio n. 25
0
 this.projecteditor.on("onEditorSave", () => {
   AppManager.validateAndUpdateProject(AppManager.selectedProject);
   this._telemetry.actionOccurred("webideProjectEditorSave");
 });
Esempio n. 26
0
  updateCommands: function () {
    // Action commands
    let playCmd = document.querySelector("#cmd_play");
    let stopCmd = document.querySelector("#cmd_stop");
    let debugCmd = document.querySelector("#cmd_toggleToolbox");
    let playButton = document.querySelector("#action-button-play");
    let projectPanelCmd = document.querySelector("#cmd_showProjectPanel");

    if (document.querySelector("window").classList.contains("busy")) {
      playCmd.setAttribute("disabled", "true");
      stopCmd.setAttribute("disabled", "true");
      debugCmd.setAttribute("disabled", "true");
      projectPanelCmd.setAttribute("disabled", "true");
      return;
    }

    if (!AppManager.selectedProject || !AppManager.connected) {
      playCmd.setAttribute("disabled", "true");
      stopCmd.setAttribute("disabled", "true");
      debugCmd.setAttribute("disabled", "true");
    } else {
      let isProjectRunning = AppManager.isProjectRunning();
      if (isProjectRunning) {
        playButton.classList.add("reload");
        stopCmd.removeAttribute("disabled");
        debugCmd.removeAttribute("disabled");
      } else {
        playButton.classList.remove("reload");
        stopCmd.setAttribute("disabled", "true");
        debugCmd.setAttribute("disabled", "true");
      }

      // If connected and a project is selected
      if (AppManager.selectedProject.type == "runtimeApp") {
        playCmd.removeAttribute("disabled");
      } else if (AppManager.selectedProject.type == "tab") {
        playCmd.removeAttribute("disabled");
        stopCmd.setAttribute("disabled", "true");
      } else if (AppManager.selectedProject.type == "mainProcess") {
        playCmd.setAttribute("disabled", "true");
        stopCmd.setAttribute("disabled", "true");
      } else {
        if (AppManager.selectedProject.errorsCount == 0 &&
            AppManager.runtimeCanHandleApps()) {
          playCmd.removeAttribute("disabled");
        } else {
          playCmd.setAttribute("disabled", "true");
        }
      }
    }

    // Runtime commands
    let monitorCmd = document.querySelector("#cmd_showMonitor");
    let screenshotCmd = document.querySelector("#cmd_takeScreenshot");
    let detailsCmd = document.querySelector("#cmd_showRuntimeDetails");
    let disconnectCmd = document.querySelector("#cmd_disconnectRuntime");
    let devicePrefsCmd = document.querySelector("#cmd_showDevicePrefs");
    let settingsCmd = document.querySelector("#cmd_showSettings");

    if (AppManager.connected) {
      if (AppManager.deviceFront) {
        monitorCmd.removeAttribute("disabled");
        detailsCmd.removeAttribute("disabled");
        screenshotCmd.removeAttribute("disabled");
      }
      if (AppManager.preferenceFront) {
        devicePrefsCmd.removeAttribute("disabled");
      }
      disconnectCmd.removeAttribute("disabled");
    } else {
      monitorCmd.setAttribute("disabled", "true");
      detailsCmd.setAttribute("disabled", "true");
      screenshotCmd.setAttribute("disabled", "true");
      disconnectCmd.setAttribute("disabled", "true");
      devicePrefsCmd.setAttribute("disabled", "true");
      settingsCmd.setAttribute("disabled", "true");
    }

    let runtimePanelButton = document.querySelector("#runtime-panel-button");

    if (AppManager.connected) {
      runtimePanelButton.setAttribute("active", "true");
      runtimePanelButton.removeAttribute("hidden");
    } else {
      runtimePanelButton.removeAttribute("active");
      runtimePanelButton.setAttribute("hidden", "true");
    }

    projectPanelCmd.removeAttribute("disabled");
  },
Esempio n. 27
0
 removeProject: function () {
   AppManager.removeSelectedProject();
 },
Esempio n. 28
0
 stop: function () {
   return UI.busyUntil(AppManager.stopRunningApp(), "stopping app");
 },
Esempio n. 29
0
window.addEventListener("unload", function onUnload() {
  window.removeEventListener("unload", onUnload);
  AppManager.off("app-manager-update", OnAppManagerUpdate);
});
Esempio n. 30
0
 load: function() {
   AppManager.on('app-manager-update', Monitor.onAppManagerUpdate);
   Monitor.connectToRuntime();
   Monitor.connectToWebSocket();
 },