From af7978a8ea2a73ff4fd3b407de4dfcb6311eb987 Mon Sep 17 00:00:00 2001 From: Mentor Date: Sat, 11 Feb 2023 22:49:30 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20bypass=20the=20need=20for=20electro?= =?UTF-8?q?n-sudo=20by=20using=20osascript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/battery.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/modules/battery.js b/app/modules/battery.js index d7611d4..9db6816 100644 --- a/app/modules/battery.js +++ b/app/modules/battery.js @@ -34,13 +34,28 @@ const exec_async = ( command, timeout_in_ms=2000, throw_on_timeout=false ) => Pr ] ) // Execute with sudo -const exec_sudo_async = async command => new Promise( ( resolve, reject ) => { +// const exec_sudo_async = async command => new Promise( ( resolve, reject ) => { - const options = { name: 'Battery limiting utility', ...shell_options } - log( `Sudo executing command: ${ command }` ) - sudo.exec( command, options, ( error, stdout, stderr ) => { +// const options = { name: 'Battery limiting utility', ...shell_options } +// log( `Sudo executing command: ${ command }` ) +// sudo.exec( command, options, ( error, stdout, stderr ) => { - if( error ) return reject( error ) +// if( error ) return reject( error ) +// if( stderr ) return reject( stderr ) +// if( stdout ) return resolve( stdout ) + +// } ) + +// } ) + +const exec_sudo_async = command => new Promise( ( resolve, reject ) => { + + log( `Executing ${ command } by running:` ) + log( `osascript -e "do shell script \\"${ command }\\" with administrator privileges"` ) + + exec( `osascript -e "do shell script \\"${ command }\\" with administrator privileges"`, shell_options, ( error, stdout, stderr ) => { + + if( error ) return reject( error, stderr, stdout ) if( stderr ) return reject( stderr ) if( stdout ) return resolve( stdout )