Skip to content

Commit

Permalink
Merge branch 'feature/sc-126222/update-the-particle-cli-executable-in…
Browse files Browse the repository at this point in the history
…-workbench' of github.com:particle-iot/particle-cli into feature/sc-126222/update-the-particle-cli-executable-in-workbench
  • Loading branch information
hugomontero committed May 8, 2024
2 parents 90737b0 + 1db5f11 commit b44db5e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
13 changes: 1 addition & 12 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"lodash": "^4.17.15",
"moment": "^2.24.0",
"node-wifiscanner2": "^1.2.1",
"openurl": "^1.1.1",
"particle-api-js": "^10.3.0",
"particle-commands": "^1.0.1",
"particle-library-manager": "^0.1.15",
Expand Down
53 changes: 53 additions & 0 deletions src/lib/openurl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copy of https://github.com/rauschma/openurl with additional error handling
const spawn = require('child_process').spawn;

let command;

switch(process.platform) {
case 'darwin':
command = 'open';
break;
case 'win32':
command = 'explorer.exe';
break;
case 'linux':
command = 'xdg-open';
break;
default:
throw new Error('Unsupported platform: ' + process.platform);
}

/**
* Error handling is deliberately minimal, as this function is to be easy to use for shell scripting
*
* @param url The URL to open
* @param callback A function with a single error argument. Optional.
*/

function open(url, callback) {
const child = spawn(command, [url]);
child.on('error', function (error) {
callback(error);
});
let errorText = "";
child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
errorText += data;
});
child.stderr.on('end', function () {
if (errorText.length > 0) {
const error = new Error(errorText);
if (callback) {
callback(error);
} else {
throw error;
}
} else if (callback) {
callback();
}
});
}

module.exports = {
open
};
6 changes: 4 additions & 2 deletions src/lib/sso.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const request = require('request');
const jose = require('jose');
const openurl = require('openurl');
const openurl = require('./openurl');
const settings = require('../../settings');
const WAIT_BETWEEN_REQUESTS = 5000;

Expand Down Expand Up @@ -78,7 +78,9 @@ const ssoLogin = async () => {
method: 'POST'
});

openurl.open(response.verification_uri_complete);
openurl.open(response.verification_uri_complete, () => {
// ignore errors opening the browser and let the user open the link manually
});

return { deviceCode: response.device_code, verificationUriComplete: response.verification_uri_complete };
};
Expand Down

0 comments on commit b44db5e

Please sign in to comment.