diff --git a/blenderkit/bkit_oauth.py b/blenderkit/bkit_oauth.py index 5350ae7457fc006fa3665a81d630d181f7da1eea..2b732bb1a9e8dad0379dad436230f05fe0086c8e 100644 --- a/blenderkit/bkit_oauth.py +++ b/blenderkit/bkit_oauth.py @@ -42,15 +42,15 @@ PORTS = [62485, 1234] def login_thread(signup=False): - thread = threading.Thread(target=login, args=([signup]), daemon=True) + r_url = paths.get_oauth_landing_url() + url = paths.get_bkit_url() + thread = threading.Thread(target=login, args=([signup, url, r_url]), daemon=True) thread.start() -def login(signup): - r_url = paths.get_oauth_landing_url() - - authenticator = oauth.SimpleOAuthAuthenticator(server_url=paths.get_bkit_url(), client_id=CLIENT_ID, ports=PORTS) - auth_token, refresh_token = authenticator.get_new_token(register = signup, redirect_url=r_url) +def login(signup, url, r_url): + authenticator = oauth.SimpleOAuthAuthenticator(server_url=url, client_id=CLIENT_ID, ports=PORTS) + auth_token, refresh_token = authenticator.get_new_token(register=signup, redirect_url=r_url) utils.p('tokens retrieved') tasks_queue.add_task((write_tokens, (auth_token, refresh_token))) @@ -58,12 +58,13 @@ def login(signup): def refresh_token_thread(): preferences = bpy.context.preferences.addons['blenderkit'].preferences if len(preferences.api_key_refresh) > 0: - thread = threading.Thread(target=refresh_token, args=([preferences.api_key_refresh]), daemon=True) + url = paths.get_bkit_url() + thread = threading.Thread(target=refresh_token, args=([preferences.api_key_refresh, url]), daemon=True) thread.start() -def refresh_token(api_key_refresh): - authenticator = oauth.SimpleOAuthAuthenticator(server_url=paths.get_bkit_url(), client_id=CLIENT_ID, ports=PORTS) +def refresh_token(api_key_refresh, url): + authenticator = oauth.SimpleOAuthAuthenticator(server_url=url, client_id=CLIENT_ID, ports=PORTS) auth_token, refresh_token = authenticator.get_refreshed_token(api_key_refresh) if auth_token is not None and refresh_token is not None: tasks_queue.add_task((write_tokens, (auth_token, refresh_token))) diff --git a/blenderkit/download.py b/blenderkit/download.py index 06342db685419e0465967c7e3fc397f1a380b976..647c15ceeaf07210f1e5742b191429a3f063ef49 100644 --- a/blenderkit/download.py +++ b/blenderkit/download.py @@ -544,7 +544,7 @@ class Downloader(threading.Thread): if check_existing(asset_data) and not tcom.passargs.get('delete'): # this sends the thread for processing, where another check should occur, since the file might be corrupted. tcom.downloaded = 100 - print('not downloading, trying to append again') + utils.p('not downloading, trying to append again') return; file_name = paths.get_download_filenames(asset_data)[0] # prefer global dir if possible. # for k in asset_data: @@ -646,7 +646,7 @@ def check_existing(asset_data): file_names = paths.get_download_filenames(asset_data) - print('check if file allready exists') + utils.p('check if file allready exists') if len(file_names) == 2: # TODO this should check also for failed or running downloads. # If download is running, assign just the running thread. if download isn't running but the file is wrong size, diff --git a/blenderkit/utils.py b/blenderkit/utils.py index 2b13533f0cc694d86ebd0db33a7a4b2d0be65516..c2c83648008136a8d2683afac3dce1404486e9f0 100644 --- a/blenderkit/utils.py +++ b/blenderkit/utils.py @@ -180,7 +180,7 @@ def load_prefs(): def save_prefs(self, context): # first check context, so we don't do this on registration or blender startup - if not bpy.app.background and hasattr(bpy.context, 'view_layer'): + if not bpy.app.background: #(hasattr kills blender) user_preferences = bpy.context.preferences.addons['blenderkit'].preferences # we test the api key for lenght, so not a random accidentaly typed sequence gets saved. lk = len(user_preferences.api_key) @@ -200,7 +200,8 @@ def save_prefs(self, context): f = open(fpath, 'w') with open(fpath, 'w') as s: json.dump(prefs, s) - bpy.ops.wm.save_userpref() + # this was crashing blender 2.8 since some point, probably not needed since autosave is in preferences. + # bpy.ops.wm.save_userpref() def get_hidden_image(tpath, bdata_name, force_reload=False):