Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --ac-only argument to start autoupdate only when device is not running on battery power #112

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ brew autoupdate version:
open a GUI to ask for the password.
Requires https://formulae.brew.sh/formula/pinentry-mac
to be installed.
--ac-only Only run autoupdate when on AC power.
Must be passed with `start`.
-d, --debug Display any debugging information.
-q, --quiet Make some output more quiet.
-v, --verbose Make some output more verbose.
Expand Down
3 changes: 2 additions & 1 deletion cmd/autoupdate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def autoupdate_args
switch "--sudo",
description: "If a Cask requires sudo, autoupdate will open a GUI to ask for the password. " \
"Requires https://formulae.brew.sh/formula/pinentry-mac to be installed."

switch "--ac-only",
description: "Only run autoupdate when on AC power. Must be passed with `start`."
named_args SUBCOMMANDS
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/autoupdate/start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,20 @@ def start(interval:, args:)
set_env << "\nexport SUDO_ASKPASS=#{env_sudo}"
end

ac_only = if args.ac_only?
<<~EOS
if [[ $(pmset -g ps | head -1) =~ "Battery Power" ]]; then
echo "Not starting autoupdate, because device is running on Battery"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this print to the applet notification? Will the user be notified essentially that Autoupdate hasn't actually been run?

Copy link
Contributor Author

@swissbuechi swissbuechi Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole autoupdate script will not run, so no applet notification will be shown.

The users will not be notified.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the autoupdate script ever start or is it essentially "stuck" until the user tries to activate it again? That's my only concern here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This time, I'm sorry for the late reply, totally missed it.

It will only run, if the user ever again plugs in power (what he's very likely to do since he want's to continue using the device) and another trigger (reboot or time) initiates the execution of the autoupdate script.

exit
fi
EOS
else
""
end

script_contents = <<~EOS
#!/bin/sh
#{ac_only.chomp}
#{set_env}
/bin/date && #{Autoupdate::Core.brew} #{auto_args}
EOS
Expand Down