Skip to content

Commit

Permalink
Update Alfred-Workflow & add self-updating
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Apr 29, 2017
1 parent 49c1e4e commit 20e0728
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 69 deletions.
Binary file not shown.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
Alfred Fixum
============

Fix Alfred 3 Python workflows affected by [the Sierra background process bug][bug] in [Alfred-Workflow][aw].
Fix Alfred 3 Python workflows affected by bugs in [Alfred-Workflow][aw], in particular the [the Sierra background process bug][bug].

If you're not running Sierra, you don't need to run Fixum.

Fixum analyses your installed workflows to see if any use an old, buggy version of the Alfred-Workflow library. If they do, it can update them with a newer, working version.
Fixum analyses your installed workflows to see if any use an old version of the Alfred-Workflow library. If they do, it can update them with a newer, working version.


Installation
Expand Down Expand Up @@ -34,6 +32,8 @@ If everything looks good, run **Fix Workflows**.
### Alfred commands ###

- `fixnum` — Show available actions
- **A newer version of Fixum is available** — Shown if an update
for Fixum is available.
- **Dry Run** — Analyse installed workflows, but don't change anything
- **View Log File** — See what the workflow would change/has changed
- **Edit Blacklist** — Change the list of bundle IDs that should not be updated (e.g. your own workflows)
Expand Down
70 changes: 68 additions & 2 deletions src/fixum.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""fixum [options]
Usage:
fixum list <query>
fixum [-n]
fixum -h|--help
fixum --version
Expand All @@ -33,7 +34,15 @@
import sys

import docopt
from workflow import Workflow3
from workflow import (
ICON_WARNING,
MATCH_STARTSWITH,
MATCH_CAPITALS,
MATCH_ATOM,
MATCH_INITIALS_STARTSWITH,
MATCH_SUBSTRING,
Workflow3,
)
from workflow.update import Version


Expand All @@ -44,8 +53,11 @@
'net.deanishe.alfred.fixum', # this workflow
]

ICON_UPDATE = 'update-available.png'

# version of AW in this workflow
MIN_VERSION = Version('1.25.2')
VERSION_FILE = os.path.join(os.path.dirname(__file__), 'workflow/version')
MIN_VERSION = Version(open(VERSION_FILE).read())

# path to good copy of Alfred-Workflow
WF_DIR = os.path.join(os.path.dirname(__file__), 'workflow')
Expand All @@ -64,6 +76,11 @@

HELP_URL = 'https://github.com/deanishe/alfred-fixum/issues'

MATCH = (MATCH_STARTSWITH |
MATCH_CAPITALS |
MATCH_ATOM |
MATCH_INITIALS_STARTSWITH |
MATCH_SUBSTRING)

Workflow = namedtuple('Workflow', 'name id dir aw_version aw_dir')
AWInfo = namedtuple('AWInfo', 'path version')
Expand Down Expand Up @@ -180,9 +197,58 @@ def update_workflow(info):
log.info(' installed new version of Alfred-Workflow')


def list_actions(opts):
"""Show available workflow actions."""
query = opts['<query>']
log.debug('query=%r', query)

if wf.update_available:
wf.add_item('A newer version of Fixum is available',
u'⇥ or ↩ to install update',
valid=False,
autocomplete='workflow:update',
icon=ICON_UPDATE)

items = [
dict(title='Dry Run',
subtitle='Show what the workflow would update',
arg='dryrun',
valid=True),
dict(title='View Log File',
subtitle='Open the log file in Console.app',
arg='log',
valid=True),
dict(title='Edit Blacklist',
subtitle='List of workflows to *not* update',
arg='blacklist',
valid=True),
dict(title='Fix Workflows',
subtitle=('Replace broken versions of Alfred-Workflow '
'within your workflows'),
arg='fix',
valid=True),
]

if query:
items = wf.filter(query, items, key=lambda d: d['title'],
match_on=MATCH, min_score=50)

if not items:
wf.add_item('No matching actions', 'Try a different query',
icon=ICON_WARNING)

for d in items:
wf.add_item(**d)

wf.send_feedback()


def main(wf):
"""Run workflow script."""
opts = docopt.docopt(__doc__, argv=wf.args, version=wf.version)
if opts['list']:
return list_actions(opts)

dry_run = opts['--nothing']
log.info('=' * 50)
log.debug('opts=%r', opts)
Expand Down
82 changes: 50 additions & 32 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<string>net.deanishe.alfred.fixum</string>
<key>connections</key>
<dict>
<key>1FFB6897-CFE2-4086-8920-CBEC8B411C31</key>
<key>4FFEB019-EBD2-452B-AC8B-54E7C33ABE9F</key>
<array>
<dict>
<key>destinationuid</key>
Expand Down Expand Up @@ -45,6 +45,49 @@
<string>Fixum</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>fixum</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>/usr/bin/python fixum.py list "$1"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Update Alfred-Workflow library in workflows using a buggy version</string>
<key>title</key>
<string>Fix Python Workflows</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>4FFEB019-EBD2-452B-AC8B-54E7C33ABE9F</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -108,42 +151,17 @@ exit 0</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argumenttype</key>
<integer>1</integer>
<key>fixedorder</key>
<true/>
<key>items</key>
<string>[{"title":"Dry Run","arg":"dryrun","subtitle":"Show what the workflow would update"},{"title":"View Log File","arg":"log","subtitle":"Open the logfile in Console.app"},{"title":"Edit Blacklist","arg":"blacklist","subtitle":"List of workflows to *not* update"},{"title":"Fix Workflows","arg":"fix","subtitle":"Replace broken versions of Alfred-Workflow within your workflows"}]</string>
<key>keyword</key>
<string>fixum</string>
<key>runningsubtext</key>
<string></string>
<key>subtext</key>
<string>Update Alfred-Workflow library in workflows using a buggy version</string>
<key>title</key>
<string>Fix Python Workflows</string>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.listfilter</string>
<key>uid</key>
<string>1FFB6897-CFE2-4086-8920-CBEC8B411C31</string>
<key>version</key>
<integer>1</integer>
</dict>
</array>
<key>readme</key>
<string></string>
<string>This workflow upgrades the version of Alfred-Workflow used by your installed workflows.
It is primarily a workaround to fix bugs that are preventing the workflows from updating themselves or causing issues with Alfred.</string>
<key>uidata</key>
<dict>
<key>1FFB6897-CFE2-4086-8920-CBEC8B411C31</key>
<key>4FFEB019-EBD2-452B-AC8B-54E7C33ABE9F</key>
<dict>
<key>xpos</key>
<integer>30</integer>
<integer>20</integer>
<key>ypos</key>
<integer>30</integer>
</dict>
Expand All @@ -163,7 +181,7 @@ exit 0</string>
</dict>
</dict>
<key>version</key>
<string>0.1.5</string>
<string>0.2</string>
<key>webaddress</key>
<string></string>
</dict>
Expand Down
Binary file added src/update-available.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Workflow objects
from .workflow import Workflow, manager
from .workflow3 import Workflow3
from .workflow3 import Variables, Workflow3

# Exceptions
from .workflow import PasswordNotFound, KeychainError
Expand Down Expand Up @@ -67,6 +67,7 @@
__copyright__ = 'Copyright 2014 Dean Jackson'

__all__ = [
'Variables',
'Workflow',
'Workflow3',
'manager',
Expand Down
2 changes: 1 addition & 1 deletion src/workflow/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.25.2
1.26
Loading

0 comments on commit 20e0728

Please sign in to comment.