2016-12-19 19:34:24 -08:00
|
|
|
//
|
|
|
|
// debugWindow.js
|
|
|
|
//
|
|
|
|
// Brad Hefta-Gaub, created on 12/19/2016.
|
|
|
|
// Copyright 2016 High Fidelity, Inc.
|
|
|
|
//
|
|
|
|
// Distributed under the Apache License, Version 2.0.
|
|
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
//
|
|
|
|
|
2016-12-21 11:31:34 -08:00
|
|
|
(function() { // BEGIN LOCAL_SCOPE
|
2016-12-19 19:34:24 -08:00
|
|
|
|
2017-11-08 18:43:59 +01:00
|
|
|
//check if script already running.
|
|
|
|
var scriptData = ScriptDiscoveryService.getRunning();
|
|
|
|
var scripts = scriptData.filter(function (datum) { return datum.name === 'debugWindow.js'; });
|
|
|
|
if (scripts.length >= 2) {
|
|
|
|
//2nd instance of the script is too much
|
2017-11-08 21:53:42 +01:00
|
|
|
ScriptDiscoveryService.stopScript(scripts[1].url);
|
2017-11-08 18:43:59 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-19 19:34:24 -08:00
|
|
|
// Set up the qml ui
|
|
|
|
var qml = Script.resolvePath('debugWindow.qml');
|
2017-11-08 18:43:59 +01:00
|
|
|
|
2016-12-19 19:34:24 -08:00
|
|
|
var window = new OverlayWindow({
|
|
|
|
title: 'Debug Window',
|
|
|
|
source: qml,
|
|
|
|
width: 400, height: 900,
|
|
|
|
});
|
2017-11-08 18:43:59 +01:00
|
|
|
|
2016-12-19 19:34:24 -08:00
|
|
|
window.setPosition(25, 50);
|
|
|
|
window.closed.connect(function() { Script.stop(); });
|
|
|
|
|
2016-12-21 11:31:34 -08:00
|
|
|
var getFormattedDate = function() {
|
|
|
|
var date = new Date();
|
|
|
|
return date.getMonth() + "/" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
|
|
|
|
};
|
|
|
|
|
|
|
|
var sendToLogWindow = function(type, message, scriptFileName) {
|
|
|
|
var typeFormatted = "";
|
|
|
|
if (type) {
|
|
|
|
typeFormatted = type + " - ";
|
|
|
|
}
|
|
|
|
window.sendToQml("[" + getFormattedDate() + "] " + "[" + scriptFileName + "] " + typeFormatted + message);
|
|
|
|
};
|
|
|
|
|
2016-12-19 19:34:24 -08:00
|
|
|
ScriptDiscoveryService.printedMessage.connect(function(message, scriptFileName) {
|
2016-12-21 11:31:34 -08:00
|
|
|
sendToLogWindow("", message, scriptFileName);
|
2016-12-19 19:34:24 -08:00
|
|
|
});
|
2016-12-20 09:00:01 -08:00
|
|
|
|
|
|
|
ScriptDiscoveryService.warningMessage.connect(function(message, scriptFileName) {
|
2016-12-21 11:31:34 -08:00
|
|
|
sendToLogWindow("WARNING", message, scriptFileName);
|
2016-12-20 09:00:01 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
ScriptDiscoveryService.errorMessage.connect(function(message, scriptFileName) {
|
2016-12-21 11:31:34 -08:00
|
|
|
sendToLogWindow("ERROR", message, scriptFileName);
|
2016-12-20 09:00:01 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
ScriptDiscoveryService.infoMessage.connect(function(message, scriptFileName) {
|
2016-12-21 11:31:34 -08:00
|
|
|
sendToLogWindow("INFO", message, scriptFileName);
|
2016-12-20 09:00:01 -08:00
|
|
|
});
|
2016-12-21 11:31:34 -08:00
|
|
|
|
2017-06-13 20:25:01 +05:30
|
|
|
ScriptDiscoveryService.clearDebugWindow.connect(function() {
|
|
|
|
window.clearDebugWindow();
|
2017-06-06 19:00:21 +05:30
|
|
|
});
|
|
|
|
|
2017-10-16 16:12:54 -04:00
|
|
|
Script.scriptEnding.connect(function () {
|
|
|
|
window.close();
|
|
|
|
})
|
|
|
|
|
2017-06-13 20:25:01 +05:30
|
|
|
}());
|