Added a startup hook that opens the main application file in case no files
are opened.

Created a public API for embedders, added function buildInspectorUrl().
This commit is contained in:
Miroslav Bajtos 2013-07-22 08:54:58 +02:00
Родитель fdc55decf6
Коммит ca352b9911
3 изменённых файлов: 77 добавлений и 4 удалений

Просмотреть файл

@ -104,3 +104,55 @@ var loadXHR = function patchedLoadXHR(url, async, callback) {
}
return _orig_loadXHR(url, async, callback);
}
//
// Open the main application file on startup
//
WebInspector.notifications.addEventListener(
WebInspector.Events.InspectorLoaded,
function() {
WebInspector.resourceTreeModel.addEventListener(
WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded,
showMainAppFile,
null
);
},
null
);
function showMainAppFile() {
var fileTabs = WebInspector.showPanel('scripts')._editorContainer._files;
if (Object.keys(fileTabs).length > 0){
// Some files are already opened - do not change user's workspace
return;
}
var uiSourceCodes = getAllUiSourceCodes();
var uriToShow = WebInspector.inspectedPageURL;
for (var i in uiSourceCodes) {
if (uiSourceCodes[i].uri() !== uriToShow) continue;
WebInspector.showPanel('scripts').showUISourceCode(uiSourceCodes[i]);
return true;
}
console.error('Cannot show the main application file ', uriToShow);
}
function getAllUiSourceCodes() {
// Based on FilteredItemSectionDialog.js > SelectUISourceCodeDialog()
var projects = WebInspector.workspace.projects();
var uiSourceCodes = [];
var projectFiles;
for (var i = 0; i < projects.length; ++i) {
projectFiles = projects[i]
.uiSourceCodes()
.filter(function(p) { return p.name(); });
uiSourceCodes = uiSourceCodes.concat(projectFiles);
}
return uiSourceCodes;
}

22
index.js Normal file
Просмотреть файл

@ -0,0 +1,22 @@
// Public API for node-inspector embedders
var url = require('url');
exports.buildInspectorUrl = buildInspectorUrl;
/**
* Build a URL for loading inspector UI in the browser.
* @param {string|undefined} inspectorHost as configured via --web-host
* @param {number} inspectorPort as configured via --web-port
* @param {number} debugPort as configured via --debug in the debugged app
*/
function buildInspectorUrl(inspectorHost, inspectorPort, debugPort, fileToShow) {
var parts = {
protocol: 'http',
hostname: inspectorHost || '127.0.0.1',
port: inspectorPort,
pathname: '/debug',
search: '?port=' + debugPort
};
return url.format(parts);
}

Просмотреть файл

@ -5,6 +5,7 @@ var http = require('http'),
express = require('express'),
io = require('socket.io'),
Session = require('./session'),
buildUrl = require('../index.js').buildInspectorUrl,
WEBROOT = path.join(__dirname, '../front-end'),
config = {};
@ -46,10 +47,8 @@ function handleWebSocketConnection(socket) {
}
function handleServerListening() {
console.log(
'Visit http://' + (config.webHost || '127.0.0.1') + ':' +
config.webPort +
'/debug?port=' + config.debugPort + ' to start debugging.');
var url = buildUrl(config.webHost, config.webPort, config.debugPort);
console.log('Visit %s to start debugging.', url);
}
function DebugServer() {}