fix: file input element - missing path property (#3757)

This commit is contained in:
lohit
2025-01-08 17:01:57 +05:30
committed by GitHub
parent c5de2343e9
commit f5ff40abfa
3 changed files with 13 additions and 5 deletions

View File

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

View File

@@ -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 = () => {

View File

@@ -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),
@@ -10,5 +10,9 @@ contextBridge.exposeInMainWorld('ipcRenderer', {
return () => {
ipcRenderer.removeListener(channel, subscription);
};
},
getFilePath (file) {
const path = webUtils.getPathForFile(file)
return path;
}
});