Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions lib/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand All @@ -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);
Expand All @@ -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));
}
Expand Down