1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/b2g/simulator/lib/main.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +const { Cc, Ci, Cu } = require("chrome"); 1.10 + 1.11 +const { SimulatorProcess } = require("./simulator-process"); 1.12 +const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {}); 1.13 +const Self = require("sdk/self"); 1.14 +const System = require("sdk/system"); 1.15 +const { Simulator } = Cu.import("resource://gre/modules/devtools/Simulator.jsm"); 1.16 + 1.17 +let process; 1.18 + 1.19 +function launch({ port }) { 1.20 + // Close already opened simulation 1.21 + if (process) { 1.22 + return close().then(launch.bind(null, { port: port })); 1.23 + } 1.24 + 1.25 + process = SimulatorProcess(); 1.26 + process.remoteDebuggerPort = port; 1.27 + process.run(); 1.28 + 1.29 + return promise.resolve(); 1.30 +} 1.31 + 1.32 +function close() { 1.33 + if (!process) { 1.34 + return promise.resolve(); 1.35 + } 1.36 + let p = process; 1.37 + process = null; 1.38 + return p.kill(); 1.39 +} 1.40 + 1.41 + 1.42 +// Load data generated at build time that 1.43 +// expose various information about the runtime we ship 1.44 +let appinfo = System.staticArgs; 1.45 + 1.46 +Simulator.register(appinfo.label, { 1.47 + appinfo: appinfo, 1.48 + launch: launch, 1.49 + close: close 1.50 +}); 1.51 + 1.52 +require("sdk/system/unload").when(function () { 1.53 + Simulator.unregister(appinfo.label); 1.54 + close(); 1.55 +});