Skip to content

Commit

Permalink
Use curl in update script
Browse files Browse the repository at this point in the history
  • Loading branch information
sballin committed May 5, 2020
1 parent 78ac23c commit 32fd37e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
2 changes: 2 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ For further info and troubleshooting, visit https://github.com/sballin/alfred-se
<key>sortByDate</key>
<string>1</string>
</dict>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>2.2.1</string>
<key>webaddress</key>
Expand Down
56 changes: 29 additions & 27 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import plistlib
from distutils.version import StrictVersion
from urllib import request


def oneDaySinceLastCheck():
Expand Down Expand Up @@ -32,14 +31,17 @@ def updateAvailable(latestVersion):
return False


def userWantsUpdate(updateUrl):
def userWantsUpdate(updateNotes):
'''
Show user a confirmation dialog.
'''
retval = os.system("""
osascript -e 'display dialog "An update is available for the Search Notes workflow. Press OK to download and open this file:
osascript -e 'display dialog "An update is available for the Search Notes workflow. Press OK to download and open it. Notes for this release:
%s
Daily update checks can be disabled by editing the workflow."'
""" % updateUrl)
Daily update checks can be disabled by editing the workflow."' 2>/dev/null
""" % updateNotes)
if retval == 0:
return True
else:
Expand All @@ -50,27 +52,27 @@ def update(updateUrl):
'''
Download and open new version of workflow.
'''
r = request.urlopen(updateUrl, timeout=60)
if r.status == 200:
updateFile = '/tmp/Search.Notes.alfredworkflow'
with open(updateFile, 'wb') as f:
f.write(r.read())
os.system('open ' + updateFile)
updateFile = '/tmp/Search.Notes.alfredworkflow'
# --location is required in order to follow redirects
curlRet = os.system('curl --silent --location --output %s %s' % (updateFile, updateUrl))
openRet = 1
if curlRet == 0:
openRet = os.system('open ' + updateFile)
if curlRet != 0 or openRet != 0:
os.system("osascript -e 'display dialog \"The Search Notes workflow failed to update.\"' 2>/dev/null")


try:
if oneDaySinceLastCheck():
latestUrl = 'https://api.github.com/repos/sballin/alfred-search-notes-app/releases/latest'
r = request.urlopen(latestUrl, timeout=60)
if r.status == 200:
body = r.read()
latest = json.loads(body.decode('utf-8'))
latestVersion = latest['tag_name']
updateUrl = latest['assets'][0]['browser_download_url']

if updateAvailable(latestVersion):
if userWantsUpdate(updateUrl):
update(updateUrl)
except:
pass

if oneDaySinceLastCheck():
latestUrl = 'https://api.github.com/repos/sballin/alfred-search-notes-app/releases/latest'
latestFile = 'latest_release.json'
retval = os.system('curl --silent --max-time 30 --output %s %s' % (latestFile, latestUrl))
if retval == 0:
with open(latestFile, 'r') as f:
latest = json.load(f)
latestVersion = latest['tag_name']
updateNotes = latest['body']
updateUrl = latest['assets'][0]['browser_download_url']

if updateAvailable(latestVersion):
if userWantsUpdate(updateNotes):
update(updateUrl)

0 comments on commit 32fd37e

Please sign in to comment.