Skip to content

Commit

Permalink
Update OneUpdater script
Browse files Browse the repository at this point in the history
  • Loading branch information
vegardinho committed Aug 11, 2022
1 parent b7532d2 commit 7f9a440
Showing 1 changed file with 43 additions and 38 deletions.
81 changes: 43 additions & 38 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -770,15 +770,10 @@ function url_exists {
}
function notification {
local -r notificator="$(find . -type d -name 'Notificator.app')"
if [[ -n "${notificator}" ]]; then
"${notificator}/Contents/Resources/Scripts/notificator" --message "${1}" --title "${alfred_workflow_name}" --subtitle 'A new version is available'
return
fi
local -r notificator="$(find . -type f -name 'notificator')"
local -r terminal_notifier="$(find . -type f -name 'terminal-notifier')"
if [[ -n "${terminal_notifier}" ]]; then
"${terminal_notifier}" -title "${alfred_workflow_name}" -subtitle 'A new version is available' -message "${1}"
if [[ -f "${notificator}" && "$(/usr/bin/file --brief --mime-type "${notificator}")" == 'text/x-shellscript' ]]; then
"${notificator}" --message "${1}" --title "${alfred_workflow_name}" --subtitle 'A new version is available'
return
fi
Expand All @@ -795,11 +790,15 @@ readonly local_version="$(/usr/libexec/PlistBuddy -c 'print version' "${local_in
# Check for updates
if [[ $(find "${local_info_plist}" -mtime +"${frequency_check}"d) ]]; then
if ! url_exists "${remote_info_plist}"; then abort "'remote_info_plist' (${remote_info_plist}) appears to not be reachable."; fi # Remote sanity check
# Remote sanity check
if ! url_exists "${remote_info_plist}"; then
abort "'remote_info_plist' (${remote_info_plist}) appears to not be reachable."
fi
readonly tmp_file="$(mktemp)"
curl --silent --location --output "${tmp_file}" "${remote_info_plist}"
readonly remote_version="$(/usr/libexec/PlistBuddy -c 'print version' "${tmp_file}")"
rm "${tmp_file}"
if [[ "${local_version}" == "${remote_version}" ]]; then
touch "${local_info_plist}" # Reset timer by touching local file
Expand All @@ -812,12 +811,19 @@ if [[ $(find "${local_info_plist}" -mtime +"${frequency_check}"d) ]]; then
exit 0
fi
download_url="$([[ "${download_type}" == 'github_release' ]] && curl --silent "https://api.github.com/repos/${workflow_url}/releases/latest" | grep 'browser_download_url' | head -1 | sed -E 's/.*browser_download_url": "(.*)"/\1/' || echo "${workflow_url}")"
readonly download_url="$(
if [[ "${download_type}" == 'github_release' ]]; then
osascript -l JavaScript -e 'function run(argv) { return JSON.parse(argv[0])["assets"].find(asset => asset["browser_download_url"].endsWith(".alfredworkflow"))["browser_download_url"] }' "$(curl --silent "https://api.github.com/repos/${workflow_url}/releases/latest")"
else
echo "${workflow_url}"
fi
)"
if url_exists "${download_url}"; then
notification 'Downloading and installing…'
curl --silent --location --output "${HOME}/Downloads/${alfred_workflow_name}.alfredworkflow" "${download_url}"
open "${HOME}/Downloads/${alfred_workflow_name}.alfredworkflow"
readonly download_name="$(basename "${download_url}")"
curl --silent --location --output "${HOME}/Downloads/${download_name}" "${download_url}"
open "${HOME}/Downloads/${download_name}"
else
abort "'workflow_url' (${download_url}) appears to not be reachable."
fi
Expand Down Expand Up @@ -1131,27 +1137,6 @@ fi</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argumenttype</key>
<integer>1</integer>
<key>keyword</key>
<string>bton</string>
<key>subtext</key>
<string></string>
<key>text</key>
<string>Turn Bluetooth On</string>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.keyword</string>
<key>uid</key>
<string>ED18B100-64A9-46AA-82B6-21A2C7182F4F</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand All @@ -1175,6 +1160,27 @@ fi</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argumenttype</key>
<integer>1</integer>
<key>keyword</key>
<string>bton</string>
<key>subtext</key>
<string></string>
<key>text</key>
<string>Turn Bluetooth On</string>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.keyword</string>
<key>uid</key>
<string>ED18B100-64A9-46AA-82B6-21A2C7182F4F</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -1571,8 +1577,7 @@ fi</string>
<key>readme</key>
<string>NEW IN THIS EDITION:
- Updated notificator binary.
- Added missing workflow icon.
- Updated OneUpdater (automatic updates) script.
Expand Down Expand Up @@ -1781,7 +1786,7 @@ Enjoy!</string>
<key>note</key>
<string>Pair with available devices</string>
<key>xpos</key>
<real>175</real>
<real>185</real>
<key>ypos</key>
<real>875</real>
</dict>
Expand Down Expand Up @@ -1874,7 +1879,7 @@ Enjoy!</string>
<key>xpos</key>
<real>30</real>
<key>ypos</key>
<real>1395</real>
<real>1430</real>
</dict>
<key>EE29FA26-7129-4E3D-9084-F402120BF8F1</key>
<dict>
Expand Down Expand Up @@ -1914,7 +1919,7 @@ Enjoy!</string>
<string>confirm</string>
</array>
<key>version</key>
<string>3.0.1</string>
<string>3.0.2</string>
<key>webaddress</key>
<string>https://github.com/vegardinho/alfred_bluetooth_controller</string>
</dict>
Expand Down

0 comments on commit 7f9a440

Please sign in to comment.