BlenderKit: save user preferences if user pastes the API key into the panel in 3d view.
some users were confused by this, because they didn't save their preferences. Also some users filled in the API key area some other string and then didn't know what they did wrong.
This commit is contained in:
parent
7d305b6868
commit
501f660fe8
|
@ -1280,6 +1280,13 @@ class BlenderKitAddonPreferences(AddonPreferences):
|
|||
min=0,
|
||||
max=20)
|
||||
|
||||
asset_counter: IntProperty(name="Usage Counter",
|
||||
description="Counts usages so it asks for registration only after reaching a limit",
|
||||
default=0,
|
||||
min=0,
|
||||
max=20000)
|
||||
|
||||
|
||||
# allow_proximity : BoolProperty(
|
||||
# name="allow proximity data reports",
|
||||
# description="This sends anonymized proximity data \n \
|
||||
|
|
|
@ -285,6 +285,11 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
|
|||
id = asset_data['asset_base_id']
|
||||
scene['assets rated'][id] = scene['assets rated'].get(id, False)
|
||||
|
||||
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
|
||||
|
||||
if user_preferences.api_key == '':
|
||||
user_preferences.asset_counter+=1
|
||||
|
||||
if asset_data['asset_type'] == 'scene':
|
||||
scene = append_link.append_scene(file_names[0], link=False, fake_user=False)
|
||||
props = scene.blenderkit
|
||||
|
|
|
@ -57,6 +57,9 @@ prev_time = 0
|
|||
def check_errors(rdata):
|
||||
if rdata.get('statusCode') == 401:
|
||||
if rdata.get('detail') == 'Invalid token.':
|
||||
# reset the api key, so it can be requested again.
|
||||
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
|
||||
user_preferences.api_key = ''
|
||||
return False, 'Missing or wrong api_key in addon preferences'
|
||||
return True, ''
|
||||
|
||||
|
|
|
@ -524,7 +524,7 @@ class VIEW3D_PT_blenderkit_unified(Panel):
|
|||
|
||||
w = context.region.width
|
||||
|
||||
if user_preferences.api_key == '':
|
||||
if len(user_preferences.api_key) < 35 and user_preferences.counter >10:
|
||||
op = layout.operator("wm.url_open", text="Register online",
|
||||
icon='QUESTION')
|
||||
op.url = paths.BLENDERKIT_SIGNUP_URL
|
||||
|
|
|
@ -174,20 +174,27 @@ def load_prefs():
|
|||
user_preferences.api_key = prefs['API_key']
|
||||
user_preferences.global_dir = prefs['global_dir']
|
||||
|
||||
|
||||
def save_prefs(self, context):
|
||||
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
|
||||
if user_preferences.api_key != '':
|
||||
prefs = {
|
||||
'API_key': user_preferences.api_key,
|
||||
'global_dir': user_preferences.global_dir,
|
||||
}
|
||||
# user_preferences.api_key = user_preferences.api_key.strip()
|
||||
fpath = paths.BLENDERKIT_SETTINGS_FILENAME
|
||||
f = open(fpath, 'w')
|
||||
with open(fpath, 'w') as s:
|
||||
json.dump(prefs, s)
|
||||
|
||||
print(len(user_preferences.api_key))
|
||||
print('length')
|
||||
if len(user_preferences.api_key)>35:
|
||||
prefs = {
|
||||
'API_key': user_preferences.api_key,
|
||||
'global_dir': user_preferences.global_dir,
|
||||
}
|
||||
# user_preferences.api_key = user_preferences.api_key.strip()
|
||||
fpath = paths.BLENDERKIT_SETTINGS_FILENAME
|
||||
f = open(fpath, 'w')
|
||||
with open(fpath, 'w') as s:
|
||||
json.dump(prefs, s)
|
||||
bpy.ops.wm.save_userpref()
|
||||
else:
|
||||
# reset the api key in case the user writes some nonsense, e.g. a search string instead of the Key
|
||||
user_preferences.api_key = ''
|
||||
props = get_search_props()
|
||||
props.report = 'Please paste a correct API Key.'
|
||||
|
||||
def load_categories():
|
||||
categories.copy_categories()
|
||||
|
|
Loading…
Reference in New Issue