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
11 changed files with 157 additions and 192 deletions

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};