Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Electron flash data warning #426

Merged
merged 1 commit into from
Jun 18, 2018
Merged
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
71 changes: 7 additions & 64 deletions src/cmd/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CloudCommand {
});
}

flashDevice(deviceId, files, { target, yes }) {
flashDevice(deviceId, files, { target }) {
return Promise.resolve().then(() => {
if (files.length === 0) {
// default to current directory
Expand All @@ -136,7 +136,7 @@ class CloudCommand {
api.ensureToken();

if (!fs.existsSync(files[0])) {
return this._flashKnownApp({ api, deviceId, filePath: files[0], yes });
return this._flashKnownApp({ api, deviceId, filePath: files[0] });
}

const version = target === 'latest' ? null : target;
Expand All @@ -162,7 +162,7 @@ class CloudCommand {
}
}

return this._doFlash({ api, deviceId, fileMapping, version, yes });
return this._doFlash({ api, deviceId, fileMapping, version });
});
}).catch((err) => {
if (VError.hasCauseWithName(err, EarlyReturnError.name)) {
Expand All @@ -174,66 +174,9 @@ class CloudCommand {
});
}

_promptForOta(api, attrs, fileMapping, targetVersion) {
const newFileMapping = {
basePath: fileMapping.basePath,
map: {}
};
_doFlash({ api, deviceId, fileMapping, targetVersion }) {
return Promise.resolve().then(() => {
const sourceExtensions = ['.h', '.cpp', '.ino', '.c'];
const list = Object.keys(fileMapping.map);
const isSourcey = _.some(list, (file) => {
return sourceExtensions.indexOf(path.extname(file)) >= 0;
});
if (!isSourcey) {
const binFile = fileMapping.map[list[0]];
newFileMapping.map[list[0]] = binFile;
return binFile;
}

const filename = temp.path({ suffix: '.bin' });
return this._compileAndDownload(api, fileMapping, attrs.platform_id, filename, targetVersion).then(() => {
newFileMapping.map['firmware.bin'] = filename;
return filename;
});
}).then((file) => {
return whenNode.lift(fs.stat)(file);
}).then((stats) => {
const dataUsage = utilities.cellularOtaUsage(stats.size);

console.log();
console.log(alert, 'Flashing firmware Over The Air (OTA) uses cellular data, which may cause you to incur usage charges.');
console.log(alert, 'This flash is estimated to use at least ' + chalk.bold(dataUsage + ' MB') + ', but may use more depending on network conditions.');
console.log();
console.log(alert, 'Please type ' + chalk.bold(dataUsage) + ' below to confirm you wish to proceed with the OTA flash.');
console.log(alert, 'Any other input will cancel.');

return prompt([{
name: 'confirmota',
type: 'input',
message: 'Confirm the amount of data usage in MB:'
}]).then((ans) => {
if (ans.confirmota !== dataUsage) {
throw new EarlyReturnError('User cancelled');
}
return newFileMapping;
});
});
}

_doFlash({ api, deviceId, fileMapping, targetVersion, yes }) {
let isCellular;
return api.getAttributes(deviceId).then((attrs) => {
isCellular = attrs.cellular;
if (!isCellular) {
return fileMapping;
} else if (yes) {
console.log('! Skipping Bandwidth Prompt !');
return fileMapping;
}
return this._promptForOta(api, attrs, fileMapping, targetVersion);
}).then((flashFiles) => {
return api.flashDevice(deviceId, flashFiles, targetVersion);
return api.flashDevice(deviceId, fileMapping, targetVersion);
}).then((resp) => {
if (resp.status || resp.message) {
console.log('Flash device OK: ', resp.status || resp.message);
Expand All @@ -248,7 +191,7 @@ class CloudCommand {
});
}

_flashKnownApp({ api, deviceId, filePath, yes }) {
_flashKnownApp({ api, deviceId, filePath }) {
if (!settings.knownApps[filePath]) {
throw new VError(`I couldn't find that file: ${filePath}`);
}
Expand Down Expand Up @@ -288,7 +231,7 @@ class CloudCommand {
return { map: { binary: binary } };
});
}).then((fileMapping) => {
return this._doFlash({ api, deviceId, fileMapping, yes });
return this._doFlash({ api, deviceId, fileMapping });
});
}

Expand Down