Skip to content

Commit

Permalink
Fix hanging background processes on Sierra #2
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Apr 1, 2017
1 parent 61b4a62 commit fad1aa3
Show file tree
Hide file tree
Showing 19 changed files with 1,550 additions and 415 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

# Alfred-Viscosity #
Alfred-Viscosity
================

Manage your [Viscosity][viscosity] VPN connections from [Alfred][alfred].

**Note:** Version 2 requires Alfred 3.

![Alfred-Viscosity in action][demo]


## Usage ##
Usage
-----

- `vpn [<query>]` — View and filter Viscosity VPN connections.
- `` — Connect/disconnect selected connection.
Expand All @@ -16,7 +20,8 @@ If you haven't entered a query, any active VPN connections will be shown at the
If you are connected to multiple VPNs, an additional "Disconnect All" item will be shown first.


## Licence & thanks ##
Licence & thanks
----------------

This workflow is licensed under the [MIT Licence][mit].

Expand Down
9 changes: 9 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Features:

Bugs:



___________________
Archive:
- Notify user when an update is available. @done(17-04-01 17:41) @project(Features)
Binary file removed Viscosity-1.1.alfredworkflow
Binary file not shown.
Binary file added Viscosity-2.0.alfredworkflow
Binary file not shown.
30 changes: 24 additions & 6 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
</dict>
Expand All @@ -31,6 +33,8 @@
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
Expand All @@ -48,7 +52,11 @@
<key>runningsubtext</key>
<string>Loading VPN information…</string>
<key>script</key>
<string>/usr/bin/python viscosity.py list "{query}"</string>
<string>/usr/bin/python viscosity.py list "$1"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Manage VPN Connections</string>
<key>title</key>
Expand All @@ -63,7 +71,7 @@
<key>uid</key>
<string>2CD984EF-1CE0-4DFD-BC28-7AB81B9C9F38</string>
<key>version</key>
<integer>0</integer>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
Expand All @@ -73,7 +81,11 @@
<key>escaping</key>
<integer>0</integer>
<key>script</key>
<string>/usr/bin/python viscosity.py {query}</string>
<string>/usr/bin/python viscosity.py $1</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
Expand All @@ -82,7 +94,7 @@
<key>uid</key>
<string>3320B185-EABE-4399-98AB-D93EFA238B86</string>
<key>version</key>
<integer>0</integer>
<integer>2</integer>
</dict>
</array>
<key>readme</key>
Expand All @@ -96,15 +108,21 @@ Requires Viscosity app from https://www.sparklabs.com/viscosity/</string>
<dict>
<key>2CD984EF-1CE0-4DFD-BC28-7AB81B9C9F38</key>
<dict>
<key>xpos</key>
<integer>40</integer>
<key>ypos</key>
<real>10</real>
<integer>40</integer>
</dict>
<key>3320B185-EABE-4399-98AB-D93EFA238B86</key>
<dict>
<key>xpos</key>
<integer>240</integer>
<key>ypos</key>
<real>10</real>
<integer>40</integer>
</dict>
</dict>
<key>version</key>
<string>2.0</string>
<key>webaddress</key>
<string></string>
</dict>
Expand Down
Binary file modified src/scripts/connect_vpn.scpt
Binary file not shown.
Binary file modified src/scripts/disconnect_vpn.scpt
Binary file not shown.
Binary file modified src/scripts/get_connections.scpt
Binary file not shown.
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.
33 changes: 20 additions & 13 deletions src/viscosity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# encoding: utf-8
#
# Copyright © 2015 deanishe@deanishe.net
# Copyright (c) 2015 deanishe@deanishe.net
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
Expand All @@ -21,7 +21,7 @@
-h, --help Show this message and exit.
"""

from __future__ import print_function, unicode_literals, absolute_import
from __future__ import print_function, absolute_import

from collections import namedtuple
from operator import attrgetter
Expand All @@ -30,10 +30,11 @@
import sys

import docopt
from workflow import Workflow, ICON_WARNING
from workflow import Workflow3, ICON_WARNING

log = None

ICON_UPDATE = 'update-available.png'
UPDATE_SETTINGS = {
'github_slug': 'deanishe/alfred-viscosity'
}
Expand All @@ -44,12 +45,10 @@
def run_script(script_name, *args):
"""Return output of script `script_name`.
Script must reside in `./scripts` subdirectory and
have extension `.scpt`.
"""

script = wf.workflowfile('scripts/{0}.scpt'.format(script_name))
cmd = ['/usr/bin/osascript', script.encode('utf-8')]
cmd += [a.encode('utf-8') for a in args]
Expand All @@ -70,7 +69,6 @@ def _load_connections():
Returns a list of VPN tuples.
"""

connections = []
output = run_script('get_connections').strip()
for line in output.split('\n'):
Expand All @@ -93,7 +91,8 @@ def _load_connections():

def load_connections():
"""Return list of VPN connections. Cache list for 5 seconds."""
return wf.cached_data('connections', _load_connections, max_age=5)
return wf.cached_data('connections', _load_connections, max_age=0,
session=True)


def do_list(args):
Expand All @@ -113,6 +112,14 @@ def do_list(args):

# ---------------------------------------------------------
# Display active connections at the top if there's no query
nouids = False
if wf.update_available:
nouids = True
wf.add_item('Update available!',
'Action this item to update the workflow',
autocomplete='workflow:update',
valid=False,
icon=ICON_UPDATE)
if not query:

if len(active_connections) > 1:
Expand All @@ -124,7 +131,7 @@ def do_list(args):
)

for con in active_connections:
arg = 'disconnect {0}'.format(pipes.quote(con.name))
arg = u'disconnect {0}'.format(pipes.quote(con.name))
wf.add_item(
con.name,
'↩ to disconnect',
Expand All @@ -148,10 +155,10 @@ def do_list(args):
if con.active:
continue

arg = 'connect {0}'.format(pipes.quote(con.name))
arg = u'connect {0}'.format(pipes.quote(con.name))
# Only add UID if there are no connected VPNs
# to ensure connected VPNs are shown first
if connected:
if connected or nouids:
uid = None
else:
uid = con.name
Expand Down Expand Up @@ -181,7 +188,7 @@ def do_connect(args):
name = args.get('<name>')
connections = filter_connections(False, name)
for con in connections:
log.debug('Connecting `%s` ...', con.name)
log.debug(u'Connecting `%s` ...', con.name)
run_script('connect_vpn', con.name)


Expand All @@ -190,7 +197,7 @@ def do_disconnect(args):
name = args.get('<name>')
connections = filter_connections(True, name)
for con in connections:
log.debug('Disconnecting `%s` ...', con.name)
log.debug(u'Disconnecting `%s` ...', con.name)
run_script('disconnect_vpn', con.name)


Expand All @@ -212,6 +219,6 @@ def main(wf):


if __name__ == '__main__':
wf = Workflow(update_settings=UPDATE_SETTINGS)
wf = Workflow3(update_settings=UPDATE_SETTINGS)
log = wf.logger
sys.exit(wf.run(main))
Binary file added src/workflow/Notify.tgz
Binary file not shown.
21 changes: 10 additions & 11 deletions src/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,13 @@
# Created on 2014-02-15
#

"""
A Python helper library for `Alfred 2 <http://www.alfredapp.com/>`_ Workflow
authors.
"""
"""A helper library for `Alfred <http://www.alfredapp.com/>`_ workflows."""

import os

__title__ = 'Alfred-Workflow'
__version__ = open(os.path.join(os.path.dirname(__file__), 'version')).read()
__author__ = 'Dean Jackson'
__licence__ = 'MIT'
__copyright__ = 'Copyright 2014 Dean Jackson'


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

# Exceptions
from .workflow import PasswordNotFound, KeychainError
Expand Down Expand Up @@ -68,8 +59,16 @@
MATCH_SUBSTRING,
)


__title__ = 'Alfred-Workflow'
__version__ = open(os.path.join(os.path.dirname(__file__), 'version')).read()
__author__ = 'Dean Jackson'
__licence__ = 'MIT'
__copyright__ = 'Copyright 2014 Dean Jackson'

__all__ = [
'Workflow',
'Workflow3',
'manager',
'PasswordNotFound',
'KeychainError',
Expand Down
Loading

0 comments on commit fad1aa3

Please sign in to comment.