Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions runtime/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//////////////////////////////////////////////////////////////
import globals from 'globals';
import js from '@eslint/js';
import unusedImports from 'eslint-plugin-unused-imports';

export default [
js.configs.recommended,
Expand All @@ -34,6 +35,9 @@ export default [
'platform': 'readonly',
},
},
'plugins': {
'unused-imports': unusedImports,
},
'rules': {
'indent': [
'error',
Expand All @@ -55,6 +59,17 @@ export default [
'no-console': ['error', { allow: ['warn', 'error'] }],
// We need to exclude below for RegEx case
'no-useless-escape': 0,
'no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
'vars': 'all',
'varsIgnorePattern': '^_',
'args': 'after-used',
'argsIgnorePattern': '^_',
},
],
},
},
];
3 changes: 1 addition & 2 deletions runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"dependencies": {
"axios": "^1.9.0",
"electron-context-menu": "^4.0.5",
"electron-dl": "^4.0.0",
"electron-store": "^10.0.0"
"electron-store": "^10.0.1"
}
}
33 changes: 7 additions & 26 deletions runtime/src/js/pgadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { setupMenu } from './menu.js';
import contextMenu from 'electron-context-menu';
import { CancelError, download } from 'electron-dl';
import { setupProgressInfo } from './progress.js';

const configStore = new Store({
defaults: {
Expand All @@ -35,6 +35,7 @@ let configureWindow = null,
viewLogWindow = null;

let serverPort = 5050;
let baseUrl = `http://127.0.0.1:${serverPort}`;
let appStartTime = (new Date()).getTime();
const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -153,28 +154,6 @@ function reloadApp() {
currWin.webContents.reload();
}

async function desktopFileDownload(payload) {
const currWin = BrowserWindow.getFocusedWindow();
try {
await download(currWin, payload.downloadUrl, {
filename: payload.fileName,
saveAs: payload.prompt_for_download_location,
onProgress: (progress) => {
currWin.webContents.send('download-progress', progress);
},
onCompleted: (item) => {
currWin.webContents.send('download-complete', item);
if (payload.automatically_open_downloaded_file)
shell.openPath(item.path);
},
});
} catch (error) {
if (!(error instanceof CancelError)) {
misc.writeServerLog(error);
}
}
}

// This functions is used to start the pgAdmin4 server by spawning a
// separate process.
function startDesktopMode() {
Expand All @@ -192,8 +171,9 @@ function startDesktopMode() {
process.env.PGADMIN_SERVER_MODE = 'OFF';

// Start Page URL
startPageUrl = 'http://127.0.0.1:' + serverPort + '/?key=' + UUID;
serverCheckUrl = 'http://127.0.0.1:' + serverPort + '/misc/ping?key=' + UUID;
baseUrl = `http://127.0.0.1:${serverPort}`;
startPageUrl = baseUrl + '/?key=' + UUID;
serverCheckUrl = baseUrl + '/misc/ping?key=' + UUID;

// Write Python Path, pgAdmin file path and command in log file.
misc.writeServerLog('pgAdmin Runtime Environment');
Expand Down Expand Up @@ -356,6 +336,8 @@ function launchPgAdminWindow() {
'reloadApp': reloadApp,
});

setupProgressInfo(pgAdminMainScreen);

pgAdminMainScreen.loadURL(startPageUrl);

const bounds = configStore.get('bounds');
Expand Down Expand Up @@ -429,7 +411,6 @@ ipcMain.on('log', (text) => ()=>{
misc.writeServerLog(text);
});
ipcMain.on('reloadApp', reloadApp);
ipcMain.on('onFileDownload', (_, payload) => desktopFileDownload(payload));
ipcMain.handle('checkPortAvailable', async (_e, fixedPort)=>{
try {
await misc.getAvailablePort(fixedPort);
Expand Down
15 changes: 14 additions & 1 deletion runtime/src/js/pgadmin_preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,18 @@ contextBridge.exposeInMainWorld('electronUI', {
showSaveDialog: (options) => ipcRenderer.invoke('showSaveDialog', options),
log: (text)=> ipcRenderer.send('log', text),
reloadApp: ()=>{ipcRenderer.send('reloadApp');},
onFileDownload: (payload) => ipcRenderer.send('onFileDownload', payload),

// progress bar
setBadge: (count) => {
ipcRenderer.send('set-badge', count);
},
clearBadge: () => {
ipcRenderer.send('clear-badge');
},
setProgress: (value) => {
ipcRenderer.send('set-progress', value);
},
clearProgress: () => {
ipcRenderer.send('clear-progress');
},
});
38 changes: 38 additions & 0 deletions runtime/src/js/progress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { app, ipcMain } from 'electron';

export function setupProgressInfo(mainWindow) {
ipcMain.on('set-badge', (event, count) => {
const badgeCount = parseInt(count, 10);
if (!isNaN(badgeCount)) {
// Set the application badge count (works on macOS and Linux)
app.setBadgeCount(badgeCount);
}
});

// Listen for 'clear-badge' message from renderer process
ipcMain.on('clear-badge', () => {
// Setting count to 0 removes the badge
app.setBadgeCount(0);
});

// Listen for 'set-progress' message from renderer process
ipcMain.on('set-progress', (event, progress) => {
const progressValue = parseFloat(progress);
if (mainWindow && !isNaN(progressValue) && progressValue >= 0 && progressValue <= 1) {
// Set the progress bar on the taskbar icon (works on Windows, macOS, Unity)
// Value should be between 0 and 1.
// Use -1 to enter indeterminate mode (or remove the bar).
mainWindow.setProgressBar(progressValue);
} else if (mainWindow && progress === -1) {
mainWindow.setProgressBar(-1); // Clear or set to indeterminate
}
});

// Listen for 'clear-progress' message from renderer process
ipcMain.on('clear-progress', () => {
if (mainWindow) {
// Setting progress to -1 removes the progress bar
mainWindow.setProgressBar(-1);
}
});
}
19 changes: 16 additions & 3 deletions runtime/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ __metadata:
languageName: node
linkType: hard

"electron-store@npm:^10.0.0":
"electron-store@npm:^10.0.1":
version: 10.0.1
resolution: "electron-store@npm:10.0.1"
dependencies:
Expand Down Expand Up @@ -881,6 +881,19 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-unused-imports@npm:^4.1.4":
version: 4.1.4
resolution: "eslint-plugin-unused-imports@npm:4.1.4"
peerDependencies:
"@typescript-eslint/eslint-plugin": ^8.0.0-0 || ^7.0.0 || ^6.0.0 || ^5.0.0
eslint: ^9.0.0 || ^8.0.0
peerDependenciesMeta:
"@typescript-eslint/eslint-plugin":
optional: true
checksum: 1f4ce3e3972699345513840f3af1b783033dbc3a3e85b62ce12b3f6a89fd8c92afe46d0c00af40bacb14465445983ba0ccc326a6fd5132553061fb0e47bcba19
languageName: node
linkType: hard

"eslint-scope@npm:^8.3.0":
version: 8.3.0
resolution: "eslint-scope@npm:8.3.0"
Expand Down Expand Up @@ -1886,9 +1899,9 @@ __metadata:
axios: ^1.9.0
electron: 36.2.0
electron-context-menu: ^4.0.5
electron-dl: ^4.0.0
electron-store: ^10.0.0
electron-store: ^10.0.1
eslint: ^9.26.0
eslint-plugin-unused-imports: ^4.1.4
languageName: unknown
linkType: soft

Expand Down
4 changes: 2 additions & 2 deletions web/pgadmin/dashboard/static/js/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Replication from './Replication';
import { getExpandCell } from '../../../static/js/components/PgReactTableStyled';
import CodeMirror from '../../../static/js/components/ReactCodeMirror';
import GetAppRoundedIcon from '@mui/icons-material/GetAppRounded';
import { downloadFile } from '../../../static/js/utils';
import { downloadTextData } from '../../../static/js/download';
import RefreshButton from './components/RefreshButtons';

function parseData(data) {
Expand Down Expand Up @@ -451,7 +451,7 @@ function Dashboard({
let fileName = 'data-' + new Date().getTime() + extension;

try {
downloadFile(respData, fileName, `text/${type}`);
downloadTextData(respData, fileName, `text/${type}`);
} catch {
setSsMsg(gettext('Failed to download the logs.'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Uploader from './Uploader';
import GridView from './GridView';
import convert from 'convert-units';
import PropTypes from 'prop-types';
import { downloadBlob } from '../../../../../static/js/utils';
import { downloadBlob } from '../../../../../static/js/download';
import ErrorBoundary from '../../../../../static/js/helpers/ErrorBoundary';
import { MY_STORAGE } from './FileManagerConstants';
import _ from 'lodash';
Expand Down
4 changes: 2 additions & 2 deletions web/pgadmin/static/js/Explain/svg_download.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//////////////////////////////////////////////////////////////
import getApiInstance from '../api_instance';
import { downloadFile } from '../utils';
import { downloadTextData } from '../download';

function convertImageURLtoDataURI(api, image) {
return new Promise(function(resolve, reject) {
Expand Down Expand Up @@ -43,6 +43,6 @@ export function downloadSvg(svg, svgName) {
}

Promise.all(image_promises).then(function() {
downloadFile(svgElement.outerHTML, svgName, 'image/svg+xml');
downloadTextData(svgElement.outerHTML, svgName, 'image/svg+xml');
});
}
8 changes: 6 additions & 2 deletions web/pgadmin/static/js/api_instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ export function parseApiError(error, withData=false) {
}

export function callFetch(url, options, headers={}) {
return fetch(url, {
return fetch(url, getFetchOptions(options, headers));
}

export function getFetchOptions(options, headers={}) {
return {
...options,
headers: {
'Content-type': 'application/json',
[pgAdmin.csrf_token_header]: pgAdmin.csrf_token,
...headers,
}
});
};
}
Loading