Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Avoid multiple prompts when the user cancels
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Aug 22, 2017
1 parent 2d836bc commit cf0bab5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 6 additions & 1 deletion index.js
Expand Up @@ -13,7 +13,12 @@ switch (process.platform) {
let authopen;

// Prompt for credentials synchronously to avoid creating multiple simultaneous prompts.
binding.spawnAsAdmin('/bin/echo', [], module.exports.testMode, () => {})
if (!binding.spawnAsAdmin('/bin/echo', [], module.exports.testMode, () => {})) {
const result = new EventEmitter()
result.write = result.end = function () {}
process.nextTick(() => result.emit('error', new Error('Failed to obtain credentials')))
return result
}

if (module.exports.testMode) {
authopen = spawn('/bin/dd', ['of=' + filePath])
Expand Down
9 changes: 6 additions & 3 deletions src/main.cc
Expand Up @@ -72,9 +72,12 @@ void SpawnAsAdmin(const Nan::FunctionCallbackInfo<Value>& info) {
}

void *child_process = StartChildProcess(command, args, test_mode);
if (!child_process) return;

Nan::AsyncQueueWorker(new Worker(new Nan::Callback(info[3].As<Function>()), child_process, test_mode));
if (!child_process) {
info.GetReturnValue().Set(Nan::False());
} else {
Nan::AsyncQueueWorker(new Worker(new Nan::Callback(info[3].As<Function>()), child_process, test_mode));
info.GetReturnValue().Set(Nan::True());
}
}

void Init(Handle<Object> exports) {
Expand Down

0 comments on commit cf0bab5

Please sign in to comment.