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

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