From 4f4148763cc8b8be45717ac9c2ed66a95cd3477b Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Tue, 6 Aug 2013 17:21:32 -0700 Subject: [PATCH] added packages.json for Sublime Package Control versioning. fixed issues with WakaTime.sublime-settings in both ST2 and ST3. --- WakaTime.py | 37 +++++++++++++++++++++++++------------ messages.json | 3 --- messages/0.3.1.txt | 6 ------ packages.json | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+), 21 deletions(-) delete mode 100644 messages.json delete mode 100644 messages/0.3.1.txt create mode 100644 packages.json diff --git a/WakaTime.py b/WakaTime.py index 01215f8..72ebe66 100644 --- a/WakaTime.py +++ b/WakaTime.py @@ -24,15 +24,16 @@ AWAY_MINUTES = 10 ACTION_FREQUENCY = 5 PLUGIN_DIR = dirname(realpath(__file__)) API_CLIENT = '%s/packages/wakatime/wakatime-cli.py' % PLUGIN_DIR -SETTINGS = '%s.sublime-settings' % __name__ +SETTINGS = 'WakaTime.sublime-settings' LAST_ACTION = 0 LAST_USAGE = 0 LAST_FILE = None BUSY = False -# Convert ~/.wakatime.conf to WakaTime.sublime-settings -def convert_config_to_sublime_settings(): +def setup_settings_file(): + """ Convert ~/.wakatime.conf to WakaTime.sublime-settings + """ # To be backwards compatible, rename config file settings = sublime.load_settings(SETTINGS) api_key = settings.get('api_key', '') @@ -49,22 +50,28 @@ def convert_config_to_sublime_settings(): pass except IOError: pass - settings.set('api_key', api_key) + settings.set('api_key', str(api_key)) sublime.save_settings(SETTINGS) -convert_config_to_sublime_settings() -# Prompt for api key if not set in WakaTime.sublime-settings -def check_api_key(): +def get_api_key(): + """If api key not set, prompt user to enter one then save + to WakaTime.sublime-settings. + """ settings = sublime.load_settings(SETTINGS) - api_key = settings.get('api_key', None) + api_key = settings.get('api_key', '') if not api_key: def got_key(text): if text: - settings.set('api_key', str(api_key)) + settings = sublime.load_settings(SETTINGS) + settings.set('api_key', str(text)) sublime.save_settings(SETTINGS) - sublime.active_window().show_input_panel('Enter your WakaTi.me api key:', '', got_key, None, None) -check_api_key() + window = sublime.active_window() + if window is not None: + window.show_input_panel('Enter your WakaTi.me api key:', '', got_key, None, None) + return sublime.load_settings(SETTINGS).get('api_key', '') + else: + return api_key def python_binary(): @@ -92,7 +99,7 @@ def api(targetFile, timestamp, isWrite=False, endtime=0): '--plugin', 'sublime-wakatime/%s' % __version__, #'--verbose', ] - api_key = sublime.load_settings(SETTINGS).get('api_key', None) + api_key = get_api_key() if api_key: cmd.extend(['--key', str(api_key)]) if isWrite: @@ -206,3 +213,9 @@ class WakatimeListener(sublime_plugin.EventListener): #print(['modified', view.file_name()]) handle_normal_action(view) + +def plugin_loaded(): + get_api_key() + setup_settings_file() +if int(sublime.version()) < 3000: + plugin_loaded() diff --git a/messages.json b/messages.json deleted file mode 100644 index 423d0a0..0000000 --- a/messages.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "0.3.1": "messages/0.3.1.txt" -} diff --git a/messages/0.3.1.txt b/messages/0.3.1.txt deleted file mode 100644 index d7153e0..0000000 --- a/messages/0.3.1.txt +++ /dev/null @@ -1,6 +0,0 @@ -WakaTime Changes for v0.3.1 - -- no more prompting after away by default -- api key moved to new WakaTime.sublime-settings file -- new setting to disable or enable the away popup -- fixes for Windows platform diff --git a/packages.json b/packages.json new file mode 100644 index 0000000..5699eea --- /dev/null +++ b/packages.json @@ -0,0 +1,20 @@ +{ + "schema_version": "1.2", + "packages": [ + { + "name": "WakaTime", + "description": "Automatic time tracking for Sublime Text 2 & 3", + "author": "wakati.me", + "homepage": "https://github.com/wakatime/sublime-wakatime", + "last_modified": "2013-08-06 23:02", + "platforms": { + "*": [ + { + "version": "0.3.1", + "url": "https://codeload.github.com/wakatime/sublime-wakatime/zip/0.3.1" + } + ] + } + } + ] +}