Skip to content

Commit 9d9c07c

Browse files
committed
Fix #48: add delay before committing selected theme
1 parent ed67f40 commit 9d9c07c

5 files changed

Lines changed: 17 additions & 15 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

colorsublime/commands.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
"""
22
Collection 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
55
These functions should catch all unexpected exceptions so the plugin does not
66
have to. Unexpected exceptions should return False. Expected exceptions should
77
be 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
"""
1111
import os
1212

1313
from . import logger
1414
from . import settings
1515
from . import http
1616
from . import io
17-
from .async import async
17+
from .asynclib import runasync
1818
from .theme import Theme
1919

2020
log = logger.get(__name__)
@@ -37,7 +37,7 @@ def get_installed_themes():
3737
return themes
3838

3939

40-
@async
40+
@runasync
4141
def 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

7876
def revert_theme(path):
7977
log.debug('Reverting theme at path %s', path)

colorsublime/http/downloaders/urllib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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()

colorsublime/settings.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff 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

5458
def is_debug():

colorsublime/status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)