mirror of
https://github.com/actuallymentor/battery.git
synced 2026-03-20 15:40:24 +00:00
🐛 migrate from sudo prompt to applescript for sudo
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
# Battery charge limiter for M1 Mac devices
|
||||
# Battery charge limiter for arm64 (M1/M2) Mac devices
|
||||
|
||||
<img width="300px" align="right" src="./screenshots/tray.png"/>This tool makes it possible to keep a chronically plugged in M1 Macbook at `80%` battery, since that will prolong the longevity of the battery. It is free and open-source and will remain that way.
|
||||
<img width="300px" align="right" src="./screenshots/tray.png"/>This tool makes it possible to keep a chronically plugged in `arm64`-based Macbook at `80%` battery, since that will prolong the longevity of the battery. It is free and open-source and will remain that way.
|
||||
|
||||
> Want to know if this tool does anything or is just a placebo? Read [this excellent article](https://batteryuniversity.com/article/bu-808-how-to-prolong-lithium-based-batteries). TL;DR: keep your battery cool, keep it at 80% when plugged in, and discharge it as shallowly as feasible.
|
||||
|
||||
### Requirements
|
||||
|
||||
This is an app for M1 Macs. It will not work on non-M1 macs. Do you have an older Mac? Consider the free version of the [Al Dente](https://apphousekitchen.com/) software package. It is a good alternative and has a premium version with many more features.
|
||||
This is an app for `arm64` Macs, also known as M1/M2 Macs. It will not work on `amd64` non-M macs. Do you have an older Mac? Consider the free version of the [Al Dente](https://apphousekitchen.com/) software package. It is a good alternative and has a premium version with many more features.
|
||||
|
||||
### Installation
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
const { promises: fs } = require( 'fs' )
|
||||
const log = ( ...messages ) => console.log( ...messages )
|
||||
|
||||
exports.default = async function( context ) {
|
||||
|
||||
const troublesome_files = [
|
||||
`dist/mac-arm64/battery.app/Contents/Resources/app.asar.unpacked/node_modules/electron-sudo/LICENSE`,
|
||||
`dist/mac-arm64/battery.app/Contents/Resources/app.asar.unpacked/node_modules/electron-sudo/dist/bin/applet.app/LICENSE`,
|
||||
`dist/mac-arm64/battery.app/Contents/Resources/app.asar.unpacked/node_modules/electron-sudo/src/bin/applet.app/LICENSE`
|
||||
]
|
||||
|
||||
try {
|
||||
log( '\n\n🪝 afterPack hook triggered: ' )
|
||||
await Promise.all( troublesome_files.map( file => {
|
||||
log( `Deleting ${ file }` )
|
||||
return fs.rm( file ).catch( f => log( `No need to delete ${ file }` ) )
|
||||
} ) )
|
||||
log( 'Cleaned up LICENSE files\n\n' )
|
||||
return context
|
||||
} catch( e ) {
|
||||
log( `afterPack issue: `, e )
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
// Notarization
|
||||
// See https://kilianvalkhof.com/2019/electron/notarizing-your-electron-application/
|
||||
// /////////////////////////////*/
|
||||
require('dotenv').config()
|
||||
const { notarize } = require('electron-notarize')
|
||||
require( 'dotenv' ).config()
|
||||
const { notarize } = require( 'electron-notarize' )
|
||||
const log = ( ...messages ) => console.log( ...messages )
|
||||
|
||||
exports.default = async function notarizing(context) {
|
||||
exports.default = async function notarizing( context ) {
|
||||
|
||||
log( '\n\n🪝 afterSign hook triggered: ' )
|
||||
const { appOutDir } = context
|
||||
@@ -16,7 +16,7 @@ exports.default = async function notarizing(context) {
|
||||
return await notarize( {
|
||||
appBundleId: 'co.palokaj.battery',
|
||||
tool: "notarytool",
|
||||
appPath: `${appOutDir}/${appName}.app`,
|
||||
appPath: `${ appOutDir }/${ appName }.app`,
|
||||
appleId: APPLEID,
|
||||
appleIdPassword: APPLEIDPASS,
|
||||
teamId: TEAMID
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Command line interactors
|
||||
const { exec } = require( 'node:child_process' )
|
||||
const sudo = require( 'sudo-prompt' )
|
||||
const { log, alert, wait } = require( './helpers' )
|
||||
const { USER } = process.env
|
||||
const path_fix = 'PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/opt/homebrew:/usr/bin/'
|
||||
@@ -34,20 +33,6 @@ 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 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( stderr ) return reject( stderr )
|
||||
// if( stdout ) return resolve( stdout )
|
||||
|
||||
// } )
|
||||
|
||||
// } )
|
||||
|
||||
const exec_sudo_async = command => new Promise( ( resolve, reject ) => {
|
||||
|
||||
log( `Executing ${ command } by running:` )
|
||||
@@ -125,6 +110,10 @@ const initialize_battery = async () => {
|
||||
|
||||
try {
|
||||
|
||||
// Check if dev mode
|
||||
const { development, skipupdate } = process.env
|
||||
if( development ) log( `Dev mode on, skip updates: ${ skipupdate }` )
|
||||
|
||||
// Check for network
|
||||
const online = await Promise.race( [
|
||||
exec_async( `${ path_fix } curl icanhasip.com &> /dev/null` ).then( () => true ).catch( () => false ),
|
||||
@@ -167,6 +156,7 @@ const initialize_battery = async () => {
|
||||
// If installed, update
|
||||
if( is_installed && visudo_complete ) {
|
||||
if( !online ) return log( `Skipping battery update because we are offline` )
|
||||
if( skipupdate ) return log( `Skipping update due to environment variable` )
|
||||
log( `Updating battery...` )
|
||||
const result = await exec_async( `${ battery } update silent` )
|
||||
log( `Update result: `, result )
|
||||
|
||||
@@ -32,7 +32,6 @@ const generate_app_menu = async () => {
|
||||
click: enable_limiter
|
||||
},
|
||||
{
|
||||
sublabel: 'thing',
|
||||
label: `Disable ${ maintain_percentage }% battery limit`,
|
||||
type: 'radio',
|
||||
checked: !limiter_on,
|
||||
|
||||
6275
app/package-lock.json
generated
6275
app/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,6 @@
|
||||
"**/*"
|
||||
]
|
||||
},
|
||||
"afterPack": "./build_hooks/afterPack.js",
|
||||
"afterSign": "./build_hooks/afterSign.js",
|
||||
"mac": {
|
||||
"hardenedRuntime": true,
|
||||
@@ -23,6 +22,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "development=true electron .",
|
||||
"start:watch": "nodemon --watch . --exec 'skipupdate=true development=true electron .'",
|
||||
"build": "rm -rf ./dist/* && electron-builder build --mac --arm64",
|
||||
"prepare": "cd .. && husky install ./app/.husky",
|
||||
"lint": "eslint --fix modules main.js"
|
||||
@@ -38,16 +38,16 @@
|
||||
"devDependencies": {
|
||||
"@babel/eslint-parser": "^7.19.1",
|
||||
"@poap/skunk-linter": "^0.0.1",
|
||||
"dotenv": "^16.0.2",
|
||||
"electron": "^20.1.4",
|
||||
"electron-builder": "^23.3.3",
|
||||
"dotenv": "^16.0.3",
|
||||
"electron": "^23.0.0",
|
||||
"electron-builder": "^23.6.0",
|
||||
"electron-notarize": "^1.2.1",
|
||||
"eslint": "^8.33.0",
|
||||
"eslint": "^8.34.0",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"husky": "^8.0.3"
|
||||
"husky": "^8.0.3",
|
||||
"nodemon": "^2.0.20"
|
||||
},
|
||||
"dependencies": {
|
||||
"sudo-prompt": "^9.2.1",
|
||||
"update-electron-app": "^2.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user