Improve performance by removing signal-based zoom-in, zoom-out, etc functionality from the runtime environment. #5723

This commit is contained in:
Nikhil Mohite 2023-01-17 17:18:35 +05:30 committed by GitHub
parent e0a3420cd9
commit a48828e7a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 157 additions and 192 deletions

View File

@ -100,41 +100,7 @@ function startDesktopMode() {
pgadminServerProcess.stderr.setEncoding('utf8');
pgadminServerProcess.stderr.on('data', (chunk) => {
if (chunk.indexOf('Runtime Open Configuration') > -1) {
// Create and launch new window and open pgAdmin url
nw.Window.open('src/html/configure.html', {
'frame': true,
'width': 600,
'height': 585,
'position': 'center',
'resizable': false,
'focus': true,
'show': true,
});
} else if (chunk.indexOf('Runtime Open View Log') > -1) {
// Create and launch new window and open pgAdmin url
nw.Window.open('src/html/view_log.html', {
'frame': true,
'width': 790,
'height': 425,
'position': 'center',
'resizable': false,
'focus': true,
'show': true,
});
} else if (chunk.indexOf('Runtime Zoom In') >= 0) {
misc.zoomIn();
} else if (chunk.indexOf('Runtime Zoom Out') >= 0) {
misc.zoomOut();
} else if (chunk.indexOf('Runtime Actual Size') >= 0) {
misc.actualSize();
} else if (chunk.indexOf('Runtime Toggle Full Screen') >= 0) {
misc.toggleFullScreen();
} else if (chunk.indexOf('Runtime new window opened') >= 0) {
misc.setZoomLevelForAllWindows();
} else {
misc.writeServerLog(chunk);
}
misc.writeServerLog(chunk);
});
// This function is used to ping the pgAdmin4 server whether it
@ -298,6 +264,7 @@ function launchPgAdminWindow() {
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-enable-disable-menu-items', enableDisableMenuItem);
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-refresh-menu-item', refreshMenuItems);
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-update-checked-menu-item', updateCheckedMenuItem);
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-set-new-window-open-size', setNewWindowSize)
// Add Main Menus to native menu.
pgadminWindow.window.pgAdmin.Browser.MainMenus.forEach((menu)=> {
addMenu(menu)
@ -381,6 +348,10 @@ splashWindow.on('close', function () {
misc.cleanupAndQuitApp();
});
function setNewWindowSize(){
misc.setZoomLevelForAllWindows();
}
function addCommonMenus(menu) {
let _menu = new gui.Menu();
@ -403,6 +374,11 @@ function addCommonMenus(menu) {
_menu.append(_menuItem);
});
if (menu.name == 'file') {
let runtimeMenu = getRuntimeMenu();
_menu.append(runtimeMenu);
}
if (menu.menuItems.length == 0) {
let _menuItem = new gui.MenuItem({
label: 'No object selected',
@ -429,6 +405,113 @@ function addCommonMenus(menu) {
}
function getRuntimeMenu() {
let controlKey = platform() === 'darwin' ? 'cmd' : 'ctrl';
let fullScreenKey = platform() === 'darwin' ? 'F' : 'F10';
let subMenus = new gui.Menu();
let rtmenudt = pgAdminMainScreen.window.pgAdmin.Browser.RUNTIME_MENUS_OPTIONS['runtime']
let runtimeSubMenus = pgAdminMainScreen.window.pgAdmin.Browser.RUNTIME_MENUS_OPTIONS['runtime']['submenus']
subMenus.append(new gui.MenuItem({
label: runtimeSubMenus['configure'].label,
enabled: runtimeSubMenus['configure'].enable,
priority: runtimeSubMenus['configure'].priority,
type: 'normal',
checked: false,
click: function () {
// Create and launch new window and open pgAdmin url
nw.Window.open('src/html/configure.html', {
'frame': true,
'width': 600,
'height': 585,
'position': 'center',
'resizable': false,
'focus': true,
'show': true,
});
},
}));
subMenus.append(new gui.MenuItem({
label: runtimeSubMenus['view_log'].label,
enabled: runtimeSubMenus['view_log'].enable,
priority: runtimeSubMenus['view_log'].priority,
type: 'normal',
checked: false,
click: function () {
// Create and launch new window and open pgAdmin url
nw.Window.open('src/html/view_log.html', {
'frame': true,
'width': 790,
'height': 425,
'position': 'center',
'resizable': false,
'focus': true,
'show': true,
});
},
}));
subMenus.append(new nw.MenuItem({ type: 'separator' }));
subMenus.append(new gui.MenuItem({
label: runtimeSubMenus['enter_full_screen'].label,
enabled: runtimeSubMenus['enter_full_screen'].enable,
priority: runtimeSubMenus['enter_full_screen'].priority,
type: 'normal',
checked: false,
key: runtimeSubMenus['enter_full_screen'].key,
modifiers: runtimeSubMenus['enter_full_screen'].modifiers,
click: function () {
misc.toggleFullScreen();
},
}));
subMenus.append(new gui.MenuItem({
label: runtimeSubMenus['actual_size'].label,
enabled: runtimeSubMenus['actual_size'].enable,
priority: runtimeSubMenus['actual_size'].priority,
type: 'normal',
checked: false,
key: runtimeSubMenus['actual_size'].key,
modifiers: runtimeSubMenus['actual_size'].modifiers,
click: function () {
misc.actualSize();
},
}));
subMenus.append(new gui.MenuItem({
label: runtimeSubMenus['zoom_in'].label,
enabled: runtimeSubMenus['zoom_in'].enable,
priority: runtimeSubMenus['zoom_in'].priority,
type: 'normal',
checked: false,
key: runtimeSubMenus['zoom_in'].key,
modifiers: runtimeSubMenus['zoom_in'].modifiers,
click: function () {
misc.zoomIn();
},
}));
subMenus.append(new gui.MenuItem({
label: runtimeSubMenus['zoom_out'].label,
enabled: runtimeSubMenus['zoom_out'].enable,
priority: runtimeSubMenus['zoom_out'].priority,
type: 'normal',
checked: false,
key: runtimeSubMenus['zoom_out'].key,
modifiers: runtimeSubMenus['zoom_out'].modifiers,
click: function () {
misc.zoomOut();
},
}));
let runtimeMenu = new gui.MenuItem({
label: rtmenudt.label,
enabled: true,
priority: rtmenudt.priority,
type: 'normal',
checked: false,
submenu: subMenus,
})
return runtimeMenu;
}
function getSubMenu(menuItem) {
let submenu = new gui.Menu();
if (menuItem.menu_items) {
@ -485,6 +568,8 @@ function addMacMenu(menu) {
}), indx);
indx++;
});
let runtimeMenu = getRuntimeMenu();
rootMenu.insert(runtimeMenu, indx++);
let separator_menu = new nw.MenuItem({ type: 'separator' });
rootMenu.insert(separator_menu, indx);
indx++;

View File

@ -135,66 +135,6 @@ class BrowserModule(PgAdminModule):
]
}
# We need 'Configure...' and 'View log...' Menu only in runtime.
if current_app.PGADMIN_RUNTIME:
full_screen_label = gettext('Enter Full Screen (F10)')
actual_size_label = gettext('Actual Size (Ctrl 0)')
zoom_in_label = gettext('Zoom In (Ctrl +)')
zoom_out_label = gettext('Zoom Out (Ctrl -)')
if sys.platform == 'darwin':
full_screen_label = gettext('Enter Full Screen (Cmd Ctrl F)')
actual_size_label = gettext('Actual Size (Cmd 0)')
zoom_in_label = gettext('Zoom In (Cmd +)')
zoom_out_label = gettext('Zoom Out (Cmd -)')
menus['file_items'].append(
MenuItem(
name='mnu_runtime',
module=PGADMIN_BROWSER,
label=gettext('Runtime'),
priority=999,
menu_items=[MenuItem(
name='mnu_configure_runtime',
module=PGADMIN_BROWSER,
callback='mnu_configure_runtime',
priority=0,
label=gettext('Configure...')
), MenuItem(
name='mnu_viewlog_runtime',
module=PGADMIN_BROWSER,
callback='mnu_viewlog_runtime',
priority=1,
label=gettext('View log...'),
below=True,
), MenuItem(
name='mnu_toggle_fullscreen_runtime',
module=PGADMIN_BROWSER,
callback='mnu_toggle_fullscreen_runtime',
priority=2,
label=full_screen_label
), MenuItem(
name='mnu_actual_size_runtime',
module=PGADMIN_BROWSER,
callback='mnu_actual_size_runtime',
priority=3,
label=actual_size_label
), MenuItem(
name='mnu_zoomin_runtime',
module=PGADMIN_BROWSER,
callback='mnu_zoomin_runtime',
priority=4,
label=zoom_in_label
), MenuItem(
name='mnu_zoomout_runtime',
module=PGADMIN_BROWSER,
callback='mnu_zoomout_runtime',
priority=5,
label=zoom_out_label
)]
)
)
return menus
def register_preferences(self):
@ -211,7 +151,7 @@ class BrowserModule(PgAdminModule):
'browser.set_master_password',
'browser.reset_master_password',
'browser.lock_layout',
'browser.signal_runtime']
]
def register(self, app, options):
"""
@ -907,30 +847,6 @@ def lock_layout():
return make_json_response()
@blueprint.route("/signal_runtime", endpoint="signal_runtime",
methods=["POST"])
def signal_runtime():
# If not runtime then no need to send signal
if current_app.PGADMIN_RUNTIME:
data = None
if hasattr(request.data, 'decode'):
data = request.data.decode('utf-8')
if data != '':
data = json.loads(data)
# Add Info Handler to current app just to send signal to runtime
tmp_handler = logging.StreamHandler()
tmp_handler.setLevel(logging.INFO)
current_app.logger.addHandler(tmp_handler)
# Send signal to runtime
current_app.logger.info(data['command'])
# Remove the temporary handler
current_app.logger.removeHandler(tmp_handler)
return make_json_response()
# Only register route if SECURITY_CHANGEABLE is set to True
# We can't access app context here so cannot
# use app.config['SECURITY_CHANGEABLE']

View File

@ -12,6 +12,8 @@ import Menu, { MenuItem } from '../../../static/js/helpers/Menu';
import getApiInstance from '../../../static/js/api_instance';
import url_for from 'sources/url_for';
import Notifier from '../../../static/js/helpers/Notifier';
import { getBrowser } from '../../../static/js/utils';
import { isMac } from '../../../static/js/keyboard_shortcuts';
const MAIN_MENUS = [
{ label: gettext('File'), name: 'file', id: 'mnu_file', index: 0, addSepratior: true },
@ -20,6 +22,33 @@ const MAIN_MENUS = [
{ label: gettext('Help'), name: 'help', id: 'mnu_help', index: 5, addSepratior: false }
];
let { name: browser } = getBrowser();
if (browser == 'Nwjs') {
let controlKey = isMac() ? 'cmd' : 'ctrl';
let fullScreenKey = isMac() ? 'F' : 'F10';
const RUNTIME_MENUS_OPTIONS = {
runtime : {
label: gettext('Runtime'),
name: 'runtime',
priority: 999,
submenus: {
configure: { label: gettext('Configure...'), name: 'configure', priority: 0, enable: true},
view_log: { label: gettext('View log...'), name: 'view_log', priority: 1, enable: true},
enter_full_screen: { label: gettext('Enter Full Screen'), name: 'enter_full_screen', enable: true, priority: 2, key: fullScreenKey, modifiers: isMac() ?`${controlKey}+ctrl` : controlKey},
actual_size: { label: gettext('Actual Size'), name: 'actual_size', priority: 3, enable: true, key: '0', modifiers: controlKey},
zoom_in: { label: gettext('Zoom In'), name: 'zoom_in', priority: 4, enable: true, key: '+', modifiers: controlKey},
zoom_out: { label: gettext('Zoom Out'), name: 'zoom_out', enable: true, priority: 5, key: '-', modifiers: controlKey},
}
}
};
pgAdmin.Browser.RUNTIME_MENUS_OPTIONS = RUNTIME_MENUS_OPTIONS;
}
export default class MainMenuFactory {
static createMainMenus() {
pgAdmin.Browser.MainMenus = [];

View File

@ -25,7 +25,7 @@ define('pgadmin.browser', [
'pgadmin.browser.utils', 'wcdocker', 'jquery.contextmenu',
'pgadmin.browser.preferences', 'pgadmin.browser.messages',
'pgadmin.browser.panel', 'pgadmin.browser.layout',
'pgadmin.browser.runtime', 'pgadmin.browser.error', 'pgadmin.browser.frame',
'pgadmin.browser.error', 'pgadmin.browser.frame',
'pgadmin.browser.node', 'pgadmin.browser.collection', 'pgadmin.browser.activity',
'sources/codemirror/addon/fold/pgadmin-sqlfoldcode',
'pgadmin.browser.keyboard', 'sources/tree/pgadmin_tree_save_state'

View File

@ -1,64 +0,0 @@
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import pgAdmin from 'sources/pgadmin';
import url_for from 'sources/url_for';
import $ from 'jquery';
import gettext from 'sources/gettext';
import Notify from '../../../static/js/helpers/Notifier';
const pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {};
_.extend(pgBrowser, {
// This function is used to send signal to runtime.
send_signal_to_runtime: function(cmd_string) {
$.ajax({
url: url_for('browser.signal_runtime'),
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({
'command': cmd_string,
}),
}).fail(function(xhr, error) {
Notify.pgNotifier(error, xhr, gettext('Failed to send signal to runtime.'));
});
},
// This function is callback function when 'Configure...' menu is clicked.
mnu_configure_runtime: function() {
this.send_signal_to_runtime('Runtime Open Configuration');
},
// This function is callback function when 'View log...' menu is clicked.
mnu_viewlog_runtime: function() {
this.send_signal_to_runtime('Runtime Open View Log');
},
// This function is callback function when 'Enter Full Screen' menu is clicked.
mnu_toggle_fullscreen_runtime: function() {
this.send_signal_to_runtime('Runtime Toggle Full Screen');
},
// This function is callback function when 'Actual Size' menu is clicked.
mnu_actual_size_runtime: function() {
this.send_signal_to_runtime('Runtime Actual Size');
},
// This function is callback function when 'Zoom In' menu is clicked.
mnu_zoomin_runtime: function() {
this.send_signal_to_runtime('Runtime Zoom In');
},
// This function is callback function when 'Zoom Out' menu is clicked.
mnu_zoomout_runtime: function() {
this.send_signal_to_runtime('Runtime Zoom Out');
}
});
export {pgBrowser};

View File

@ -110,7 +110,7 @@ export class MenuItem {
let menu_opts = [
'name', 'label', 'priority', 'module', 'callback', 'data', 'enable',
'category', 'target', 'url', 'node',
'checked', 'below', 'menu_items', 'is_checkbox', 'action', 'applies', 'is_native_only', 'type'
'checked', 'below', 'menu_items', 'is_checkbox', 'action', 'applies', 'is_native_only', 'type',
];
let defaults = {
url: '#',

View File

@ -696,7 +696,7 @@ function openWindow(toolForm, title) {
let pgBrowser = window.pgAdmin.Browser;
// Send the signal to runtime, so that proper zoom level will be set.
setTimeout(function() {
pgBrowser.send_signal_to_runtime('Runtime new window opened');
pgBrowser.Events.trigger('pgadmin:nw-set-new-window-open-size');
}, 500);
} else {
return false;

View File

@ -400,7 +400,7 @@ export default class DebuggerModule {
window.open(url, '_blank');
// Send the signal to runtime, so that proper zoom level will be set.
setTimeout(function () {
self.pgBrowser.send_signal_to_runtime('Runtime new window opened');
self.pgBrowser.Events.trigger('pgadmin:nw-set-new-window-open-size');
}, 500);
} else {
self.pgBrowser.Events.once(
@ -582,7 +582,7 @@ export default class DebuggerModule {
window.open(url, '_blank');
// Send the signal to runtime, so that proper zoom level will be set.
setTimeout(function () {
self.pgBrowser.send_signal_to_runtime('Runtime new window opened');
self.pgBrowser.Browser.Events.trigger('pgadmin:nw-set-new-window-open-size');
}, 500);
} else {
self.pgBrowser.Events.once(

View File

@ -722,7 +722,7 @@ export default function DebuggerArgumentComponent({ debuggerInfo, restartDebug,
window.open(url, '_blank');
// Send the signal to runtime, so that proper zoom level will be set.
setTimeout(function () {
pgAdmin.Browser.send_signal_to_runtime('Runtime new window opened');
pgAdmin.Browser.Events.trigger('pgadmin:nw-set-new-window-open-size');
}, 500);
} else {
pgAdmin.Browser.Events.once(

View File

@ -120,7 +120,7 @@ export default class SchemaDiff {
window.open(baseUrl, '_blank');
// Send the signal to runtime, so that proper zoom level will be set.
setTimeout(function () {
this.pgBrowser.send_signal_to_runtime('Runtime new window opened');
self.pgBrowser.Events.trigger('pgadmin:nw-set-new-window-open-size');
}, 500);
} else {
this.pgBrowser.Events.once(

View File

@ -128,7 +128,6 @@ let webpackShimConfig = {
'pgadmin.browser.frame': path.join(__dirname, './pgadmin/browser/static/js/frame'),
'pgadmin.browser.keyboard': path.join(__dirname, './pgadmin/browser/static/js/keyboard'),
'pgadmin.browser.layout': path.join(__dirname, './pgadmin/browser/static/js/layout'),
'pgadmin.browser.runtime': path.join(__dirname, './pgadmin/browser/static/js/runtime'),
'pgadmin.browser.preferences': path.join(__dirname, './pgadmin/browser/static/js/preferences'),
'pgadmin.browser.activity': path.join(__dirname, './pgadmin/browser/static/js/activity'),
'pgadmin.browser.messages': '/browser/js/messages',