diff --git a/lib/launch.js b/lib/launch.js index b81de65..fbf72a5 100644 --- a/lib/launch.js +++ b/lib/launch.js @@ -501,12 +501,19 @@ const appdata = commonTools.appdata, function _findSimulatorVersion(fileList, next) { log.silly("launcher#launchSimulator#_findSimulatorVersion():", "fileList:", fileList); let versionList = []; + const simulatorExecutablePathByVersion = {}; + for (let i = 0; i < fileList.length; i++) { if (fileList[i].indexOf(options.simulatorPrefix) === 0) { const filePath = path.resolve(options.simulatorDir, fileList[i]); + const ext = path.extname(filePath).toLowerCase(); + if (fs.existsSync(filePath) - && [".exe", ".appimage", ".app"].includes(path.extname(filePath))) { - versionList.push(path.parse(filePath).name.slice(options.simulatorPrefix.length + 1)); + && [".exe", ".appimage", ".app"].includes(ext)) { + const version = path.parse(filePath).name.slice(options.simulatorPrefix.length + 1); + + versionList.push(version); + simulatorExecutablePathByVersion[version] = filePath; } } } @@ -518,6 +525,7 @@ const appdata = commonTools.appdata, // sort version descending order versionList = versionList.sort(semver.rcompare); options.simulatorVersion = versionList[0]; + options.simulatorExecutablePath = simulatorExecutablePathByVersion[options.simulatorVersion]; next(); } catch(err) { next(err, null); @@ -526,21 +534,12 @@ const appdata = commonTools.appdata, } function _launchSimulator(next) { - let ext = ''; - switch (process.platform) { - case 'win32': - ext = 'exe'; - break; - case 'linux': - ext = 'appimage'; - break; - case 'darwin': - ext = 'app'; - break; - default: + const simulatorPath = options.simulatorExecutablePath; + + if (!simulatorPath) { + return setImmediate(next, errHndl.getErrMsg('EMPTY_VALUE', "simulatorExecutablePath")); } - const simulatorName = `${options.simulatorPrefix}_${options.simulatorVersion}`, - simulatorPath = path.join(options.simulatorDir, `${simulatorName}.${ext}`); + if (!fs.existsSync(simulatorPath)) { return setImmediate(next, errHndl.getErrMsg('NOT_EXIST_PATH', simulatorPath)); }