Redirect pgAdmin main window console logs to NW.js server logs.

This commit is contained in:
Aditya Toshniwal 2023-04-06 15:16:14 +05:30 committed by GitHub
parent 644575415e
commit a93c0c8d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 1 deletions

View File

@ -424,6 +424,18 @@ let ConfigureStore = {
},
};
function parseConsoleArgs(_method, args) {
const retData = Array.from(args).map(arg => {
try {
if(arg.stack) return arg.stack;
return JSON.stringify(arg);
} catch (e) {
return arg
}
});
return retData?.join(' ');
}
module.exports = {
readServerLog: readServerLog,
@ -444,4 +456,5 @@ module.exports = {
unregisterZoomEvents: unregisterZoomEvents,
setZoomLevelForAllWindows: setZoomLevelForAllWindows,
ConfigureStore: ConfigureStore,
parseConsoleArgs: parseConsoleArgs,
};

View File

@ -11,6 +11,7 @@ const fs = require('fs');
const path = require('path');
const misc = require('../js/misc.js');
const spawn = require('child_process').spawn;
const {EOL} = require('os');
let pgadminServerProcess = null;
let startPageUrl = null;
@ -249,6 +250,10 @@ function launchPgAdminWindow() {
* nothing but a splash screen. We will have to make it null,
* so that open in new browser tab will work.
*/
pgadminWindow.window.hookConsole((method, args)=>{
misc.writeServerLog(
`--------------[UI ${method}]---------------${EOL}${misc.parseConsoleArgs(method, args)}${EOL}------------[UI End]----------------`);
});
pgadminWindow.window.opener = null;
// Show new window

View File

@ -3,6 +3,17 @@
{% block title %}{{ config.APP_NAME }}{% endblock %}
{% block init_script %}
window.hookConsole = function(callback) {
for (const method of ['log', 'error']) {
const nativeMethod = window.console[method];
window.console[method] = function () {
nativeMethod.apply(this, arguments);
setTimeout(()=>{
callback(method, arguments);
});
}
}
}
try {
require(
['sources/generated/app.bundle', 'sources/generated/codemirror', 'sources/generated/browser_nodes'],

View File

@ -176,7 +176,7 @@ export class MenuItem {
* Checks this menu enable/disable state based on the selection.
*/
disabled(node, item) {
if (this.enable == undefined) {
if (this.enable == undefined || !node) {
return false;
}