Skip to content

Commit

Permalink
2.50
Browse files Browse the repository at this point in the history
2 November 2022
* Automatised upgrades #46
  • Loading branch information
Jaroslaw Hartman committed Nov 2, 2022
1 parent 715a7dc commit bfaffbc
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 6 deletions.
Binary file renamed TimeZones-v2.41.zip → TimeZones-v2.50.zip
Binary file not shown.
Binary file modified TimeZones.alfredworkflow
Binary file not shown.
88 changes: 82 additions & 6 deletions source/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@
<false/>
</dict>
</array>
<key>408AA1A8-69F7-45E1-AF88-D3B90A40A00E</key>
<array>
<dict>
<key>destinationuid</key>
<string>CAFFEE63-507B-4755-ADDC-20AFDF0CE87E</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>4D7626AC-9354-4ABF-B95D-9224BCC91DDA</key>
<array>
<dict>
Expand Down Expand Up @@ -431,7 +444,7 @@
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<true/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
Expand All @@ -453,9 +466,10 @@
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Fetching time data...</string>
<string>Fetchinig timiezones or checking for an upgrade...</string>
<key>script</key>
<string>./timezone_list.sh "{query}"</string>
<string>./oneUpdater.sh 7
./timezone_list.sh "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -1160,9 +1174,53 @@
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argumenttype</key>
<integer>2</integer>
<key>keyword</key>
<string>timezone upgrade</string>
<key>subtext</key>
<string>Normall, new versions are checked every 7 days</string>
<key>text</key>
<string>Check for a newer version</string>
<key>withspace</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.input.keyword</string>
<key>uid</key>
<string>408AA1A8-69F7-45E1-AF88-D3B90A40A00E</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>0</integer>
<key>script</key>
<string>./oneUpdater.sh 0</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>CAFFEE63-507B-4755-ADDC-20AFDF0CE87E</string>
<key>version</key>
<integer>2</integer>
</dict>
</array>
<key>readme</key>
<string>TimeZones v2.41
<string>TimeZones
2 November 2022
=====
Expand Down Expand Up @@ -1207,6 +1265,10 @@ CHANGELOG
All issues tracked on GitHub https://github.com/jaroslawhartman/TimeZones-Alfred/issues
2.50
2 November 2022
* Automatised upgrades #46
2.41
2 November 2022
* Fixed Option + Enter does not remove a locale #51
Expand Down Expand Up @@ -1440,6 +1502,13 @@ v1.0
<key>ypos</key>
<real>410</real>
</dict>
<key>408AA1A8-69F7-45E1-AF88-D3B90A40A00E</key>
<dict>
<key>xpos</key>
<integer>290</integer>
<key>ypos</key>
<integer>1405</integer>
</dict>
<key>4D5D6C9D-E596-4EB1-A0A7-634814560B7F</key>
<dict>
<key>xpos</key>
Expand Down Expand Up @@ -1573,6 +1642,13 @@ v1.0
<key>ypos</key>
<real>1160</real>
</dict>
<key>CAFFEE63-507B-4755-ADDC-20AFDF0CE87E</key>
<dict>
<key>xpos</key>
<integer>495</integer>
<key>ypos</key>
<integer>1405</integer>
</dict>
<key>D8D3E88A-E982-4F27-B3AA-46DAD6C5D87F</key>
<dict>
<key>xpos</key>
Expand Down Expand Up @@ -1630,10 +1706,10 @@ v1.0
<real>1040</real>
</dict>
</dict>
<key>userconfigurationconfig</key>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>2.41</string>
<string>2.50</string>
<key>webaddress</key>
<string>https://jhartman.pl/tag/time-zones/</string>
</dict>
Expand Down
79 changes: 79 additions & 0 deletions source/oneUpdater.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash

set -x

# THESE VARIABLES MUST BE SET. SEE THE ONEUPDATER README FOR AN EXPLANATION OF EACH.
readonly remote_info_plist='https://raw.githubusercontent.com/jaroslawhartman/TimeZones-Alfred/master/source/info.plist'
readonly workflow_url='https://github.com/jaroslawhartman/TimeZones-Alfred/raw/master/TimeZones.alfredworkflow'
readonly download_type='direct'
readonly frequency_check="${1:-7}"

# FROM HERE ON, CODE SHOULD BE LEFT UNTOUCHED!
function abort {
echo "${1}" >&2
exit 1
}

function url_exists {
curl --silent --location --output /dev/null --fail --range 0-0 "${1}"
}

function notification {
local -r notificator="$(find . -type f -name 'notificator')"

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

osascript -e "display notification \"${1}\" with title \"${alfred_workflow_name}\" subtitle \"A new version is available\""
}

# Local sanity checks
readonly local_info_plist='info.plist'
readonly local_version="$(/usr/libexec/PlistBuddy -c 'print version' "${local_info_plist}")"

[[ -n "${local_version}" ]] || abort 'You need to set a workflow version in the configuration sheet.'
[[ "${download_type}" =~ ^(direct|page|github_release)$ ]] || abort "'download_type' (${download_type}) needs to be one of 'direct', 'page', or 'github_release'."
[[ "${frequency_check}" =~ ^[0-9]+$ ]] || abort "'frequency_check' (${frequency_check}) needs to be a number."

# Check for updates
if [[ $(find "${local_info_plist}" -mtime +"${frequency_check}"d) ]]; then
# 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
exit 0
fi

if [[ "${download_type}" == 'page' ]]; then
notification 'Opening download page…'
open "${workflow_url}"
exit 0
fi

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…'
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
fi

0 comments on commit bfaffbc

Please sign in to comment.