@@ -134,12 +134,6 @@ const disabledDescriptionDarkStyles = css({
134134
135135type FileInputVariant = 'default' | 'small' | 'vertical' ;
136136
137- // https://www.electronjs.org/docs/latest/api/file-object
138- type FileWithPath = File & {
139- /** Electron-specific property that contains an absolute path to the file */
140- path : string ;
141- } ;
142-
143137// Matches Electron's file dialog options.
144138export type ElectronFileDialogOptions = {
145139 title ?: string ;
@@ -292,6 +286,20 @@ export function createElectronFileInputBackend<ElectronWindow>(
292286 } ;
293287}
294288
289+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
290+ let _electron : typeof import ( 'electron' ) | undefined | null ;
291+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
292+ function getElectronWebUtils ( ) : typeof import ( 'electron' ) . webUtils | undefined {
293+ if ( _electron === undefined ) {
294+ try {
295+ _electron = require ( 'electron' ) ;
296+ } catch {
297+ _electron = null ;
298+ }
299+ }
300+ return _electron ?. webUtils ;
301+ }
302+
295303function FileInput ( {
296304 autoOpen = false ,
297305 id,
@@ -357,7 +365,9 @@ function FileInput({
357365 ( evt : React . ChangeEvent < HTMLInputElement > ) => {
358366 const fileList = Array . from ( evt . currentTarget . files ?? [ ] ) ;
359367 const files = fileList . map ( ( file ) => {
360- return ( file as FileWithPath ) . path ;
368+ // https://github.com/electron/electron/blob/83d704009687956fb4b69cb13ab03664d7950118/docs/breaking-changes.md#removed-filepath
369+ // eslint-disable-next-line @typescript-eslint/no-var-requires
370+ return getElectronWebUtils ( ) ?. getPathForFile ( file ) ;
361371 } ) ;
362372 onChange ( files ) ;
363373 } ,
0 commit comments