Skip to content

Commit

Permalink
Merge pull request #20 from whomwah/latest-update
Browse files Browse the repository at this point in the history
fix: reduce update api check request to just one
  • Loading branch information
whomwah authored Oct 31, 2022
2 parents edd0d2b + 00e1b47 commit e99a087
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ readonly gh_url="https://api.github.com/repos/${gh_repo}/releases/latest"
# Fetch latest version
function fetch_remote_version {
curl --silent "${gh_url}" | grep 'tag_name' | head -1 | sed -E 's/.*tag_name": "v?(.*)".*/\1/'
echo $1 | grep 'tag_name' | head -1 | sed -E 's/.*tag_name": "v?(.*)".*/\1/'
}
# Fetch download url
function fetch_download_url {
curl --silent "${gh_url}" | grep 'browser_download_url.*\.alfredworkflow"' | head -1 | sed -E 's/.*browser_download_url": "(.*)".*/\1/'
echo $1 | grep 'browser_download_url.*\.alfredworkflow"' | head -1 | sed -E 's/.*browser_download_url": "(.*)".*/\1/'
}
# Download and install workflow
Expand All @@ -122,8 +122,9 @@ function download_and_install {
}
# Setting version and download url for later use
readonly version="$(fetch_remote_version)"
readonly download_url="$(fetch_download_url)"
readonly response=$(curl --silent "${gh_url}")
readonly version="$(fetch_remote_version $response)"
readonly download_url="$(fetch_download_url $response)"
# Compare current version to installed version and download if required
[ $(printf "%d%03d%03d%03d\n" $(echo ${alfred_workflow_version} | tr '.' ' ')) -lt $(printf "%d%03d%03d%03d\n" $(echo ${version} | tr '.' ' ')) ] && download_and_install ${download_url} ${version}
Expand Down

0 comments on commit e99a087

Please sign in to comment.