File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed
Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 11import { dialog , ipcMain , shell } from "electron" ;
22import fileIndex from "./index" ;
33
4- ipcMain . handle ( "file:openFile" , async ( _ , options ) : Promise < string | null > => {
4+ ipcMain . handle ( "file:openFile" , async (
5+ event ,
6+ options : {
7+ filters ?: {
8+ name : string ;
9+ extensions : string [ ] ;
10+ } [ ] ,
11+ properties ?: ( "multiSelections" | "openFile" ) [ ]
12+ } = { } ) : Promise < string | string [ ] | null > => {
13+ options = Object . assign ( {
14+ filters : [ ] ,
15+ properties : [ ] ,
16+ } , options ) ;
17+ if ( ! options . properties . includes ( "openFile" ) ) {
18+ options . properties . push ( "openFile" ) ;
19+ }
520 const res = await dialog
621 . showOpenDialog ( {
7- properties : [ "openFile" ] ,
822 ...options ,
923 } )
1024 . catch ( e => {
1125 } ) ;
1226 if ( ! res || res . canceled ) {
1327 return null ;
1428 }
29+ if ( res . filePaths . length > 1 ) {
30+ return res . filePaths ;
31+ }
1532 return res . filePaths ?. [ 0 ] || null ;
1633} ) ;
1734
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ export const doOpenFile = async (
4848 } ]
4949 }
5050 if ( options . multiple ) {
51- opt . properties = [ 'openFile' , ' multiSelections'] ;
51+ opt . properties = [ 'multiSelections' ] ;
5252 }
5353 const result = await window . $mapi . file . openFile ( opt ) ;
5454 if ( result ) {
Original file line number Diff line number Diff line change @@ -205,7 +205,13 @@ type DefsMapi = {
205205 progress ?: ( percent : number , total : number ) => void ;
206206 }
207207 ) => Promise < string > ;
208- openFile : ( options : { } = { } ) => Promise < string | null > ;
208+ openFile : ( options : {
209+ filters ?: {
210+ name : string ;
211+ extensions : string [ ] ;
212+ } [ ] ,
213+ properties ?: ( "multiSelections" ) [ ]
214+ } = { } ) => Promise < string | null > ;
209215 openDirectory : ( options : { } = { } ) => Promise < string | null > ;
210216 openSave : ( options : { } = { } ) => Promise < string | null > ;
211217 ext : ( path : string ) => Promise < string > ;
You can’t perform that action at this time.
0 commit comments