Skip to content

Commit

Permalink
fix: file input element - missing path property (#3757)
Browse files Browse the repository at this point in the history
  • Loading branch information
lohxt1 authored Jan 8, 2025
1 parent c5de234 commit f5ff40a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ const ClientCertSettings = ({ root, clientCertConfig, onUpdate, onRemove }) => {
});

const getFile = (e) => {
if (e.files?.[0]?.path) {
const filePath = window?.ipcRenderer?.getFilePath(e?.files?.[0]);
if (filePath) {
let relativePath;
if (isWindowsOS()) {
relativePath = slash(path.win32.relative(root, e.files[0].path));
relativePath = slash(path.win32.relative(root, filePath));
} else {
relativePath = path.posix.relative(root, e.files[0].path);
relativePath = path.posix.relative(root, filePath);
}
formik.setFieldValue(e.name, relativePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ const General = ({ close }) => {
};

const addCaCertificate = (e) => {
formik.setFieldValue('customCaCertificate.filePath', e.target.files[0]?.path);
const filePath = window?.ipcRenderer?.getFilePath(e?.target?.files?.[0]);
if (filePath) {
formik.setFieldValue('customCaCertificate.filePath', filePath);
}
};

const deleteCaCertificate = () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/bruno-electron/src/preload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ipcRenderer, contextBridge } = require('electron');
const { ipcRenderer, contextBridge, webUtils } = require('electron');

contextBridge.exposeInMainWorld('ipcRenderer', {
invoke: (channel, ...args) => ipcRenderer.invoke(channel, ...args),
Expand All @@ -10,5 +10,9 @@ contextBridge.exposeInMainWorld('ipcRenderer', {
return () => {
ipcRenderer.removeListener(channel, subscription);
};
},
getFilePath (file) {
const path = webUtils.getPathForFile(file)
return path;
}
});

0 comments on commit f5ff40a

Please sign in to comment.