Skip prompting for api key when found from common config file

This commit is contained in:
Alan Hamlett 2019-05-27 12:39:48 -07:00
parent cde8f8f1de
commit 60608bd322

View file

@ -142,7 +142,8 @@ sys.path.insert(0, os.path.join(PLUGIN_DIR, 'packages'))
try: try:
from wakatime.main import parseConfigFile from wakatime.main import parseConfigFile
except ImportError: except ImportError:
pass def parseConfigFile():
return None
def set_timeout(callback, seconds): def set_timeout(callback, seconds):
@ -274,12 +275,15 @@ def prompt_api_key():
if SETTINGS.get('api_key'): if SETTINGS.get('api_key'):
return True return True
default_key = ''
try: try:
configs = parseConfigFile() configs = parseConfigFile()
if configs is not None: if configs is not None:
if configs.has_option('settings', 'api_key'): if configs.has_option('settings', 'api_key'):
default_key = configs.get('settings', 'api_key') key = configs.get('settings', 'api_key')
if key:
SETTINGS.set('api_key', str(key))
sublime.save_settings(SETTINGS_FILE)
return True
except: except:
pass pass
@ -289,7 +293,7 @@ def prompt_api_key():
if text: if text:
SETTINGS.set('api_key', str(text)) SETTINGS.set('api_key', str(text))
sublime.save_settings(SETTINGS_FILE) sublime.save_settings(SETTINGS_FILE)
window.show_input_panel('[WakaTime] Enter your wakatime.com api key:', default_key, got_key, None, None) window.show_input_panel('[WakaTime] Enter your wakatime.com api key:', '', got_key, None, None)
return True return True
else: else:
log(ERROR, 'Could not prompt for api key because no window found.') log(ERROR, 'Could not prompt for api key because no window found.')