@@ -2,10 +2,12 @@ import * as React from 'react';
22import { useHotkeys as rawUseHotkeys } from "react-hotkeys-hook" ;
33import { action , observable } from 'mobx' ;
44
5- import { desktopVersion } from '../services/service-versions' ;
65import { getDeferred , delay } from './promise' ;
76import { logError } from '../errors' ;
87
8+ import { desktopVersion } from '../services/service-versions' ;
9+ import { DesktopApi } from '../services/desktop-api' ;
10+
911export function isReactElement ( node : any ) : node is React . ReactElement {
1012 return node && ! ! node . $$typeof ;
1113}
@@ -128,9 +130,22 @@ export function uploadFile(
128130 const file = fileInput . files [ 0 ] ;
129131
130132 if ( type === 'path' ) {
131- // file.path is an Electron-only extra property:
132- // https://github.com/electron/electron/blob/master/docs/api/file-object.md
133- result . resolve ( ( file as unknown as { path : string } ) . path ) ;
133+ const fileWithPath = ( file as unknown as { path ?: string } ) ;
134+ if ( DesktopApi . getPathForFile ) {
135+ // In the latest desktop app, we can request the file path via the desktop API:
136+ return result . resolve ( DesktopApi . getPathForFile ( file ) ) ;
137+ } else if ( fileWithPath . path ) {
138+ // On older Electron, we can access the path on the File object directly:
139+ return result . resolve ( fileWithPath . path ) ;
140+ } else {
141+ // In the middle ground, we released a desktop version that includes an Electron update
142+ // with disables file.path, with no fallback. Anybody using this needs to update.
143+ window . alert (
144+ "File path access is not available due to a temporary issue in this release.\n\n" +
145+ "Please update to the latest HTTP Toolkit from httptoolkit.com"
146+ ) ;
147+ return result . resolve ( null ) ;
148+ }
134149 } else {
135150 const fileReader = new FileReader ( ) ;
136151
0 commit comments