Skip to content

Commit

Permalink
2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
grahampugh committed Jun 23, 2023
1 parent 58cbffb commit b60b243
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

No date

## [2.4]

23.06.2023

- If a user figures out the quit key and exits swiftDialog that way, this is treated the same as the Continue button.
- Dialog is no longer movable, so users cannot move it out of the way.
- If Software Update is left open for an hour, the dialog appears again, so users can't just minimise Software Update to avoid deferral count increases.
- Update for compatibility with swiftDialog 2.2.1.

## [2.3.1]

20.03.2023
Expand Down Expand Up @@ -110,7 +119,8 @@ Changed the default button of the jamfHelper dialogs to Cancel, because after ti

Also shortened the timeout to 82800 from 99999 seconds to prevent overlap of two days' dialogs.

[untagged]: https://github.com/grahampugh/nice-updater/compare/v2.3...HEAD
[untagged]: https://github.com/grahampugh/nice-updater/compare/v2.4...HEAD
[2.4]: https://github.com/grahampugh/nice-updater/compare/v2.3.1...v2.4
[2.3.1]: https://github.com/grahampugh/nice-updater/compare/v2.3...v2.3.1
[2.3]: https://github.com/grahampugh/nice-updater/compare/v2.2...v2.3
[2.2]: https://github.com/grahampugh/nice-updater/compare/v2.1...v2.2
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
identifier="com.github.grahampugh.nice_updater"

# Default version of the build, you can leave this alone and specify as an argument like so: ./build.sh 1.7
version="2.3.1"
version="2.4"

# The title of the message that is displayed when software updates are in progress and a user is logged in
updateRequiredTitle="macOS Software Updates Required"
Expand Down Expand Up @@ -38,7 +38,7 @@ startIntervalMinute="0" # valid is 0-59. Do not leave blank - set as 0
alertTimeout="3540"

###### Variables below this point are not intended to be modified #####
SWIFTDIALOG_URL="https://github.com/bartreardon/swiftDialog/releases/download/v2.1.0/dialog-2.1.0-4148.pkg"
SWIFTDIALOG_URL="https://github.com/bartreardon/swiftDialog/releases/download/v2.2.1/dialog-2.2.1-4591.pkg"
mainDaemonPlist="/Library/LaunchDaemons/${identifier}.plist"
mainDaemonFileName="${mainDaemonPlist##*/}"
mainOnDemandDaemonPlist="/Library/LaunchDaemons/${identifier}_on_demand.plist"
Expand Down
69 changes: 32 additions & 37 deletions nice_updater.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Nice Updater 2
version="2.3"
version="2.4"

# These variables will be automagically updated if you run build.sh, no need to modify them
preferenceFileFullPath="/Library/Preferences/com.github.grahampugh.nice_updater.prefs.plist"
Expand All @@ -28,7 +28,7 @@ dialog_log=$(/usr/bin/mktemp /var/tmp/dialog.XXX)

# URL for downloading dialog (with tag version)
# This ensures a compatible dialog is used if not using the package installer
dialog_download_url="https://github.com/bartreardon/swiftDialog/releases/download/v2.1.0/dialog-2.1.0-4148.pkg"
dialog_download_url="https://github.com/bartreardon/swiftDialog/releases/download/v2.2.1/dialog-2.2.1-4591.pkg"

# set default icon if not included in build
if [[ "$iconCustomPath" ]]; then
Expand Down Expand Up @@ -118,7 +118,6 @@ get_default_dialog_args() {
elif [[ "$1" == "utility" ]]; then
echo " [get_default_dialog_args] Invoking utility dialog"
default_dialog_args+=(
"--moveable"
"--width"
"60%"
"--titlefont"
Expand Down Expand Up @@ -155,13 +154,24 @@ record_last_full_update() {
open_software_update() {
/usr/bin/open -W /System/Library/PreferencePanes/SoftwareUpdate.prefPane &
suPID=$!
writelog "Software Update PID: $suPID"
writelog "Opening Software Update with PID: $suPID"
# While Software Update is open...
timecount=0
while kill -0 "$suPID" 2> /dev/null; do
sleep 1
# set a maximum time that Software Update can be open before invoking another dialog
((timecount++))
if [[ $timecount -ge 3600 ]]; then
break
fi
done
writelog "Software Update was closed"
write_status "Software Update was closed"
if [[ $timecount -ge 3600 ]]; then
writelog "Software Update was open too long"
write_status "Software Update was open too long"
else
writelog "Software Update was closed"
write_status "Software Update was closed"
fi
was_closed=1
}

Expand Down Expand Up @@ -225,47 +235,32 @@ alert_user() {
"Continue"
"--button2text"
"Defer for 24 hours"
"--timer"
"$alertTimeout"
"--hidetimerbar"
)
# run the dialog command
"$dialog_bin" "${dialog_args[@]}" & sleep 0.1

dialogPID=$!
writelog "dialogPID: $dialogPID"
# since the "cancel" exit code is the same as the timeout exit code, we
# need to distinguish between the two. We use a while loop that checks
# that the process exists every second. If so, count down 1 and check
# again. If the process is gone, use `wait` to grab the exit code.
timeLeft=$alertTimeout
while [[ $timeLeft -gt 0 ]]; do
if /usr/bin/pgrep dialog ; then
# writelog "Waiting for timeout: $timeLeft remaining"
sleep 1
((timeLeft--))
else
wait $dialogPID
helperExitCode=$?
break
fi
done
# if the process is still running, we need to kill it and give a fake
# exit code
if /usr/bin/pgrep dialog; then
# quit an existing window
echo "quit:" >> "$dialog_log"
helperExitCode=1
else
writelog "A button was pressed"
fi
fi

# writelog "Response: $helperExitCode"
if [[ $helperExitCode == 0 ]]; then
# get the helper exit code
dialogPID=$!
wait $dialogPID
helperExitCode=$?
writelog "Dialog exit code: $helperExitCode"

# all exit codes decrease the remaining deferrals except when the window times out without response
if [[ $helperExitCode -eq 0 ]]; then
writelog "User initiated installation"
write_status "User initiated installation"
open_software_update
elif [[ $helperExitCode == 2 ]]; then
elif [[ $helperExitCode -eq 2 ]]; then
writelog "User cancelled installation"
write_status "User cancelled installation"
elif [[ $helperExitCode -eq 10 ]]; then
writelog "User quit dialog using the quit key"
write_status "User quit dialog using the quit key"
open_software_update
else
writelog "Alert timed out without response"
write_status "Alert timed out without response"
Expand Down

0 comments on commit b60b243

Please sign in to comment.