Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I take persistent permissions in electron app?

I am creating an electron app where I need to scan and update files which need root permission. I know I can run such commands using sudo.exec() in that way:

sudo.exec ("rm /private/var/log/fsck_hfs.log", options, (e, stdout, stderr) => {});

And even I can put multiple commands in a script and execute them with single sudo.exec(). In my case, commands needs to be executed at different point of time and I cannot execute them with a single script. It is annoying for user to grant permissions again and again.

I tried to do it another way (to run a piece of code where everything that require root permission can be executed). For that, I posted another question here. But it seems that it is not possible.

Now I want a way to get permission once when use install app (as most of the apps does after user install them) and be able to use throughout the app sudo.exec() or some other method to execute commands (preferably also the code fs.readdir, etc) that require root permission.

like image 573
Nargis Avatar asked Feb 12 '19 14:02

Nargis


People also ask

How do you protect the electron source code?

While Electron can obfuscate code, performance is reduced. The V8 JavaScript engine as not designed to hide source code, an application will need to be written in C++ and make a native Node module to protect source code.

What is Nodeintegration electron?

Electron node integration refers to the ability of accessing Node. js resources from within the “renderer” thread (the UI). It is enabled by default in Quasar CLI, although Electron is encouraging developers to turn it off as a security precaution.

Does electron use https?

By default, Electron will not allow websites loaded over HTTPS to load and execute scripts, CSS, or plugins from insecure sources ( HTTP ). Setting the property allowRunningInsecureContent to true disables that protection.


1 Answers

You need to run the applicaton with administrator privilege. If you are using electron builder to build the app, use the requestedExecutionLevel value as "requireAdministrator"

https://www.electron.build/configuration/win

like image 122
Sharvin K Avatar answered Oct 06 '22 00:10

Sharvin K