All Projects → automation-stack → Electron Sudo

automation-stack / Electron Sudo

Licence: mit
Electron subprocesses with administrative privileges, prompting the user with an OS dialog if necessary.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Electron Sudo

Gbt
Highly configurable prompt builder for Bash, ZSH and PowerShell written in Go.
Stars: ✭ 457 (+36.01%)
Mutual labels:  prompt, sudo
Sbp
Simple Bash Prompt (SBP) is a bash prompt, which strives to be simple. But it isn't. But it looks kind of nice. I think.
Stars: ✭ 273 (-18.75%)
Mutual labels:  prompt
git-commiter
📖✨ Allows you to commit following custom rules or conventions easily
Stars: ✭ 17 (-94.94%)
Mutual labels:  prompt
Razor.SweetAlert2
A Razor class library for interacting with SweetAlert2
Stars: ✭ 98 (-70.83%)
Mutual labels:  prompt
enquirer
Stylish, intuitive and user-friendly prompts, for Node.js. Used by eslint, webpack, yarn, pm2, pnpm, RedwoodJS, FactorJS, salesforce, Cypress, Google Lighthouse, Generate, tencent cloudbase, lint-staged, gluegun, hygen, hardhat, AWS Amplify, GitHub Actions Toolkit, @airbnb/nimbus, and many others! Please follow Enquirer's author: https://github.…
Stars: ✭ 6,523 (+1841.37%)
Mutual labels:  prompt
date-prompt
A CLI date picker prompt.
Stars: ✭ 16 (-95.24%)
Mutual labels:  prompt
gitprompt
Display git status in the the terminal prompt
Stars: ✭ 22 (-93.45%)
Mutual labels:  prompt
Docker Shell
A simple interactive prompt for docker
Stars: ✭ 299 (-11.01%)
Mutual labels:  prompt
Pam reattach
Reattach to the user's GUI session on macOS during authentication (for Touch ID support in tmux)
Stars: ✭ 262 (-22.02%)
Mutual labels:  sudo
slimline
Minimal, customizable, fast and elegant ZSH prompt
Stars: ✭ 48 (-85.71%)
Mutual labels:  prompt
mobile-message
基于移动端的弹窗组件,默认提供info、success、warning、error、alert、confirm、multiple、vertical、bottomSheet、prompt,可自定义弹窗。它可以包含任何Html内容可以自定义弹窗的样式,也可以加入自定以的弹窗动画。
Stars: ✭ 13 (-96.13%)
Mutual labels:  prompt
yargs-interactive
Interactive support for yargs
Stars: ✭ 40 (-88.1%)
Mutual labels:  prompt
sudo
Development repository for sudo cookbook
Stars: ✭ 119 (-64.58%)
Mutual labels:  sudo
zsh-prompt-generator
Zsh Prompt Generator
Stars: ✭ 39 (-88.39%)
Mutual labels:  prompt
Trueline
Fast and extensible bash powerline prompt with true color and fancy icon support
Stars: ✭ 271 (-19.35%)
Mutual labels:  prompt
bash-cache
Transparent caching layer for bash functions; particularly useful for functions invoked as part of your prompt.
Stars: ✭ 45 (-86.61%)
Mutual labels:  prompt
bashy
Extremely fast and simple git prompt for bash and zsh
Stars: ✭ 43 (-87.2%)
Mutual labels:  prompt
apollo-zsh-theme
Heavily customizable, compatible, and fast ZSH theme framework.
Stars: ✭ 64 (-80.95%)
Mutual labels:  prompt
Vuejs Dialog
A lightweight, promise based alert, prompt and confirm dialog
Stars: ✭ 327 (-2.68%)
Mutual labels:  prompt
Rxbiometric
☝️ RxJava and RxKotlin bindings for Biometric Prompt (Fingerprint Scanner) on Android
Stars: ✭ 295 (-12.2%)
Mutual labels:  prompt

Electron subprocess with administrative privileges

Run a subprocess with administrative privileges, prompting the user with a graphical OS dialog if necessary. Useful for background subprocesse which run native Electron apps that need sudo.

  • Windows, uses elevate utility with native User Account Control (UAC) prompt (no PowerShell required)
  • OS X, uses bundled applet (inspired by Joran Dirk Greef)
  • Linux, uses system pkexec or gksudo (system or bundled).

If you don't trust binaries bundled in npm package you can manually build tools and use them instead.

Features

  • Supports spawn and exec subprocess behavior
  • Supports applications packaged as asar archive
  • Separate password prompt for each call (use sh or bat script for single prompt)
  • No external dependencies, does not depend on OS versions

Installation

npm install electron-sudo

Usage

Note: Your command should not start with the sudo prefix.

Version 4.0.*

import Sudoer from 'electron-sudo';

let options = {name: 'electron sudo application'},
    sudoer = new Sudoer(options);

/* Spawn subprocess behavior */
let cp = await sudoer.spawn(
  'echo', ['$PARAM'], {env: {PARAM: 'VALUE'}}
);
cp.on('close', () => {
  /*
    cp.output.stdout (Buffer)
    cp.output.stderr (Buffer)
  */
});

/* Exec subprocess behavior */
let result = await sudoer.exec(
  'echo $PARAM', {env: {PARAM: 'VALUE'}}
);
/* result is Buffer with mixed (both stdout and stderr) output */


/* Usage with Vanila JS */

var Sudoer = require('electron-sudo').default;
var sudoer = new Sudoer(options);
sudoer.spawn('echo', ['$PARAM'], {env: {PARAM: 'VALUE'}}).then(function (cp) {
  /*
    cp.output.stdout (Buffer)
    cp.output.stderr (Buffer)
  */
});

Version 3.0.* (deprecated)

var sudo = require('electron-sudo');
var options = {
  name: 'Your application name',
  icns: '/path/to/icns/file' // (optional, only for MacOS),
  process: {
    options: {
      // Can use custom environment variables for your privileged subprocess
      env: {'VAR': 'VALUE'}
      // ... and all other subprocess options described here
      // https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
    },
    on: function(ps) {
      ps.stdout.on('data', function(data) {});
      setTimeout(function() {
        ps.kill()
      }.bind(ps), 50000);
    }
  }
};
sudo.exec('echo hello', options, function(error) {});

Tests

npm i && npm test

Usage with Webpack

Webpack config should contain __dirname equals true for work properly

let nodeModules = fs.readdirSync('./node_modules')
    .filter((module) => {
        return module !== '.bin';
    })
    .reduce((prev, module) => {
        return Object.assign(prev, {[module]: 'commonjs ' + module});
    }, {});

export default {
    ...
    target: 'electron',
    node: {
        /* http://webpack.github.io/docs/configuration.html#node */
        __dirname: true
    },
    externals: nodeModules
};
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].