Coder Social home page Coder Social logo

Comments (5)

jorangreef avatar jorangreef commented on July 22, 2024

Thanks, I tried your example on OS X 10.10.4 and it worked fine.

Could the password prompt possibly be hidden by other windows?

Once you enter your password the first time using the prompt, or via a sudo command in the console, your user will have sudo privileges for a few minutes, which is why the programmatic version would not require a password prompt the second time.

It is designed to only prompt if sudo privileges are necessary, so it may look like it is silently failing by not showing a prompt each time, but it might actually be working fine.

Are you removing the /etc/test.txt file each time before you test, and what is the title of your process?

from sudo-prompt.

erikmellum avatar erikmellum commented on July 22, 2024

Thanks Joran for your response it is much appreciated. I checked and didn't locate the password prompt behind any other windows. My process.title is "/Users/guest/Desktop/yeti-launch/node_modules/electron-prebuilt/dist/Electron.app/Contents/Frameworks/Electron Helper.app/Contents/MacOS/Electron Helper"

My process was to launch the application (with no sudo timestamp). Before I attempted the sudo command, I checked in an external terminal that /etc/test.txt did not exist using stat '/etc/test.txt'. After executing the sudo code, the prompt for sudo did not pop up, and the file did not exist using the same check in the external terminal stat '/etc/test.txt'. However, when I have a sudo timestamp available (by running anything that requires sudo in the external terminal, and entering the password), sudo execute will be able to create the /etc/test.txt file (albeit with no dialog prompt). I have been careful to ensure that the file does not already exist in doing these tests. It appears to be having some sort of issue pulling up the dialog box.

Hope that helps, I will continue testing for now!

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

Could you try and run sudo.setName('test') before you call sudo.exec?

If you could also please let me know the following:

  1. What does os.tmpdir() return when called from your Electron app and is that path writable by your user?
  2. What does process.env['USER'] contain when checked from your Electron app?
  3. What do you get when running which osascript in the terminal?
  4. What version of OS X are you running?
  5. Are you sure that you are checking for errors when calling sudo.exec?

from sudo-prompt.

erikmellum avatar erikmellum commented on July 22, 2024

Running sudo.setName('test') fixed the issue. I told myself that the title couldn't possibly be the problem in my debugging, which was quite shortsighted. I should have tested that myself. I will be testing it on another computer tomorrow to verify that it is completely solved. I suspect that it is, and I will close the issue for now. Thanks for your assistance. The package is quite useful in my electron application.

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

That's great to hear.

sudo-prompt works without native dependencies by creating a copy of the osascript binary using the title of your process as the binary name. It does this so that the password prompt shows as being from your application.

I think the reason your process.title didn't work is because it contained slashes which are not valid in a pathname. sudo-prompt should definitely have given you an error in the callback if your process title was invalid:

[Error: Please use sudo.setName(string) to set your app name (process.title contains invalid characters).]

from sudo-prompt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.