File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,20 +13,20 @@ def _is_function(fn):
1313 return hasattr (fn , '__call__' )
1414
1515
16- def async (fn ):
16+ def runasync (fn ):
1717 """ Decorator for running functions asynchronously.
1818 Async functions can have a callback as the
1919 last argument. Returns False if uncaught exception.
2020
2121 e.x. no callback:
22- @async
22+ @runasync
2323 def no_callback(arg):
2424 chage_some_state(arg)
2525
2626 no_callback(2)
2727
2828 or has callback:
29- @async
29+ @runasync
3030 def has_callback(arg):
3131 return arg*2
3232
Original file line number Diff line number Diff line change 11"""
22Collection of functions the plugin can invoke. Most if not all should be
3- non-blocking (@async ) functions to keep the main UI thread from freezing.
3+ non-blocking (@runasync ) functions to keep the main UI thread from freezing.
44
55These functions should catch all unexpected exceptions so the plugin does not
66have to. Unexpected exceptions should return False. Expected exceptions should
77be caught by other modules this module uses. Log all unusual behavior.
88
9- All @async functions have an optional callback parameter as the last argument.
9+ All @runasync functions have an optional callback parameter as the last argument.
1010"""
1111import os
1212
1313from . import logger
1414from . import settings
1515from . import http
1616from . import io
17- from .async import async
17+ from .asynclib import runasync
1818from .theme import Theme
1919
2020log = logger .get (__name__ )
@@ -37,7 +37,7 @@ def get_installed_themes():
3737 return themes
3838
3939
40- @async
40+ @runasync
4141def fetch_repo ():
4242 """ Get current theme archive in a new thread """
4343 archive = http .get (settings .repo_url ())
@@ -71,9 +71,7 @@ def install_theme(theme):
7171 return
7272
7373 io .copy (theme .cache_path .abs , theme .install_path .abs )
74- settings .set_theme (theme .install_path .rel )
75- settings .commit ()
76-
74+ settings .commit_theme (theme .install_path .rel )
7775
7876def revert_theme (path ):
7977 log .debug ('Reverting theme at path %s' , path )
Original file line number Diff line number Diff line change @@ -28,8 +28,8 @@ def get(self, url):
2828 result = request .urlopen (url )
2929 except error .URLError as e :
3030 log .error ('Urllib downloader failed: %s' % e .reason )
31- traceback .print_exc ()
32- result = b''
31+ raise e
3332 if result .getcode () >= 400 :
33+ log .error ('Urllib downloader failed with code: %s' % result .getcode ())
3434 return b''
3535 return result .read ()
Original file line number Diff line number Diff line change @@ -47,8 +47,12 @@ def set_theme(path):
4747 return sublime .load_settings (SUBLIME_PREF ).set ('color_scheme' , path )
4848
4949
50- def commit ():
51- sublime .save_settings (SUBLIME_PREF )
50+ def commit_theme (path ):
51+ def callback ():
52+ set_theme (path )
53+ sublime .save_settings (SUBLIME_PREF )
54+ # Timeout so sublime can get caught up with the filesystem
55+ sublime .set_timeout_async (callback , 1000 )
5256
5357
5458def is_debug ():
Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ class Loader(Message):
9292
9393 def _get_message (self ):
9494 mod = len (self .chars )
95- rands = [self .chars [x % mod ] for x in random .sample (range (100 ), 10 )]
95+ rands = [self .chars [x % mod ] for x in random .sample (range (100 ), 1 )]
9696 msg = self .message + ' [' + '' .join (rands ) + '] '
9797 return msg
9898
You can’t perform that action at this time.
0 commit comments