mirror of
https://github.com/actuallymentor/battery.git
synced 2026-02-03 14:03:24 +00:00
Add uninstall button to GUI
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// Command line interactors
|
||||
const { app } = require( 'electron' )
|
||||
const { exec } = require( 'node:child_process' )
|
||||
const { log, alert, wait } = require( './helpers' )
|
||||
const { log, alert, wait, confirm } = require( './helpers' )
|
||||
const { USER } = process.env
|
||||
const path_fix = 'PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/opt/homebrew:/usr/bin/'
|
||||
const path_fix = 'PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:/opt/homebrew'
|
||||
const battery = `${ path_fix } battery`
|
||||
const shell_options = {
|
||||
shell: '/bin/bash',
|
||||
@@ -177,6 +177,22 @@ const initialize_battery = async () => {
|
||||
|
||||
}
|
||||
|
||||
const uninstall_battery = async () => {
|
||||
|
||||
try {
|
||||
const confirmed = await confirm( `Are you sure you want to uninstall Battery?` )
|
||||
if( !confirmed ) return false
|
||||
await exec_sudo_async( `${ path_fix } sudo battery uninstall silent` )
|
||||
await alert( `Battery is now uninstalled!` )
|
||||
return true
|
||||
} catch ( e ) {
|
||||
log( 'Error uninstalling battery: ', e )
|
||||
alert( `Error uninstalling battery: ${ e.message }` )
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
const is_limiter_enabled = async () => {
|
||||
|
||||
@@ -197,5 +213,6 @@ module.exports = {
|
||||
disable_battery_limiter,
|
||||
initialize_battery,
|
||||
is_limiter_enabled,
|
||||
get_battery_status
|
||||
get_battery_status,
|
||||
uninstall_battery
|
||||
}
|
||||
@@ -4,6 +4,10 @@ let has_alerted_user_no_home = false
|
||||
|
||||
const { dialog } = require( 'electron' )
|
||||
const alert = ( message ) => dialog.showMessageBox( { message } )
|
||||
const confirm = ( message ) => dialog.showMessageBox( { message, buttons: [ "Confirm", "Cancel" ] } ).then( ( { response } ) => {
|
||||
if( response == 0 ) return true
|
||||
return false
|
||||
} )
|
||||
const wait = time_in_ms => new Promise( resolve => {
|
||||
setTimeout( resolve, time_in_ms )
|
||||
} )
|
||||
@@ -30,5 +34,6 @@ const log = async ( ...messages ) => {
|
||||
module.exports = {
|
||||
log,
|
||||
alert,
|
||||
wait
|
||||
wait,
|
||||
confirm
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
const { shell, app, Tray, Menu, powerMonitor, nativeTheme } = require( 'electron' )
|
||||
const { enable_battery_limiter, disable_battery_limiter, initialize_battery, is_limiter_enabled, get_battery_status } = require( './battery' )
|
||||
const { enable_battery_limiter, disable_battery_limiter, initialize_battery, is_limiter_enabled, get_battery_status, uninstall_battery } = require( './battery' )
|
||||
const { log } = require( "./helpers" )
|
||||
const { get_logo_template } = require( './theme' )
|
||||
|
||||
@@ -58,6 +58,19 @@ const generate_app_menu = async () => {
|
||||
label: `Check for updates`,
|
||||
click: () => shell.openExternal( `https://github.com/actuallymentor/battery/releases` )
|
||||
},
|
||||
{
|
||||
type: 'normal',
|
||||
label: `Uninstall Battery ${ app.getVersion() }`,
|
||||
click: async () => {
|
||||
const uninstalled = await uninstall_battery()
|
||||
if( !uninstalled ) return
|
||||
tray.destroy()
|
||||
app.quit()
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: `User manual`,
|
||||
click: () => shell.openExternal( `https://github.com/actuallymentor/battery#readme` )
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "battery",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"description": "A battery charge limiter for Apple silicon Mac devices",
|
||||
"main": "main.js",
|
||||
"build": {
|
||||
|
||||
Reference in New Issue
Block a user