88} from '@theia/core/electron-shared/electron' ;
99import { fork } from 'child_process' ;
1010import { AddressInfo } from 'net' ;
11- import { join , dirname , isAbsolute , resolve } from 'path' ;
11+ import { join , isAbsolute , resolve } from 'path' ;
1212import { promises as fs , Stats } from 'fs' ;
1313import { MaybePromise } from '@theia/core/lib/common/types' ;
1414import { ElectronSecurityToken } from '@theia/core/lib/electron-common/electron-token' ;
@@ -86,7 +86,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
8686 return this . launch ( {
8787 secondInstance : false ,
8888 argv : this . processArgv . getProcessArgvWithoutBin ( process . argv ) ,
89- cwd
89+ cwd,
9090 } ) ;
9191 }
9292
@@ -158,11 +158,11 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
158158 /**
159159 * The `path` argument is valid, if accessible and either pointing to a `.ino` file,
160160 * or it's a directory, and one of the files in the directory is an `.ino` file.
161- * The resolved filesystem path is pointing to the sketch folder to open in IDE2.
161+ *
162162 * If `undefined`, `path` was pointing to neither an accessible sketch file nor a sketch folder.
163163 *
164- * The sketch folder name and sketch file name can be different. This method is not that strict .
165- * The `path` must be an absolute path.
164+ * The sketch folder name and sketch file name can be different. This method is not sketch folder name compliant .
165+ * The `path` must be an absolute, resolved path.
166166 */
167167 private async isValidSketchPath ( path : string ) : Promise < string | undefined > {
168168 let stats : Stats | undefined = undefined ;
@@ -178,14 +178,16 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
178178 return undefined ;
179179 }
180180 if ( stats . isFile ( ) && path . endsWith ( '.ino' ) ) {
181- return dirname ( path ) ;
181+ return path ;
182182 }
183183 try {
184184 const entries = await fs . readdir ( path , { withFileTypes : true } ) ;
185- if (
186- entries . some ( ( entry ) => entry . isFile ( ) && entry . name . endsWith ( '.ino' ) )
187- ) {
188- return path ;
185+ const sketchFilename = entries
186+ . filter ( ( entry ) => entry . isFile ( ) && entry . name . endsWith ( '.ino' ) )
187+ . map ( ( { name } ) => name )
188+ . sort ( ( left , right ) => left . localeCompare ( right ) ) [ 0 ] ;
189+ if ( sketchFilename ) {
190+ return join ( path , sketchFilename ) ;
189191 }
190192 } catch ( err ) {
191193 throw err ;
0 commit comments